Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bac0d9ae authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

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
(cherry picked from commit f542f28a31b38a4e454535a1fea63968811b418c)
parent 15c3fd31
Loading
Loading
Loading
Loading
+0 −28
Original line number Diff line number Diff line
@@ -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));
            }
        }
    }

+40 −4
Original line number Diff line number Diff line
@@ -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.
     */
+15 −2
Original line number Diff line number Diff line
@@ -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;
    }
}