summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2014-04-18 12:32:38 -0700
committerDeepanshu Gupta <deepanshu@google.com>2014-05-04 13:29:14 -0700
commit094fd8ecb6f4b666be6c9e7332679bce28fdc3ca (patch)
tree7338cbdd74ca211525fb12553d6dde3f2d808de3 /core
parent56759be8960ea1b5dc8b6de1810a84e2f10e2058 (diff)
downloadframeworks_base-094fd8ecb6f4b666be6c9e7332679bce28fdc3ca.zip
frameworks_base-094fd8ecb6f4b666be6c9e7332679bce28fdc3ca.tar.gz
frameworks_base-094fd8ecb6f4b666be6c9e7332679bce28fdc3ca.tar.bz2
Add view cookies for action bar menus. [DO NOT MERGE]
The change adds the view cookies for the menus rendered in the action bar. This enables the IDE to map the menu to the relevant XML Tag in the menu xml and show the highlighting accordingly. The change also contains a bugfix where a method wasn't renamed properly. Change-Id: Idcfc263a8ebe0a4f25afa3a1eb085fa628fd03ca (cherry-picked from commit 7704837947455909f295b088a3d15a20e107dbd7)
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/MenuInflater.java36
-rw-r--r--core/java/com/android/internal/view/menu/MenuBuilder.java13
2 files changed, 41 insertions, 8 deletions
diff --git a/core/java/android/view/MenuInflater.java b/core/java/android/view/MenuInflater.java
index a7ee12b..71296fa 100644
--- a/core/java/android/view/MenuInflater.java
+++ b/core/java/android/view/MenuInflater.java
@@ -161,6 +161,7 @@ public class MenuInflater {
} else if (tagName.equals(XML_MENU)) {
// A menu start tag denotes a submenu for an item
SubMenu subMenu = menuState.addSubMenuItem();
+ registerMenu(subMenu, attrs);
// Parse the submenu into returned SubMenu
parseMenu(parser, attrs, subMenu);
@@ -183,9 +184,9 @@ public class MenuInflater {
if (!menuState.hasAddedItem()) {
if (menuState.itemActionProvider != null &&
menuState.itemActionProvider.hasSubMenu()) {
- menuState.addSubMenuItem();
+ registerMenu(menuState.addSubMenuItem(), attrs);
} else {
- menuState.addItem();
+ registerMenu(menuState.addItem(), attrs);
}
}
} else if (tagName.equals(XML_MENU)) {
@@ -200,7 +201,30 @@ public class MenuInflater {
eventType = parser.next();
}
}
-
+
+ /**
+ * The method is a hook for layoutlib to do its magic.
+ * Nothing is needed outside of LayoutLib. However, it should not be deleted because it
+ * appears to do nothing.
+ */
+ private void registerMenu(@SuppressWarnings("unused") MenuItem item,
+ @SuppressWarnings("unused") AttributeSet set) {
+ }
+
+ /**
+ * The method is a hook for layoutlib to do its magic.
+ * Nothing is needed outside of LayoutLib. However, it should not be deleted because it
+ * appears to do nothing.
+ */
+ private void registerMenu(@SuppressWarnings("unused") SubMenu subMenu,
+ @SuppressWarnings("unused") AttributeSet set) {
+ }
+
+ // Needed by layoutlib.
+ /*package*/ Context getContext() {
+ return mContext;
+ }
+
private static class InflatedOnMenuItemClickListener
implements MenuItem.OnMenuItemClickListener {
private static final Class<?>[] PARAM_TYPES = new Class[] { MenuItem.class };
@@ -446,9 +470,11 @@ public class MenuInflater {
}
}
- public void addItem() {
+ public MenuItem addItem() {
itemAdded = true;
- setItem(menu.add(groupId, itemId, itemCategoryOrder, itemTitle));
+ MenuItem item = menu.add(groupId, itemId, itemCategoryOrder, itemTitle);
+ setItem(item);
+ return item;
}
public SubMenu addSubMenuItem() {
diff --git a/core/java/com/android/internal/view/menu/MenuBuilder.java b/core/java/com/android/internal/view/menu/MenuBuilder.java
index 458ea2f..542e61e 100644
--- a/core/java/com/android/internal/view/menu/MenuBuilder.java
+++ b/core/java/com/android/internal/view/menu/MenuBuilder.java
@@ -386,8 +386,8 @@ public class MenuBuilder implements Menu {
private MenuItem addInternal(int group, int id, int categoryOrder, CharSequence title) {
final int ordering = getOrdering(categoryOrder);
- final MenuItemImpl item = new MenuItemImpl(this, group, id, categoryOrder,
- ordering, title, mDefaultShowAsAction);
+ final MenuItemImpl item = createNewMenuItem(group, id, categoryOrder, ordering, title,
+ mDefaultShowAsAction);
if (mCurrentMenuInfo != null) {
// Pass along the current menu info
@@ -399,7 +399,14 @@ public class MenuBuilder implements Menu {
return item;
}
-
+
+ // Layoutlib overrides this method to return its custom implementation of MenuItemImpl
+ private MenuItemImpl createNewMenuItem(int group, int id, int categoryOrder, int ordering,
+ CharSequence title, int defaultShowAsAction) {
+ return new MenuItemImpl(this, group, id, categoryOrder, ordering, title,
+ defaultShowAsAction);
+ }
+
public MenuItem add(CharSequence title) {
return addInternal(0, 0, 0, title);
}