New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uses Camera Property for Web Viewer #2096
base: ucr
Are you sure you want to change the base?
Changes from all commits
fed3493
4b15c07
d211841
c031eec
42b0619
26d3e67
79197e5
e032bd1
c0a48de
5626f1b
5fad68b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,8 @@ public abstract class ProjectEditor extends Composite { | |
private final Map<String, FileEditor> openFileEditors; | ||
protected final List<String> fileIds; | ||
private final HashMap<String,String> locationHashMap = new HashMap<String,String>(); | ||
private final HashMap<String, String> cameraHashMap = new HashMap<String,String>(); | ||
private final HashMap<String, String> microphoneHashMap = new HashMap<String, String>(); | ||
private final DeckPanel deckPanel; | ||
private FileEditor selectedFileEditor; | ||
private final TreeMap<String, Boolean> screenHashMap = new TreeMap<String, Boolean>(); | ||
|
@@ -307,28 +309,73 @@ public final void changeProjectSettingsProperty(String category, String name, St | |
*/ | ||
|
||
public final void recordLocationSetting(String componentName, String newValue) { | ||
OdeLog.log("ProjectEditor: recordLocationSetting(" + componentName + "," + newValue + ")"); | ||
locationHashMap.put(componentName, newValue); | ||
recomputeLocationPermission(); | ||
recordPermission(componentName, newValue, SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_LOCATION, locationHashMap); | ||
} | ||
|
||
private final void recomputeLocationPermission() { | ||
String usesLocation = "False"; | ||
for (String c : locationHashMap.values()) { | ||
OdeLog.log("ProjectEditor:recomputeLocationPermission: " + c); | ||
public final void recordCameraSetting(String componentName, String newValue) { | ||
recordPermission(componentName, newValue, SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_CAMERA, cameraHashMap); | ||
} | ||
|
||
public final void recordMicrophoneSetting(String componentName, String newValue) { | ||
recordPermission(componentName, newValue, SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_MICROPHONE, microphoneHashMap); | ||
} | ||
|
||
/** | ||
* Auxiliary function to record a targetted permission for a component. | ||
* | ||
* @param componentName Name of the component to record permission for | ||
* @param newValue New value of the permission | ||
* @param permission Name of the permission | ||
* @param permissionMap Map holding the permission mappings (component -> value) | ||
*/ | ||
private final void recordPermission(String componentName, String newValue, String permission, | ||
Map<String, String> permissionMap) { | ||
OdeLog.log("ProjectEditor: record" + permission + "Setting(" + componentName + "," + newValue + ")"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation should be 2 space from function declaration (4 spaces total) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should remove this call to OdeLog.log or replace it with Ode.CLog. OdeLog manipulates the DOM and so every log message adds HTML, making the UI slower. |
||
permissionMap.put(componentName, newValue); | ||
recomputePermission(permissionMap, permission); | ||
} | ||
|
||
/** | ||
* Auxiliary function to clear a targetted permission for a component. | ||
* | ||
* @param componentName Name of the component to clear permission from | ||
* @param permission Name of the permission to revoke | ||
* @param permissionMap Map holding the permission mappings (component -> value) | ||
*/ | ||
private final void clearPermission(String componentName, String permission, Map<String, String> permissionMap) { | ||
OdeLog.log("ProjectEditor:clear" + permission + ": clearing " + componentName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous note on OdeLog |
||
permissionMap.remove(componentName); | ||
recomputePermission(permissionMap, permission); | ||
} | ||
|
||
/** | ||
* Auxiliary function to recompute a permission given a permission map | ||
* | ||
* @param permissionMap Permission map that maps component -> permission value | ||
* @param permissionName Name of the permission | ||
*/ | ||
private final void recomputePermission(Map<String,String> permissionMap, String permissionName) { | ||
String usesPermission = "False"; | ||
for (String c : permissionMap.values()) { | ||
OdeLog.log(permissionName + ": " + c); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto OdeLog |
||
if (c.equals("True")) { | ||
usesLocation = "True"; | ||
usesPermission = "True"; | ||
break; | ||
} | ||
} | ||
changeProjectSettingsProperty(SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_LOCATION, | ||
usesLocation); | ||
changeProjectSettingsProperty(SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, permissionName, usesPermission); | ||
} | ||
|
||
public void clearLocation(String componentName) { | ||
OdeLog.log("ProjectEditor:clearLocation: clearing " + componentName); | ||
locationHashMap.remove(componentName); | ||
recomputeLocationPermission(); | ||
clearPermission(componentName, SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_LOCATION, locationHashMap); | ||
} | ||
|
||
public void clearCamera(String componentName) { | ||
clearPermission(componentName, SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_CAMERA, cameraHashMap); | ||
} | ||
|
||
public void clearMicrophone(String componentName) { | ||
clearPermission(componentName, SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_MICROPHONE, microphoneHashMap); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,12 +132,15 @@ public YoungAndroidProjectService(StorageIo storageIo) { | |
* Returns project settings that can be used when creating a new project. | ||
*/ | ||
public static String getProjectSettings(String icon, String vCode, String vName, | ||
String useslocation, String aName, String sizing, String showListsAsJson, String tutorialURL, String subsetJSON, | ||
String actionBar, String theme, String primaryColor, String primaryColorDark, String accentColor) { | ||
String useslocation, String usescamera, String usesmicrophone, String aName, String sizing, String showListsAsJson, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old code was wrong w.r.t. indentation here, but you should go ahead and fix it (should be 6 spaces from beginning of line). |
||
String tutorialURL, String subsetJSON, String actionBar, String theme, String primaryColor, String primaryColorDark, | ||
String accentColor) { | ||
icon = Strings.nullToEmpty(icon); | ||
vCode = Strings.nullToEmpty(vCode); | ||
vName = Strings.nullToEmpty(vName); | ||
useslocation = Strings.nullToEmpty(useslocation); | ||
usescamera = Strings.nullToEmpty(usescamera); | ||
usesmicrophone = Strings.nullToEmpty(usesmicrophone); | ||
sizing = Strings.nullToEmpty(sizing); | ||
aName = Strings.nullToEmpty(aName); | ||
showListsAsJson = Strings.nullToEmpty(showListsAsJson); | ||
|
@@ -153,6 +156,8 @@ public static String getProjectSettings(String icon, String vCode, String vName, | |
"\",\"" + SettingsConstants.YOUNG_ANDROID_SETTINGS_VERSION_CODE + "\":\"" + vCode + | ||
"\",\"" + SettingsConstants.YOUNG_ANDROID_SETTINGS_VERSION_NAME + "\":\"" + vName + | ||
"\",\"" + SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_LOCATION + "\":\"" + useslocation + | ||
"\",\"" + SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_CAMERA + "\":\"" + usescamera + | ||
"\",\"" + SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_MICROPHONE + "\":\"" + usesmicrophone + | ||
"\",\"" + SettingsConstants.YOUNG_ANDROID_SETTINGS_APP_NAME + "\":\"" + aName + | ||
"\",\"" + SettingsConstants.YOUNG_ANDROID_SETTINGS_SIZING + "\":\"" + sizing + | ||
"\",\"" + SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_LISTS_AS_JSON + "\":\"" + showListsAsJson + | ||
|
@@ -177,9 +182,9 @@ public static String getProjectSettings(String icon, String vCode, String vName, | |
* @param vname the version name | ||
*/ | ||
public static String getProjectPropertiesFileContents(String projectName, String qualifiedName, | ||
String icon, String vcode, String vname, String useslocation, String aname, | ||
String sizing, String showListsAsJson, String tutorialURL, String subsetJSON, String actionBar, String theme, | ||
String primaryColor, String primaryColorDark, String accentColor) { | ||
String icon, String vcode, String vname, String useslocation, String usescamera, String usesmicrophone, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct the indentation |
||
String aname, String sizing, String showListsAsJson, String tutorialURL, String subsetJSON, String actionBar, | ||
String theme, String primaryColor, String primaryColorDark, String accentColor) { | ||
String contents = "main=" + qualifiedName + "\n" + | ||
"name=" + projectName + '\n' + | ||
"assets=../" + ASSETS_FOLDER + "\n" + | ||
|
@@ -197,6 +202,12 @@ public static String getProjectPropertiesFileContents(String projectName, String | |
if (useslocation != null && !useslocation.isEmpty()) { | ||
contents += "useslocation=" + useslocation + "\n"; | ||
} | ||
if (usescamera != null && !usescamera.isEmpty()) { | ||
contents += "usescamera=" + usescamera + "\n"; | ||
} | ||
if (usesmicrophone!= null && !usesmicrophone.isEmpty()) { | ||
contents += "usesmicrophone=" + usesmicrophone + "\n"; | ||
} | ||
if (aname != null) { | ||
contents += "aname=" + aname + "\n"; | ||
} | ||
|
@@ -290,6 +301,12 @@ public void storeProjectSettings(String userId, long projectId, String projectSe | |
String newUsesLocation = Strings.nullToEmpty(settings.getSetting( | ||
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, | ||
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_LOCATION)); | ||
String newUsesCamera = Strings.nullToEmpty(settings.getSetting( | ||
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, | ||
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_CAMERA)); | ||
String newUsesMicrophone = Strings.nullToEmpty(settings.getSetting( | ||
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, | ||
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_MICROPHONE)); | ||
String newSizing = Strings.nullToEmpty(settings.getSetting( | ||
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, | ||
SettingsConstants.YOUNG_ANDROID_SETTINGS_SIZING)); | ||
|
@@ -336,6 +353,8 @@ public void storeProjectSettings(String userId, long projectId, String projectSe | |
String oldVCode = Strings.nullToEmpty(properties.getProperty("versioncode")); | ||
String oldVName = Strings.nullToEmpty(properties.getProperty("versionname")); | ||
String oldUsesLocation = Strings.nullToEmpty(properties.getProperty("useslocation")); | ||
String oldUsesCamera = Strings.nullToEmpty(properties.getProperty("usescamera")); | ||
String oldUsesMicrophone = Strings.nullToEmpty(properties.getProperty("usesmicrophone")); | ||
String oldSizing = Strings.nullToEmpty(properties.getProperty("sizing")); | ||
String oldAName = Strings.nullToEmpty(properties.getProperty("aname")); | ||
String oldShowListsAsJson = Strings.nullToEmpty(properties.getProperty("showlistsasjson")); | ||
|
@@ -348,17 +367,17 @@ public void storeProjectSettings(String userId, long projectId, String projectSe | |
String oldAccentColor = Strings.nullToEmpty(properties.getProperty("color.accent")); | ||
|
||
if (!newIcon.equals(oldIcon) || !newVCode.equals(oldVCode) || !newVName.equals(oldVName) | ||
|| !newUsesLocation.equals(oldUsesLocation) || | ||
!newAName.equals(oldAName) || !newSizing.equals(oldSizing) || | ||
!newShowListsAsJson.equals(oldShowListsAsJson) || | ||
|| !newUsesLocation.equals(oldUsesLocation) || !newUsesCamera.equals(oldUsesCamera) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest correcting the entirety of the if statement conditional to have |
||
!newUsesMicrophone.equals(oldUsesMicrophone) || !newAName.equals(oldAName) || | ||
!newSizing.equals(oldSizing) || !newShowListsAsJson.equals(oldShowListsAsJson) || | ||
!newTutorialURL.equals(oldTutorialURL) || !newSubsetJSON.equals(oldSubsetJSON) || !newActionBar.equals(oldActionBar) || | ||
!newTheme.equals(oldTheme) || !newPrimaryColor.equals(oldPrimaryColor) || | ||
!newPrimaryColorDark.equals(oldPrimaryColorDark) || !newAccentColor.equals(oldAccentColor)) { | ||
// Recreate the project.properties and upload it to storageIo. | ||
String projectName = properties.getProperty("name"); | ||
String qualifiedName = properties.getProperty("main"); | ||
String newContent = getProjectPropertiesFileContents(projectName, qualifiedName, newIcon, | ||
newVCode, newVName, newUsesLocation, newAName, newSizing, newShowListsAsJson, newTutorialURL, newSubsetJSON, | ||
newVCode, newVName, newUsesLocation, newUsesCamera, newUsesMicrophone, newAName, newSizing, newShowListsAsJson, newTutorialURL, newSubsetJSON, | ||
newActionBar, newTheme, newPrimaryColor, newPrimaryColorDark, newAccentColor); | ||
storageIo.uploadFileForce(projectId, PROJECT_PROPERTIES_FILE_NAME, userId, | ||
newContent, StorageUtil.DEFAULT_CHARSET); | ||
|
@@ -379,7 +398,7 @@ public long newProject(String userId, String projectName, NewProjectParameters p | |
String propertiesFileName = PROJECT_PROPERTIES_FILE_NAME; | ||
String propertiesFileContents = getProjectPropertiesFileContents(projectName, | ||
qualifiedFormName, null, null, null, null, null, null, null, null, null, null, null, null, | ||
null, null); | ||
null, null, null, null); | ||
|
||
String formFileName = YoungAndroidFormNode.getFormFileId(qualifiedFormName); | ||
String formFileContents = getInitialFormPropertiesFileContents(qualifiedFormName); | ||
|
@@ -399,7 +418,7 @@ public long newProject(String userId, String projectName, NewProjectParameters p | |
project.addTextFile(new TextFile(yailFileName, yailFileContents)); | ||
|
||
// Create new project | ||
return storageIo.createProject(userId, project, getProjectSettings("", "1", "1.0", "false", | ||
return storageIo.createProject(userId, project, getProjectSettings("", "1", "1.0", "false", "false", "false", | ||
projectName, "Fixed", "false", "", "", "false", "AppTheme.Light.DarkActionBar","0", "0", "0")); | ||
} | ||
|
||
|
@@ -421,6 +440,12 @@ public long copyProject(String userId, long oldProjectId, String newName) { | |
String useslocation = oldSettings.getSetting( | ||
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, | ||
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_LOCATION); | ||
String usescamera = oldSettings.getSetting( | ||
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, | ||
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_CAMERA); | ||
String usesmicrophone = oldSettings.getSetting( | ||
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, | ||
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_MICROPHONE); | ||
String aname = oldSettings.getSetting( | ||
SettingsConstants.PROJECT_YOUNG_ANDROID_SETTINGS, | ||
SettingsConstants.YOUNG_ANDROID_SETTINGS_APP_NAME); | ||
|
@@ -470,7 +495,7 @@ public long copyProject(String userId, long oldProjectId, String newName) { | |
String qualifiedFormName = StringUtils.getQualifiedFormName( | ||
storageIo.getUser(userId).getUserEmail(), newName); | ||
newContents = getProjectPropertiesFileContents(newName, qualifiedFormName, icon, vcode, | ||
vname, useslocation, aname, sizing, showListsAsJson, tutorialURL, subsetJSON, actionBar, | ||
vname, useslocation, usescamera, usesmicrophone, aname, sizing, showListsAsJson, tutorialURL, subsetJSON, actionBar, | ||
theme, primaryColor, primaryColorDark, accentColor); | ||
} else { | ||
// This is some file other than the project properties file. | ||
|
@@ -495,7 +520,7 @@ public long copyProject(String userId, long oldProjectId, String newName) { | |
|
||
// Create the new project and return the new project's id. | ||
return storageIo.createProject(userId, newProject, getProjectSettings(icon, vcode, vname, | ||
useslocation, aname, sizing, showListsAsJson, tutorialURL, subsetJSON, actionBar, theme, primaryColor, | ||
useslocation, usescamera, usesmicrophone, aname, sizing, showListsAsJson, tutorialURL, subsetJSON, actionBar, theme, primaryColor, | ||
primaryColorDark, accentColor)); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation should be 4 spaces in from previous line.