diff options
| author | 2014-05-15 09:32:12 -0700 | |
|---|---|---|
| committer | 2014-05-29 18:22:04 -0700 | |
| commit | 3885220ed562b82d9109bb305c2f9db75853c6ed (patch) | |
| tree | ba12315191e3cca275fe494331979d2dcbc37626 | |
| parent | 432fe9829744983576f0afabb4b73165f9695a8f (diff) | |
Distinguish between menus in ActionBar and popup.
Mark the menus in the ActionBar and the ones in the Overflow popup
separately. This enables the IDE to differentiate between the two and
enable gestures such as double-click to open the menu xml for menus in
the ActionBar and single click for the menus in the Overflow popup.
Change-Id: I7a23f87d34d618a134ffbe3a665be695915d4bae
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 e59ccd735f4d..d95c815771de 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 @@ -23,10 +23,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.WindowDecorActionBar; -import com.android.internal.util.Predicate; import com.android.internal.view.menu.MenuBuilder; import com.android.internal.view.menu.MenuItemImpl; import com.android.internal.widget.ActionBarAccessor; @@ -50,7 +48,6 @@ import android.view.LayoutInflater; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ActionMenuView; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.ListAdapter; @@ -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. */ @@ -174,29 +169,6 @@ public class ActionBarLayout extends LinearLayout { mActionBarView.setSplitToolbar(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 4af73cf52814..13b822c74a9d 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,6 +37,7 @@ 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.BridgeMenuItemImpl; @@ -83,9 +84,11 @@ 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.view.WindowManagerGlobal_Delegate; import android.widget.AbsListView; import android.widget.AbsSpinner; +import android.widget.ActionMenuView; import android.widget.AdapterView; import android.widget.ExpandableListView; import android.widget.FrameLayout; @@ -1473,16 +1476,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) { @@ -1501,7 +1537,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 5c267df56a3a..9fea1677d5f2 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; } } |