am 52a86f17: am 7f56beb8: Support actionProviderClass attribute for menus [DO NOT MERGE]
* commit '52a86f17ea4940561c6d73ac226bef177a84c035':
Support actionProviderClass attribute for menus [DO NOT MERGE]
diff --git a/tools/layoutlib/bridge/src/com/android/internal/view/menu/BridgeMenuItemImpl.java b/tools/layoutlib/bridge/src/com/android/internal/view/menu/BridgeMenuItemImpl.java
index 4bef424..cdb839a 100644
--- a/tools/layoutlib/bridge/src/com/android/internal/view/menu/BridgeMenuItemImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/internal/view/menu/BridgeMenuItemImpl.java
@@ -16,6 +16,12 @@
package com.android.internal.view.menu;
+import com.android.layoutlib.bridge.android.BridgeContext;
+
+import android.content.Context;
+import android.view.ContextThemeWrapper;
+import android.view.View;
+
/**
* An extension of the {@link MenuItemImpl} to store the view cookie also.
*/
@@ -27,6 +33,7 @@
* at the time of rendering.
*/
private Object viewCookie;
+ private BridgeContext mContext;
/**
* Instantiates this menu item.
@@ -34,14 +41,28 @@
BridgeMenuItemImpl(MenuBuilder menu, int group, int id, int categoryOrder, int ordering,
CharSequence title, int showAsAction) {
super(menu, group, id, categoryOrder, ordering, title, showAsAction);
+ Context context = menu.getContext();
+ if (context instanceof ContextThemeWrapper) {
+ context = ((ContextThemeWrapper) context).getBaseContext();
+ }
+ if (context instanceof BridgeContext) {
+ mContext = ((BridgeContext) context);
+ }
}
-
public Object getViewCookie() {
return viewCookie;
}
public void setViewCookie(Object viewCookie) {
+ // If the menu item has an associated action provider view,
+ // directly set the cookie in the view to cookie map stored in BridgeContext.
+ View actionView = getActionView();
+ if (actionView != null && mContext != null) {
+ mContext.addViewKey(actionView, viewCookie);
+ // We don't need to add the view cookie to the this item now. But there's no harm in
+ // storing it, in case we need it in the future.
+ }
this.viewCookie = viewCookie;
}
}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java
index 349f330..9082e27 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java
@@ -27,6 +27,7 @@
import com.android.internal.R;
import com.android.internal.app.ActionBarImpl;
import com.android.internal.util.Predicate;
+import com.android.internal.view.menu.ActionMenuView;
import com.android.internal.view.menu.MenuBuilder;
import com.android.internal.view.menu.MenuBuilderAccessor;
import com.android.internal.view.menu.MenuItemImpl;
@@ -181,8 +182,9 @@
Predicate<View> overflowMenuButtonTest = new Predicate<View>() {
@Override
public boolean apply(View view) {
- return view.getClass().getName().equals("com.android.internal.view.menu." +
- "ActionMenuPresenter$OverflowMenuButton");
+ ViewGroup.LayoutParams lp = view.getLayoutParams();
+ return lp instanceof ActionMenuView.LayoutParams &&
+ ((ActionMenuView.LayoutParams) lp).isOverflowButton;
}
};
View overflowMenu = null;