Commit a433e3ab authored by hal's avatar hal

Merge pull request #85 from halatmit/visibility

Visibility
parents c52cba97 e548f4ed
......@@ -2,7 +2,10 @@
package com.google.appinventor.client.editor.youngandroid.palette;
import com.google.appinventor.client.Ode;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.google.appinventor.client.editor.simple.SimpleComponentDatabase;
import com.google.appinventor.client.editor.simple.components.MockComponent;
import com.google.appinventor.client.editor.simple.palette.DropTargetProvider;
......@@ -21,6 +24,7 @@ import com.google.appinventor.client.editor.youngandroid.properties.YoungAndroid
import com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidScreenOrientationChoicePropertyEditor;
import com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidSensorDistIntervalChoicePropertyEditor;
import com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidSensorTimeIntervalChoicePropertyEditor;
import com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidVisibilityChoicePropertyEditor;
import com.google.appinventor.client.widgets.properties.FloatPropertyEditor;
import com.google.appinventor.client.widgets.properties.IntegerPropertyEditor;
import com.google.appinventor.client.widgets.properties.NonNegativeFloatPropertyEditor;
......@@ -36,10 +40,6 @@ import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.StackPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Panel showing Simple components which can be dropped onto the Young Android
* visual designer panel.
......@@ -180,6 +180,8 @@ public class YoungAndroidPalettePanel extends Composite implements SimplePalette
return new YoungAndroidAlignmentChoicePropertyEditor();
} else if (editorType.equals(PropertyTypeConstants.PROPERTY_TYPE_TYPEFACE)) {
return new YoungAndroidFontTypefaceChoicePropertyEditor();
} else if (editorType.equals(PropertyTypeConstants.PROPERTY_TYPE_VISIBILITY)) {
return new YoungAndroidVisibilityChoicePropertyEditor();
} else {
return new TextPropertyEditor();
}
......
// Copyright 2012 MIT. All Rights Reserved.
package com.google.appinventor.client.editor.youngandroid.properties;
import com.google.appinventor.client.widgets.properties.ChoicePropertyEditor;
/**
* Property editor for visibility: selects showing or hidden
*
* @author hal@mit.edu (Hal Abelson)
*/
public class YoungAndroidVisibilityChoicePropertyEditor extends ChoicePropertyEditor {
// TODO(hal): The values must be True and False. Lowercase true and false do not work here:
// they are not transformed from strings to booleans when passed to the property.
// Figure out why not and explain in a comment.
private static final Choice[] visibility = new Choice[] {
new Choice("showing", "True"),
new Choice("hidden", "False"),
};
public YoungAndroidVisibilityChoicePropertyEditor() {
super(visibility);
}
}
......@@ -131,4 +131,10 @@ public class PropertyTypeConstants {
* com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidFontTypefaceChoicePropertyEditor}.
*/
public static final String PROPERTY_TYPE_TYPEFACE = "typeface";
/**
* Choices of visibility for view components offered by {@link
* com.google.appinventor.client.editor.youngandroid.properties.YoungAndroidVisibilityChoicePropertyEditor}.
*/
public static final String PROPERTY_TYPE_VISIBILITY = "visibility";
}
......@@ -47,22 +47,25 @@ public abstract class AndroidViewComponent extends VisibleComponent {
* Returns true iff the component is visible.
* @return true iff the component is visible
*/
@SimpleProperty(description = "Whether the component is visible",
@SimpleProperty(
category = PropertyCategory.APPEARANCE)
public boolean Visible() {
return getView().getVisibility() == View.VISIBLE;
}
/**
* Specifies whether the component should be visible
* Specifies whether the component should be visible on the screen. Value is true if the
* component is showing and false if hidden.
* @param visible desired state
*/
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "True")
@SimpleProperty
public void Visible(boolean visible) {
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_VISIBILITY,
defaultValue = "True")
@SimpleProperty(description = "Specifies whether the component should be visible on the screen. "
+ "Value is true if the component is showing and false if hidden.")
public void Visible(Boolean visibility) {
// The principle of least astonishment suggests we not offer the
// Android option INVISIBLE.
getView().setVisibility(visible ? View.VISIBLE : View.GONE);
getView().setVisibility(visibility ? View.VISIBLE : View.GONE);
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment