diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2014-10-30 11:44:14 -0700 |
---|---|---|
committer | Deepanshu Gupta <deepanshu@google.com> | 2014-10-30 11:58:37 -0700 |
commit | df0ebab0f954044c39b171160ab4276dd2391993 (patch) | |
tree | c3a4b54d6a7e5625fd79b5bb24a3090862705e71 /tools | |
parent | 0bffc736e1f260724764d31f7499cbc09471a535 (diff) | |
download | frameworks_base-df0ebab0f954044c39b171160ab4276dd2391993.zip frameworks_base-df0ebab0f954044c39b171160ab4276dd2391993.tar.gz frameworks_base-df0ebab0f954044c39b171160ab4276dd2391993.tar.bz2 |
Support framework menus in ActionBar
Add support for adding menus in the framework namespace to the ActionBar
preview. If a menu id name begins with the android namespace prefix
(android:) we find the framework menu and render it.
Change-Id: If52910b46154591883af2b2f357e72eea6f84235
Diffstat (limited to 'tools')
-rw-r--r-- | tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomActionBarWrapper.java | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomActionBarWrapper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomActionBarWrapper.java index f3fc397..f283e34 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomActionBarWrapper.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/CustomActionBarWrapper.java @@ -32,7 +32,6 @@ import com.android.internal.widget.ActionBarView; import com.android.internal.widget.DecorToolbar; import com.android.layoutlib.bridge.android.BridgeContext; import com.android.layoutlib.bridge.impl.ResourceHelper; -import com.android.resources.ResourceType; import android.app.ActionBar; import android.app.ActionBar.Tab; @@ -49,6 +48,9 @@ import android.widget.ActionMenuPresenter; import android.widget.Toolbar; import android.widget.Toolbar_Accessor; +import static com.android.SdkConstants.ANDROID_NS_NAME_PREFIX; +import static com.android.resources.ResourceType.MENU; + /** * A common API to access {@link ToolbarActionBar} and {@link WindowDecorActionBar}. */ @@ -128,13 +130,24 @@ public abstract class CustomActionBarWrapper { MenuInflater inflater = new MenuInflater(getActionMenuContext()); MenuBuilder menuBuilder = getMenuBuilder(); for (String name : mCallback.getMenuIdNames()) { - if (mContext.getRenderResources().getProjectResource(ResourceType.MENU, name) - != null) { - int id = mContext.getProjectResourceValue(ResourceType.MENU, name, -1); - if (id > -1) { - inflater.inflate(id, menuBuilder); + int id = -1; + if (name.startsWith(ANDROID_NS_NAME_PREFIX)) { + // Framework menu. + name = name.substring(ANDROID_NS_NAME_PREFIX.length()); + if (mContext.getRenderResources().getFrameworkResource(MENU, name) != null) { + // We need to check for the existence of the menu first, since getting the id + // never returns the default value. It creates a new value if one is not found. + id = mContext.getFrameworkResourceValue(MENU, name, -1); + } + } else { + // Project menu. + if (mContext.getRenderResources().getProjectResource(MENU, name) != null) { + id = mContext.getProjectResourceValue(MENU, name, -1); } } + if (id > -1) { + inflater.inflate(id, menuBuilder); + } } } |