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

Commit 244911f9 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "API for inflating action bar menus against a different theme"

parents 41cd577c 3d0f21da
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -244,6 +244,7 @@ package android {
    field public static final int action = 16842797; // 0x101002d
    field public static final int actionBarDivider = 16843675; // 0x101039b
    field public static final int actionBarItemBackground = 16843676; // 0x101039c
    field public static final int actionBarPopupTheme = 16843918; // 0x101048e
    field public static final int actionBarSize = 16843499; // 0x10102eb
    field public static final int actionBarSplitStyle = 16843656; // 0x1010388
    field public static final int actionBarStyle = 16843470; // 0x10102ce
@@ -36109,11 +36110,13 @@ package android.widget {
    ctor public ActionMenuView(android.content.Context, android.util.AttributeSet);
    method public void dismissPopupMenus();
    method public android.view.Menu getMenu();
    method public int getPopupTheme();
    method public boolean hideOverflowMenu();
    method public boolean isOverflowMenuShowing();
    method public void onConfigurationChanged(android.content.res.Configuration);
    method public void onDetachedFromWindow();
    method public void setOnMenuItemClickListener(android.widget.ActionMenuView.OnMenuItemClickListener);
    method public void setPopupTheme(int);
    method public boolean showOverflowMenu();
  }
@@ -38341,6 +38344,7 @@ package android.widget {
    method public android.view.Menu getMenu();
    method public java.lang.CharSequence getNavigationContentDescription();
    method public android.graphics.drawable.Drawable getNavigationIcon();
    method public int getPopupTheme();
    method public java.lang.CharSequence getSubtitle();
    method public java.lang.CharSequence getTitle();
    method public boolean hasExpandedActionView();
@@ -38362,6 +38366,7 @@ package android.widget {
    method public void setNavigationIcon(android.graphics.drawable.Drawable);
    method public void setNavigationOnClickListener(android.view.View.OnClickListener);
    method public void setOnMenuItemClickListener(android.widget.Toolbar.OnMenuItemClickListener);
    method public void setPopupTheme(int);
    method public void setSubtitle(int);
    method public void setSubtitle(java.lang.CharSequence);
    method public void setSubtitleTextAppearance(android.content.Context, int);
+41 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.widget;
import android.content.Context;
import android.content.res.Configuration;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
@@ -28,7 +29,6 @@ import android.view.accessibility.AccessibilityEvent;
import com.android.internal.view.menu.ActionMenuItemView;
import com.android.internal.view.menu.MenuBuilder;
import com.android.internal.view.menu.MenuItemImpl;
import com.android.internal.view.menu.MenuPresenter;
import com.android.internal.view.menu.MenuView;

/**
@@ -45,6 +45,12 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo

    private MenuBuilder mMenu;

    /** Context against which to inflate popup menus. */
    private Context mPopupContext;

    /** Theme resource against which to inflate popup menus. */
    private int mPopupTheme;

    private boolean mReserveOverflow;
    private ActionMenuPresenter mPresenter;
    private boolean mFormatItems;
@@ -64,9 +70,41 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
        final float density = context.getResources().getDisplayMetrics().density;
        mMinCellSize = (int) (MIN_CELL_SIZE * density);
        mGeneratedItemPadding = (int) (GENERATED_ITEM_PADDING * density);
        mPopupContext = context;
        mPopupTheme = 0;
    }

    /** @hide */
    /**
     * Specifies the theme to use when inflating popup menus. By default, uses
     * the same theme as the action menu view itself.
     *
     * @param resId theme used to inflate popup menus
     * @see #getPopupTheme()
     */
    public void setPopupTheme(int resId) {
        if (mPopupTheme != resId) {
            mPopupTheme = resId;
            if (resId == 0) {
                mPopupContext = mContext;
            } else {
                mPopupContext = new ContextThemeWrapper(mContext, resId);
            }
        }
    }

    /**
     * @return resource identifier of the theme used to inflate popup menus, or
     *         0 if menus are inflated against the action menu view theme
     * @see #setPopupTheme(int)
     */
    public int getPopupTheme() {
        return mPopupTheme;
    }

    /**
     * @param presenter Menu presenter used to display popup menu
     * @hide
     */
    public void setPresenter(ActionMenuPresenter presenter) {
        mPresenter = presenter;
        mPresenter.setMenuView(this);
@@ -571,7 +609,7 @@ public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvo
            mMenu.setCallback(new MenuBuilderCallback());
            mPresenter = new ActionMenuPresenter(context);
            mPresenter.setCallback(new ActionMenuPresenterCallback());
            mMenu.addMenuPresenter(mPresenter);
            mMenu.addMenuPresenter(mPresenter, mPopupContext);
            mPresenter.setMenuView(this);
        }

+45 −11
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
 * limitations under the License.
 */


package android.widget;

import android.annotation.NonNull;
@@ -27,16 +26,15 @@ import android.os.Parcelable;
import android.text.Layout;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.CollapsibleActionView;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewDebug;
import android.view.ViewGroup;
import android.view.Window;

import com.android.internal.R;
import com.android.internal.view.menu.MenuBuilder;
import com.android.internal.view.menu.MenuItemImpl;
@@ -104,6 +102,12 @@ public class Toolbar extends ViewGroup {
    private ImageButton mCollapseButtonView;
    View mExpandedActionView;

    /** Context against which to inflate popup menus. */
    private Context mPopupContext;

    /** Theme resource against which to inflate popup menus. */
    private int mPopupTheme;

    private int mTitleTextAppearance;
    private int mSubtitleTextAppearance;
    private int mNavButtonStyle;
@@ -230,6 +234,36 @@ public class Toolbar extends ViewGroup {
            setSubtitle(subtitle);
        }
        a.recycle();

        mPopupContext = context;
        mPopupTheme = 0;
    }

    /**
     * Specifies the theme to use when inflating popup menus. By default, uses
     * the same theme as the toolbar itself.
     *
     * @param resId theme used to inflate popup menus
     * @see #getPopupTheme()
     */
    public void setPopupTheme(int resId) {
        if (mPopupTheme != resId) {
            mPopupTheme = resId;
            if (resId == 0) {
                mPopupContext = mContext;
            } else {
                mPopupContext = new ContextThemeWrapper(mContext, resId);
            }
        }
    }

    /**
     * @return resource identifier of the theme used to inflate popup menus, or
     *         0 if menus are inflated against the toolbar theme
     * @see #setPopupTheme(int)
     */
    public int getPopupTheme() {
        return mPopupTheme;
    }

    @Override
@@ -306,22 +340,21 @@ public class Toolbar extends ViewGroup {
            oldMenu.removeMenuPresenter(mExpandedMenuPresenter);
        }

        final Context context = getContext();

        if (mExpandedMenuPresenter == null) {
            mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
        }

        outerPresenter.setExpandedActionViewsExclusive(true);
        if (menu != null) {
            menu.addMenuPresenter(outerPresenter);
            menu.addMenuPresenter(mExpandedMenuPresenter);
            menu.addMenuPresenter(outerPresenter, mPopupContext);
            menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext);
        } else {
            outerPresenter.initForMenu(context, null);
            mExpandedMenuPresenter.initForMenu(context, null);
            outerPresenter.initForMenu(mPopupContext, null);
            mExpandedMenuPresenter.initForMenu(mPopupContext, null);
            outerPresenter.updateMenuView(true);
            mExpandedMenuPresenter.updateMenuView(true);
        }
        mMenuView.setPopupTheme(mPopupTheme);
        mMenuView.setPresenter(outerPresenter);
        mOuterActionMenuPresenter = outerPresenter;
    }
@@ -768,13 +801,14 @@ public class Toolbar extends ViewGroup {
                mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
            }
            mMenuView.setExpandedActionViewsExclusive(true);
            menu.addMenuPresenter(mExpandedMenuPresenter);
            menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext);
        }
    }

    private void ensureMenuView() {
        if (mMenuView == null) {
            mMenuView = new ActionMenuView(getContext());
            mMenuView.setPopupTheme(mPopupTheme);
            mMenuView.setOnMenuItemClickListener(mMenuViewItemClickListener);
            final LayoutParams lp = generateDefaultLayoutParams();
            lp.gravity = Gravity.END | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK);
+14 −1
Original line number Diff line number Diff line
@@ -212,8 +212,21 @@ public class MenuBuilder implements Menu {
     * @param presenter The presenter to add
     */
    public void addMenuPresenter(MenuPresenter presenter) {
        addMenuPresenter(presenter, mContext);
    }

    /**
     * Add a presenter to this menu that uses an alternate context for
     * inflating menu items. This will only hold a WeakReference; you do not
     * need to explicitly remove a presenter, but you can using
     * {@link #removeMenuPresenter(MenuPresenter)}.
     *
     * @param presenter The presenter to add
     * @param menuContext The context used to inflate menu items
     */
    public void addMenuPresenter(MenuPresenter presenter, Context menuContext) {
        mPresenters.add(new WeakReference<MenuPresenter>(presenter));
        presenter.initForMenu(mContext, this);
        presenter.initForMenu(menuContext, this);
        mIsActionItemsStale = true;
    }

+2 −1
Original line number Diff line number Diff line
@@ -95,7 +95,8 @@ public class MenuPopupHelper implements AdapterView.OnItemClickListener, View.On

        mAnchorView = anchorView;

        menu.addMenuPresenter(this);
        // Present the menu using our context, not the menu builder's context.
        menu.addMenuPresenter(this, context);
    }

    public void setAnchorView(View anchor) {
Loading