Distinguish between menus in ActionBar and popup. [DO NOT MERGE]

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
(cherry picked from commit 03c0735017)
This commit is contained in:
Deepanshu Gupta
2014-05-15 09:32:12 -07:00
parent 3b7c09b433
commit 3ff08eb6bf
3 changed files with 55 additions and 34 deletions

View File

@ -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));
}
}
}

View File

@ -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.
*/

View File

@ -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;
}
}