diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2014-06-04 19:32:05 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-06-04 19:32:05 +0000 |
commit | 61fb5784322fce5198e74834c32c8d8c547a8adf (patch) | |
tree | b071aa33d4bf14bfc585e6bcfeaa8546f82418af /tools | |
parent | f48ab8feec71419e574a2d2f08a29be87743ef07 (diff) | |
parent | 3ff08eb6bf68868d4f4e872fbbf1ecaf521934a9 (diff) | |
download | frameworks_base-61fb5784322fce5198e74834c32c8d8c547a8adf.zip frameworks_base-61fb5784322fce5198e74834c32c8d8c547a8adf.tar.gz frameworks_base-61fb5784322fce5198e74834c32c8d8c547a8adf.tar.bz2 |
am 3ff08eb6: Distinguish between menus in ActionBar and popup. [DO NOT MERGE]
* commit '3ff08eb6bf68868d4f4e872fbbf1ecaf521934a9':
Distinguish between menus in ActionBar and popup. [DO NOT MERGE]
Diffstat (limited to 'tools')
3 files changed, 55 insertions, 34 deletions
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 97b07c7..253af58 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 @@ -22,11 +22,8 @@ import com.android.ide.common.rendering.api.ActionBarCallback.HomeButtonStyle; import com.android.ide.common.rendering.api.RenderResources; import com.android.ide.common.rendering.api.ResourceValue; import com.android.ide.common.rendering.api.SessionParams; -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; @@ -59,8 +56,6 @@ import android.widget.RelativeLayout; import java.util.ArrayList; -import static com.android.ide.common.rendering.api.SystemViewCookie.ACTION_BAR_OVERFLOW; - /** * A layout representing the action bar. */ @@ -175,29 +170,6 @@ public class ActionBarLayout extends LinearLayout { mActionBarView.setSplitActionBar(mSplit); inflateMenus(); - - // Find if the Overflow Menu Button (the three dots) exists. If yes, - // add the view cookie. - Predicate<View> overflowMenuButtonTest = new Predicate<View>() { - @Override - public boolean apply(View view) { - ViewGroup.LayoutParams lp = view.getLayoutParams(); - return lp instanceof ActionMenuView.LayoutParams && - ((ActionMenuView.LayoutParams) lp).isOverflowButton; - } - }; - View overflowMenu = null; - if (mSplit) { - if (splitView != null) { - overflowMenu = splitView.findViewByPredicate(overflowMenuButtonTest); - } - } - else { - overflowMenu = mActionBarView.findViewByPredicate(overflowMenuButtonTest); - } - if (overflowMenu != null) { - mBridgeContext.addViewKey(overflowMenu, new SystemViewCookie(ACTION_BAR_OVERFLOW)); - } } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index 1d1c73f..30c625f 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -37,8 +37,10 @@ import com.android.ide.common.rendering.api.Result.Status; import com.android.ide.common.rendering.api.SessionParams; import com.android.ide.common.rendering.api.SessionParams.RenderingMode; import com.android.ide.common.rendering.api.ViewInfo; +import com.android.ide.common.rendering.api.ViewType; import com.android.internal.util.XmlUtils; import com.android.internal.view.menu.ActionMenuItemView; +import com.android.internal.view.menu.ActionMenuView; import com.android.internal.view.menu.BridgeMenuItemImpl; import com.android.internal.view.menu.IconMenuItemView; import com.android.internal.view.menu.ListMenuItemView; @@ -83,6 +85,7 @@ import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.MarginLayoutParams; +import android.view.ViewParent; import android.widget.AbsListView; import android.widget.AbsSpinner; import android.widget.AdapterView; @@ -1456,16 +1459,49 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { ViewInfo result; if (isContentFrame) { + // The view is part of the layout added by the user. Hence, + // the ViewCookie may be obtained only through the Context. result = new ViewInfo(view.getClass().getName(), - getViewKey(view), + getContext().getViewKey(view), view.getLeft(), view.getTop() + offset, view.getRight(), view.getBottom() + offset, view, view.getLayoutParams()); - } else { - result = new SystemViewInfo(view.getClass().getName(), + // We are part of the system decor. + SystemViewInfo r = new SystemViewInfo(view.getClass().getName(), getViewKey(view), view.getLeft(), view.getTop(), view.getRight(), view.getBottom(), view, view.getLayoutParams()); + result = r; + // We currently mark three kinds of views: + // 1. Menus in the Action Bar + // 2. Menus in the Overflow popup. + // 3. The overflow popup button. + if (view instanceof ListMenuItemView) { + // Mark 2. + // All menus in the popup are of type ListMenuItemView. + r.setViewType(ViewType.ACTION_BAR_OVERFLOW_MENU); + } else { + // Mark 3. + ViewGroup.LayoutParams lp = view.getLayoutParams(); + if (lp instanceof ActionMenuView.LayoutParams && + ((ActionMenuView.LayoutParams) lp).isOverflowButton) { + r.setViewType(ViewType.ACTION_BAR_OVERFLOW); + } else { + // Mark 1. + // A view is a menu in the Action Bar is it is not the overflow button and of + // its parent is of type ActionMenuView. We can also check if the view is + // instanceof ActionMenuItemView but that will fail for menus using + // actionProviderClass. + ViewParent parent = view.getParent(); + while (parent != mViewRoot && parent instanceof ViewGroup) { + if (parent instanceof ActionMenuView) { + r.setViewType(ViewType.ACTION_BAR_MENU); + break; + } + parent = parent.getParent(); + } + } + } } if (setExtendedInfo) { @@ -1484,7 +1520,7 @@ public class RenderSessionImpl extends RenderAction<SessionParams> { return result; } - /** + /* (non-Javadoc) * The cookie for menu items are stored in menu item and not in the map from View stored in * BridgeContext. */ diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java index 5c267df..9fea167 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java @@ -17,9 +17,15 @@ package com.android.layoutlib.bridge.impl; import com.android.ide.common.rendering.api.ViewInfo; +import com.android.ide.common.rendering.api.ViewType; +/** + * ViewInfo for views added by the platform. + */ public class SystemViewInfo extends ViewInfo { + private ViewType mViewType; + public SystemViewInfo(String name, Object cookie, int left, int top, int right, int bottom) { super(name, cookie, left, top, right, bottom); @@ -32,7 +38,14 @@ public class SystemViewInfo extends ViewInfo { } @Override - public boolean isSystemView() { - return true; + public ViewType getViewType() { + if (mViewType != null) { + return mViewType; + } + return ViewType.SYSTEM_UNKNOWN; + } + + public void setViewType(ViewType type) { + mViewType = type; } } |