summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Deepanshu Gupta <deepanshu@google.com> 2014-05-01 16:18:34 -0700
committer Deepanshu Gupta <deepanshu@google.com> 2014-05-01 20:13:06 -0700
commitd25d33cdebeb5a363b299939017a0cdfa42c7338 (patch)
treeb0ef15a9924fd0c9fd068041ecdcebcde5f7353d
parent4b5fa4d318e7efaffdc678e0cb8953ffc78c2b1e (diff)
Support actionProviderClass attribute for menus [DO NOT MERGE]
The change adds support for view cookies for actionProviderClasses (for example, ShareActionProvider) in the action bar menus. This also provides a more robust search for the overflowMenuButton. Change-Id: I316c8b9a69e2e337b41ba0fe4e61af9fe850f750 (cherry picked from commit 28fa661f79e18fc9fc46bf112edded9c0d07696f)
-rw-r--r--tools/layoutlib/bridge/src/com/android/internal/view/menu/BridgeMenuItemImpl.java23
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java6
2 files changed, 26 insertions, 3 deletions
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 4bef424f506c..cdb839adb451 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 @@ public class BridgeMenuItemImpl extends MenuItemImpl {
* at the time of rendering.
*/
private Object viewCookie;
+ private BridgeContext mContext;
/**
* Instantiates this menu item.
@@ -34,14 +41,28 @@ public class BridgeMenuItemImpl extends MenuItemImpl {
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 f82ca653df40..0e39a572a594 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.ide.common.rendering.api.SystemViewCookie;
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;
@@ -180,8 +181,9 @@ public class ActionBarLayout extends LinearLayout {
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;