Skip to content
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

Open
wants to merge 11 commits into
base: ucr
Choose a base branch
from
Expand Up @@ -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>();
Expand Down Expand Up @@ -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) {
Copy link
Member

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.

OdeLog.log("ProjectEditor: record" + permission + "Setting(" + componentName + "," + newValue + ")");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation should be 2 space from function declaration (4 spaces total)

Copy link
Member

Choose a reason for hiding this comment

The 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);
Copy link
Member

Choose a reason for hiding this comment

The 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);
Copy link
Member

Choose a reason for hiding this comment

The 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);
}

/**
Expand Down
Expand Up @@ -1119,6 +1119,8 @@ public void onRemoved()

public void delete() {
this.editor.getProjectEditor().clearLocation(getName());
this.editor.getProjectEditor().clearCamera(getName());
this.editor.getProjectEditor().clearMicrophone(getName());
getForm().select(null);
// Pass true to indicate that the component is being permanently deleted.
getContainer().removeComponent(this, true);
Expand Down
Expand Up @@ -30,6 +30,8 @@ public final class MockWebViewer extends MockVisibleComponent {

// Property names that we need to treat specially
private static final String PROPERTY_NAME_USESLOCATION = "UsesLocation";
private static final String PROPERTY_NAME_USESCAMERA = "UsesCamera";
private static final String PROPERTY_NAME_USESMICROPHONE = "UsesMicrophone";

// Large icon image for use in designer. Smaller version is in the palette.
private final Image largeImage = new Image(images.webviewerbig());
Expand Down Expand Up @@ -88,6 +90,10 @@ public void onPropertyChange(String propertyName, String newValue) {

if (propertyName.equals(PROPERTY_NAME_USESLOCATION)) {
editor.getProjectEditor().recordLocationSetting(this.getName(), newValue);
} else if (propertyName.equals(PROPERTY_NAME_USESCAMERA)) {
editor.getProjectEditor().recordCameraSetting(this.getName(), newValue);
} else if (propertyName.equals(PROPERTY_NAME_USESMICROPHONE)) {
editor.getProjectEditor().recordMicrophoneSetting(this.getName(), newValue);
}

}
Expand Down
Expand Up @@ -45,6 +45,12 @@ public YoungAndroidSettings(Project project) {
addProperty(new EditableProperty(this,
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_LOCATION, "false",
EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this,
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_CAMERA, "false",
EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this,
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_MICROPHONE, "false",
EditableProperty.TYPE_INVISIBLE));
addProperty(new EditableProperty(this,
SettingsConstants.YOUNG_ANDROID_SETTINGS_APP_NAME, "",
EditableProperty.TYPE_INVISIBLE));
Expand Down
Expand Up @@ -103,7 +103,7 @@ public UserProject importProject(String userId, String projectName,
// the projectName and qualifiedFormName.
String content = YoungAndroidProjectService.getProjectPropertiesFileContents(
projectName, qualifiedFormName, null, null, null, null, null, null, null, null,
null, null, null, null, null, null);
null, null, null, null, null, null, null, null);
project.addTextFile(new TextFile(fileName, content));
isProjectArchive = true;

Expand Down Expand Up @@ -151,7 +151,7 @@ public UserProject importProject(String userId, String projectName,
project.setProjectHistory(projectHistory);
}
String settings = YoungAndroidProjectService.getProjectSettings(null, null, null, null, null,
null, null, null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null, null, null);
long projectId = storageIo.createProject(userId, project, settings);
return storageIo.getUserProject(userId, projectId);
}
Expand Down
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The 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);
Expand All @@ -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 +
Expand All @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The 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" +
Expand All @@ -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";
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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"));
Expand All @@ -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) ||
Copy link
Member

Choose a reason for hiding this comment

The 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 || at the beginning of the line per Google style guide to be consistent because right now this is mixed (I think this is also on me).

!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);
Expand All @@ -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);
Expand All @@ -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"));
}

Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -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));
}

Expand Down
Expand Up @@ -51,6 +51,8 @@ private SettingsConstants() {
public static final String YOUNG_ANDROID_SETTINGS_VERSION_CODE = "VersionCode";
public static final String YOUNG_ANDROID_SETTINGS_VERSION_NAME = "VersionName";
public static final String YOUNG_ANDROID_SETTINGS_USES_LOCATION = "UsesLocation";
public static final String YOUNG_ANDROID_SETTINGS_USES_CAMERA = "UsesCamera";
public static final String YOUNG_ANDROID_SETTINGS_USES_MICROPHONE = "UsesMicrophone";
public static final String YOUNG_ANDROID_SETTINGS_SIZING = "Sizing";
public static final String YOUNG_ANDROID_SETTINGS_APP_NAME = "AppName";
public static final String YOUNG_ANDROID_SETTINGS_SHOW_LISTS_AS_JSON = "ShowListsAsJson";
Expand Down
Expand Up @@ -342,6 +342,8 @@ public void testCopyProject() throws Exception {
"versioncode=1\n" +
"versionname=1.0\n" +
"useslocation=false\n" +
"usescamera=false\n" +
"usesmicrophone=false\n" +
"aname=Project1\n" +
"sizing=Fixed\n" +
"showlistsasjson=false\n" +
Expand Down Expand Up @@ -495,6 +497,8 @@ public void testLoadAndStoreProjectSettings() throws Exception {
SettingsConstants.YOUNG_ANDROID_SETTINGS_VERSION_CODE + "\":\"1\",\"" +
SettingsConstants.YOUNG_ANDROID_SETTINGS_VERSION_NAME + "\":\"1.0\",\"" +
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_LOCATION + "\":\"false\",\"" +
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_CAMERA + "\":\"false\",\"" +
SettingsConstants.YOUNG_ANDROID_SETTINGS_USES_MICROPHONE + "\":\"false\",\"" +
SettingsConstants.YOUNG_ANDROID_SETTINGS_APP_NAME + "\":\"Project1\",\"" +
SettingsConstants.YOUNG_ANDROID_SETTINGS_SIZING + "\":\"Fixed\",\"" +
SettingsConstants.YOUNG_ANDROID_SETTINGS_SHOW_LISTS_AS_JSON + "\":\"false\",\"" +
Expand Down