aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2011-02-08 12:17:33 -0800
committerTor Norbye <tnorbye@google.com>2011-02-08 12:17:33 -0800
commit523c97de99580f005611d982df0459324267cf1b (patch)
treee12ee995e5ede1f6606c2700ff35d7b829265396
parent3affb7747350f449529260744f37e0274f8fac50 (diff)
downloadplatform_sdk-523c97de99580f005611d982df0459324267cf1b.tar.gz
platform_sdk-523c97de99580f005611d982df0459324267cf1b.tar.bz2
platform_sdk-523c97de99580f005611d982df0459324267cf1b.zip
Layout Actions bar fixes
This changeset fixes a couple of layout actions bar issues: (1) Refresh the actions bar after running one of the layout actions. This for example fixes the issue that if you click to toggle the layout orientation then the baseline button will appear for horizontal layouts. (2) Fix an issue with the lazy-initialization of dropdown menus; they weren't actually initialized lazily because the code to determine whether a choice list should be a dropdown or a radio group would cause initialization. (3) Fix layout gravity on RelativeLayouts; it was reading/writing the attribute "layout_gravity" instead of "gravity". Change-Id: Ic41158257b3938a2e6daa8714dcd15d6bf21fa2f
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/api/MenuAction.java25
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java10
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java4
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java1
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java10
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RelativeLayoutRule.java4
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java36
7 files changed, 64 insertions, 26 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/api/MenuAction.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/api/MenuAction.java
index e54ae360e..3e912f875 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/api/MenuAction.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/api/MenuAction.java
@@ -121,7 +121,7 @@ public abstract class MenuAction implements Comparable<MenuAction> {
return action;
}
- public static MenuAction createChoices(String id, String title, String groupId,
+ public static OrderedChoices createChoices(String id, String title, String groupId,
IMenuCallback callback, List<String> titles, List<URL> iconUrls, List<String> ids,
String current, URL iconUrl, int sortPriority) {
OrderedChoices choices = new OrderedChoices(id, title, groupId, callback, titles, iconUrls,
@@ -131,7 +131,7 @@ public abstract class MenuAction implements Comparable<MenuAction> {
return choices;
}
- public static MenuAction createChoices(String id, String title, String groupId,
+ public static OrderedChoices createChoices(String id, String title, String groupId,
IMenuCallback callback, ChoiceProvider provider,
String current, URL iconUrl, int sortPriority) {
OrderedChoices choices = new DelayedOrderedChoices(id, title, groupId, callback,
@@ -437,6 +437,7 @@ public abstract class MenuAction implements Comparable<MenuAction> {
protected List<String> mTitles;
protected List<URL> mIconUrls;
protected List<String> mIds;
+ private boolean mRadio;
/**
* One or more id for the checked choice(s) that will be check marked.
@@ -468,6 +469,26 @@ public abstract class MenuAction implements Comparable<MenuAction> {
public String getCurrent() {
return mCurrent;
}
+
+ /**
+ * Set whether this choice list is best visualized as a radio group (instead of a
+ * dropdown)
+ *
+ * @param radio true if this choice list should be visualized as a radio group
+ */
+ public void setRadio(boolean radio) {
+ mRadio = radio;
+ }
+
+ /**
+ * Returns true if this choice list is best visualized as a radio group (instead
+ * of a dropdown)
+ *
+ * @return true if this choice list should be visualized as a radio group
+ */
+ public boolean isRadio() {
+ return mRadio;
+ }
}
/** Provides the set of choices associated with an {@link OrderedChoices} object
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java
index a33594c58..bd6c80633 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/BaseLayoutRule.java
@@ -18,7 +18,6 @@ package com.android.ide.common.layout;
import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI;
import static com.android.ide.common.layout.LayoutConstants.ATTR_ID;
-import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_GRAVITY;
import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT;
import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_MARGIN;
import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_MARGIN_BOTTOM;
@@ -113,13 +112,14 @@ public class BaseLayoutRule extends BaseViewRule {
// Both LinearLayout and RelativeLayout have a gravity (but RelativeLayout applies it
// to the parent whereas for LinearLayout it's on the children)
- protected MenuAction createGravityAction(final List<? extends INode> targets) {
+ protected MenuAction createGravityAction(final List<? extends INode> targets, final
+ String attributeName) {
if (targets != null && targets.size() > 0) {
final INode first = targets.get(0);
ChoiceProvider provider = new ChoiceProvider() {
public void addChoices(List<String> titles, List<URL> iconUrls,
List<String> ids) {
- IAttributeInfo info = first.getAttributeInfo(ANDROID_URI, ATTR_LAYOUT_GRAVITY);
+ IAttributeInfo info = first.getAttributeInfo(ANDROID_URI, attributeName);
if (info != null) {
// Generate list of possible gravity value constants
assert IAttributeInfo.Format.FLAG.in(info.getFormats());
@@ -134,9 +134,9 @@ public class BaseLayoutRule extends BaseViewRule {
return MenuAction.createChoices("_gravity", "Change Gravity", //$NON-NLS-1$
null,
new PropertyCallback(targets, "Change Gravity", ANDROID_URI,
- ATTR_LAYOUT_GRAVITY),
+ attributeName),
provider,
- first.getStringAttr(ANDROID_URI, ATTR_LAYOUT_GRAVITY), ICON_GRAVITY,
+ first.getStringAttr(ANDROID_URI, attributeName), ICON_GRAVITY,
43);
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java
index 0f8fa1845..655eee229 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java
@@ -16,6 +16,8 @@
package com.android.ide.common.layout;
+import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_GRAVITY;
+
import com.android.ide.common.api.DrawingStyle;
import com.android.ide.common.api.DropFeedback;
import com.android.ide.common.api.IDragElement;
@@ -154,7 +156,7 @@ public class FrameLayoutRule extends BaseLayoutRule {
actions.add(MenuAction.createSeparator(25));
actions.add(createMarginAction(parentNode, children));
if (children.size() > 0) {
- actions.add(createGravityAction(children));
+ actions.add(createGravityAction(children, ATTR_LAYOUT_GRAVITY));
}
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java
index ef7bba7b1..ee5a8c997 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java
@@ -143,6 +143,7 @@ public class LayoutConstants {
// like fill_parent for API 8
public static final String VALUE_MATCH_PARENT = "match_parent"; //$NON-NLS-1$
+ public static final String ATTR_GRAVITY = "gravity"; //$NON-NLS-1$
public static final String ATTR_WEIGHT_SUM = "weightSum"; //$NON-NLS-1$
public static final String ATTR_BASELINE_ALIGNED = "baselineAligned"; //$NON-NLS-1$
public static String ATTR_ORIENTATION = "orientation"; //$NON-NLS-1$
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java
index 3efa2201d..1e2d0e320 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LinearLayoutRule.java
@@ -18,6 +18,7 @@ package com.android.ide.common.layout;
import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI;
import static com.android.ide.common.layout.LayoutConstants.ATTR_BASELINE_ALIGNED;
+import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_GRAVITY;
import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT;
import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WEIGHT;
import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH;
@@ -41,6 +42,7 @@ import com.android.ide.common.api.MenuAction;
import com.android.ide.common.api.Point;
import com.android.ide.common.api.Rect;
import com.android.ide.common.api.IViewMetadata.FillPreference;
+import com.android.ide.common.api.MenuAction.OrderedChoices;
import java.net.URL;
import java.util.ArrayList;
@@ -131,7 +133,7 @@ public class LinearLayoutRule extends BaseLayoutRule {
final List<? extends INode> children) {
super.addLayoutActions(actions, parentNode, children);
if (supportsOrientation()) {
- actions.add(MenuAction.createChoices(
+ OrderedChoices action = MenuAction.createChoices(
ACTION_ORIENTATION, "Orientation", //$NON-NLS-1$
null,
new PropertyCallback(Collections.singletonList(parentNode),
@@ -143,7 +145,9 @@ public class LinearLayoutRule extends BaseLayoutRule {
getCurrentOrientation(parentNode),
null /* icon */,
-10
- ));
+ );
+ action.setRadio(true);
+ actions.add(action);
}
if (!isVertical(parentNode)) {
String current = parentNode.getStringAttr(ANDROID_URI, ATTR_BASELINE_ALIGNED);
@@ -164,7 +168,7 @@ public class LinearLayoutRule extends BaseLayoutRule {
actions.add(createMarginAction(parentNode, children));
// Gravity
- actions.add(createGravityAction(children));
+ actions.add(createGravityAction(children, ATTR_LAYOUT_GRAVITY));
// Weights
IMenuCallback actionCallback = new IMenuCallback() {
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RelativeLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RelativeLayoutRule.java
index b7160edea..33fe202bf 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RelativeLayoutRule.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/RelativeLayoutRule.java
@@ -17,6 +17,7 @@
package com.android.ide.common.layout;
import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI;
+import static com.android.ide.common.layout.LayoutConstants.ATTR_GRAVITY;
import static com.android.ide.common.layout.LayoutConstants.ATTR_ID;
import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_PREFIX;
import static com.android.ide.common.layout.LayoutConstants.VALUE_ABOVE;
@@ -659,7 +660,8 @@ public class RelativeLayoutRule extends BaseLayoutRule {
final List<? extends INode> children) {
super.addLayoutActions(actions, parentNode, children);
- actions.add(createGravityAction(Collections.<INode>singletonList(parentNode)));
+ actions.add(createGravityAction(Collections.<INode>singletonList(parentNode),
+ ATTR_GRAVITY));
actions.add(MenuAction.createSeparator(25));
actions.add(createMarginAction(parentNode, children));
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java
index e64004dc2..5f2450cb3 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutActionBar.java
@@ -32,6 +32,7 @@ import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -145,8 +146,7 @@ public class LayoutActionBar extends Composite {
if (action instanceof MenuAction.OrderedChoices) {
final MenuAction.OrderedChoices choices = (OrderedChoices) action;
- final List<URL> icons = choices.getIconUrls();
- if (icons == null || icons.size() == 0) {
+ if (!choices.isRadio()) {
addDropdown(choices);
} else {
addSeparator(mLayoutToolBar);
@@ -191,6 +191,7 @@ public class LayoutActionBar extends Composite {
public void widgetSelected(SelectionEvent e) {
toggle.getCallback().action(toggle, toggle.getId(),
button.getSelection());
+ updateSelection();
}
});
if (toggle.isChecked()) {
@@ -214,15 +215,16 @@ public class LayoutActionBar extends Composite {
@Override
public void widgetSelected(SelectionEvent e) {
menuAction.getCallback().action(menuAction, menuAction.getId(), false);
+ updateSelection();
}
});
}
private void addRadio(final MenuAction.OrderedChoices choices) {
- final List<URL> icons = choices.getIconUrls();
- final List<String> titles = choices.getTitles();
- final List<String> ids = choices.getIds();
- final String current = choices.getCurrent() != null ? choices.getCurrent() : ""; //$NON-NLS-1$
+ List<URL> icons = choices.getIconUrls();
+ List<String> titles = choices.getTitles();
+ List<String> ids = choices.getIds();
+ String current = choices.getCurrent() != null ? choices.getCurrent() : ""; //$NON-NLS-1$
assert icons != null;
assert icons.size() == titles.size();
@@ -239,6 +241,7 @@ public class LayoutActionBar extends Composite {
public void widgetSelected(SelectionEvent e) {
if (item.getSelection()) {
choices.getCallback().action(choices, id, null);
+ updateSelection();
}
}
});
@@ -250,13 +253,6 @@ public class LayoutActionBar extends Composite {
}
private void addDropdown(final MenuAction.OrderedChoices choices) {
- final List<URL> icons = choices.getIconUrls();
- final List<String> titles = choices.getTitles();
- final List<String> ids = choices.getIds();
- final String current = choices.getCurrent() != null ? choices.getCurrent() : ""; //$NON-NLS-1$
-
- assert icons == null || icons.size() == 0;
-
final ToolItem combo = new ToolItem(mLayoutToolBar, SWT.DROP_DOWN);
URL iconUrl = choices.getIconUrl();
if (iconUrl != null) {
@@ -272,12 +268,23 @@ public class LayoutActionBar extends Composite {
Point point = new Point(event.x, event.y);
point = combo.getDisplay().map(mLayoutToolBar, null, point);
- final Menu menu = new Menu(mLayoutToolBar.getShell(), SWT.POP_UP);
+ Menu menu = new Menu(mLayoutToolBar.getShell(), SWT.POP_UP);
+
+ List<URL> icons = choices.getIconUrls();
+ List<String> titles = choices.getTitles();
+ List<String> ids = choices.getIds();
+ String current = choices.getCurrent() != null ? choices.getCurrent() : ""; //$NON-NLS-1$
+
for (int i = 0; i < titles.size(); i++) {
String title = titles.get(i);
final String id = ids.get(i);
+ URL itemIconUrl = icons != null && icons.size() > 0 ? icons.get(i) : null;
MenuItem item = new MenuItem(menu, SWT.CHECK);
item.setText(title);
+ if (itemIconUrl != null) {
+ Image itemIcon = IconFactory.getInstance().getIcon(itemIconUrl);
+ item.setImage(itemIcon);
+ }
boolean selected = id.equals(current);
if (selected) {
@@ -288,6 +295,7 @@ public class LayoutActionBar extends Composite {
@Override
public void widgetSelected(SelectionEvent e) {
choices.getCallback().action(choices, id, null);
+ updateSelection();
}
});
}