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

Commit 31d5becb authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Bug 2923440 - ActionMode buttons show if room by default - different approach."

parents 89c7ec34 4d9861e7
Loading
Loading
Loading
Loading
+8 −15
Original line number Diff line number Diff line
@@ -54,23 +54,13 @@ public class MenuInflater {
    
    private Context mContext;
    
    private int mDefaultShowAsAction;

    /**
     * Constructs a menu inflater.
     * 
     * @see Activity#getMenuInflater()
     */
    public MenuInflater(Context context) {
        this(context, MenuItem.SHOW_AS_ACTION_NEVER);
    }

    /**
     * @hide used internally to change the default showAsAction setting in action modes
     */
    public MenuInflater(Context context, int defaultShowAsAction) {
        mContext = context;
        mDefaultShowAsAction = defaultShowAsAction;
    }

    /**
@@ -256,6 +246,7 @@ public class MenuInflater {
         * - 0: never
         * - 1: ifRoom
         * - 2: always
         * - -1: Safe sentinel for "no value".
         */
        private int itemShowAsAction;
        
@@ -272,7 +263,6 @@ public class MenuInflater {
        
        public MenuState(final Menu menu) {
            this.menu = menu;
            this.itemShowAsAction = mDefaultShowAsAction;
            
            resetGroup();
        }
@@ -333,7 +323,7 @@ public class MenuInflater {
            itemChecked = a.getBoolean(com.android.internal.R.styleable.MenuItem_checked, defaultItemChecked);
            itemVisible = a.getBoolean(com.android.internal.R.styleable.MenuItem_visible, groupVisible);
            itemEnabled = a.getBoolean(com.android.internal.R.styleable.MenuItem_enabled, groupEnabled);
            itemShowAsAction = a.getInt(com.android.internal.R.styleable.MenuItem_showAsAction, 0);
            itemShowAsAction = a.getInt(com.android.internal.R.styleable.MenuItem_showAsAction, -1);
            itemListenerMethodName = a.getString(com.android.internal.R.styleable.MenuItem_onClick);
            
            a.recycle();
@@ -357,8 +347,11 @@ public class MenuInflater {
                .setTitleCondensed(itemTitleCondensed)
                .setIcon(itemIconResId)
                .setAlphabeticShortcut(itemAlphabeticShortcut)
                .setNumericShortcut(itemNumericShortcut)
                .setShowAsAction(itemShowAsAction);
                .setNumericShortcut(itemNumericShortcut);
            
            if (itemShowAsAction >= 0) {
                item.setShowAsAction(itemShowAsAction);
            }
            
            if (itemListenerMethodName != null) {
                if (mContext.isRestricted()) {
+3 −2
Original line number Diff line number Diff line
@@ -429,13 +429,14 @@ public class ActionBarImpl extends ActionBar {
        
        public ActionModeImpl(ActionMode.Callback callback) {
            mCallback = callback;
            mMenu = new MenuBuilder(mActionView.getContext());
            mMenu = new MenuBuilder(mActionView.getContext())
                    .setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            mMenu.setCallback(this);
        }

        @Override
        public MenuInflater getMenuInflater() {
            return new MenuInflater(mContext, MenuItem.SHOW_AS_ACTION_IF_ROOM);
            return new MenuInflater(mContext);
        }

        @Override
+2 −2
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public class StandaloneActionMode extends ActionMode implements MenuBuilder.Call
        mContextView = view;
        mCallback = callback;

        mMenu = new MenuBuilder(context);
        mMenu = new MenuBuilder(context).setDefaultShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        mMenu.setCallback(this);
    }

@@ -112,7 +112,7 @@ public class StandaloneActionMode extends ActionMode implements MenuBuilder.Call

    @Override
    public MenuInflater getMenuInflater() {
        return new MenuInflater(mContext, MenuItem.SHOW_AS_ACTION_IF_ROOM);
        return new MenuInflater(mContext);
    }

    public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
+12 −1
Original line number Diff line number Diff line
@@ -170,6 +170,11 @@ public class MenuBuilder implements Menu {
     */
    private boolean mReserveActionOverflow;

    /**
     * Default value for how added items should show in the action list.
     */
    private int mDefaultShowAsAction = MenuItem.SHOW_AS_ACTION_NEVER;

    /**
     * Current use case is Context Menus: As Views populate the context menu, each one has
     * extra information that should be passed along.  This is the current menu info that
@@ -328,6 +333,11 @@ public class MenuBuilder implements Menu {
                (mResources.getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS);
    }
    
    public MenuBuilder setDefaultShowAsAction(int defaultShowAsAction) {
        mDefaultShowAsAction = defaultShowAsAction;
        return this;
    }
    
    public void setCallback(Callback callback) {
        mCallback = callback;
    }
@@ -411,7 +421,8 @@ public class MenuBuilder implements Menu {
    private MenuItem addInternal(int group, int id, int categoryOrder, CharSequence title) {
        final int ordering = getOrdering(categoryOrder);
        
        final MenuItemImpl item = new MenuItemImpl(this, group, id, categoryOrder, ordering, title);
        final MenuItemImpl item = new MenuItemImpl(this, group, id, categoryOrder,
                ordering, title, mDefaultShowAsAction);

        if (mCurrentMenuInfo != null) {
            // Pass along the current menu info
+2 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ public final class MenuItemImpl implements MenuItem {
     * @param title The text to display for the item.
     */
    MenuItemImpl(MenuBuilder menu, int group, int id, int categoryOrder, int ordering,
            CharSequence title) {
            CharSequence title, int showAsAction) {

        if (sPrependShortcutLabel == null) {
            // This is instantiated from the UI thread, so no chance of sync issues 
@@ -129,6 +129,7 @@ public final class MenuItemImpl implements MenuItem {
        mCategoryOrder = categoryOrder;
        mOrdering = ordering;
        mTitle = title;
        mShowAsAction = showAsAction;
    }
    
    /**