Search in sources :

Example 6 with MenuBuilder

use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by DirtyUnicorns.

the class Toolbar method setMenu.

/** @hide */
public void setMenu(MenuBuilder menu, ActionMenuPresenter outerPresenter) {
    if (menu == null && mMenuView == null) {
        return;
    }
    ensureMenuView();
    final MenuBuilder oldMenu = mMenuView.peekMenu();
    if (oldMenu == menu) {
        return;
    }
    if (oldMenu != null) {
        oldMenu.removeMenuPresenter(mOuterActionMenuPresenter);
        oldMenu.removeMenuPresenter(mExpandedMenuPresenter);
    }
    if (mExpandedMenuPresenter == null) {
        mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
    }
    outerPresenter.setExpandedActionViewsExclusive(true);
    if (menu != null) {
        menu.addMenuPresenter(outerPresenter, mPopupContext);
        menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext);
    } else {
        outerPresenter.initForMenu(mPopupContext, null);
        mExpandedMenuPresenter.initForMenu(mPopupContext, null);
        outerPresenter.updateMenuView(true);
        mExpandedMenuPresenter.updateMenuView(true);
    }
    mMenuView.setPopupTheme(mPopupTheme);
    mMenuView.setPresenter(outerPresenter);
    mOuterActionMenuPresenter = outerPresenter;
}
Also used : SubMenuBuilder(com.android.internal.view.menu.SubMenuBuilder) MenuBuilder(com.android.internal.view.menu.MenuBuilder)

Example 7 with MenuBuilder

use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by DirtyUnicorns.

the class Toolbar method getCurrentContentInsetEnd.

/**
     * Gets the content inset that will be used on the ending side of the bar in the current
     * toolbar configuration.
     *
     * @return the current content inset end in pixels
     *
     * @see #getContentInsetEndWithActions()
     */
public int getCurrentContentInsetEnd() {
    boolean hasActions = false;
    if (mMenuView != null) {
        final MenuBuilder mb = mMenuView.peekMenu();
        hasActions = mb != null && mb.hasVisibleItems();
    }
    return hasActions ? Math.max(getContentInsetEnd(), Math.max(mContentInsetEndWithActions, 0)) : getContentInsetEnd();
}
Also used : SubMenuBuilder(com.android.internal.view.menu.SubMenuBuilder) MenuBuilder(com.android.internal.view.menu.MenuBuilder)

Example 8 with MenuBuilder

use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by DirtyUnicorns.

the class ActionBarContextView method initForMode.

public void initForMode(final ActionMode mode) {
    if (mClose == null) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        mClose = inflater.inflate(mCloseItemLayout, this, false);
        addView(mClose);
    } else if (mClose.getParent() == null) {
        addView(mClose);
    }
    View closeButton = mClose.findViewById(R.id.action_mode_close_button);
    closeButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            mode.finish();
        }
    });
    final MenuBuilder menu = (MenuBuilder) mode.getMenu();
    if (mActionMenuPresenter != null) {
        mActionMenuPresenter.dismissPopupMenus();
    }
    mActionMenuPresenter = new ActionMenuPresenter(mContext);
    mActionMenuPresenter.setReserveOverflow(true);
    final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    if (!mSplitActionBar) {
        menu.addMenuPresenter(mActionMenuPresenter, mPopupContext);
        mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        mMenuView.setBackground(null);
        addView(mMenuView, layoutParams);
    } else {
        // Allow full screen width in split mode.
        mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true);
        // No limit to the item count; use whatever will fit.
        mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
        // Span the whole width
        layoutParams.width = LayoutParams.MATCH_PARENT;
        layoutParams.height = mContentHeight;
        menu.addMenuPresenter(mActionMenuPresenter, mPopupContext);
        mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        mMenuView.setBackgroundDrawable(mSplitBackground);
        mSplitView.addView(mMenuView, layoutParams);
    }
}
Also used : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ActionMenuView(android.widget.ActionMenuView) View(android.view.View) MenuBuilder(com.android.internal.view.menu.MenuBuilder) ActionMenuPresenter(android.widget.ActionMenuPresenter)

Example 9 with MenuBuilder

use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by DirtyUnicorns.

the class ToolbarActionBar method populateOptionsMenu.

void populateOptionsMenu() {
    if (!mMenuCallbackSet) {
        mDecorToolbar.setMenuCallbacks(new ActionMenuPresenterCallback(), new MenuBuilderCallback());
        mMenuCallbackSet = true;
    }
    final Menu menu = mDecorToolbar.getMenu();
    final MenuBuilder mb = menu instanceof MenuBuilder ? (MenuBuilder) menu : null;
    if (mb != null) {
        mb.stopDispatchingItemsChanged();
    }
    try {
        menu.clear();
        if (!mWindowCallback.onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, menu) || !mWindowCallback.onPreparePanel(Window.FEATURE_OPTIONS_PANEL, null, menu)) {
            menu.clear();
        }
    } finally {
        if (mb != null) {
            mb.startDispatchingItemsChanged();
        }
    }
}
Also used : Menu(android.view.Menu) MenuBuilder(com.android.internal.view.menu.MenuBuilder)

Example 10 with MenuBuilder

use of com.android.internal.view.menu.MenuBuilder in project android_frameworks_base by DirtyUnicorns.

the class FrameworkActionBar method createMenuPopup.

/**
     * Creates a Popup and adds it to the content frame. It also adds another {@link FrameLayout} to
     * the content frame which shall serve as the new content root.
     */
@Override
public void createMenuPopup() {
    if (!isOverflowPopupNeeded()) {
        return;
    }
    DisplayMetrics metrics = mBridgeContext.getMetrics();
    MenuBuilder menu = mActionBar.getMenuBuilder();
    OverflowMenuAdapter adapter = new OverflowMenuAdapter(menu, mActionBar.getPopupContext());
    ListView listView = new ListView(mActionBar.getPopupContext(), null, R.attr.dropDownListViewStyle);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(measureContentWidth(adapter), LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
    if (mActionBar.isSplit()) {
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        layoutParams.bottomMargin = getActionBarHeight() + mActionBar.getMenuPopupMargin();
    } else {
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        layoutParams.topMargin = getActionBarHeight() + mActionBar.getMenuPopupMargin();
    }
    layoutParams.setMarginEnd(getPixelValue("5dp", metrics));
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(adapter);
    final TypedArray a = mActionBar.getPopupContext().obtainStyledAttributes(null, R.styleable.PopupWindow, R.attr.popupMenuStyle, 0);
    listView.setBackground(a.getDrawable(R.styleable.PopupWindow_popupBackground));
    listView.setDivider(a.getDrawable(R.attr.actionBarDivider));
    a.recycle();
    listView.setElevation(mActionBar.getMenuPopupElevation());
    assert mEnclosingLayout != null : "Unable to find view to attach ActionMenuPopup.";
    mEnclosingLayout.addView(listView);
}
Also used : ListView(android.widget.ListView) LayoutParams(android.view.ViewGroup.LayoutParams) TypedArray(android.content.res.TypedArray) RelativeLayout(android.widget.RelativeLayout) DisplayMetrics(android.util.DisplayMetrics) MenuBuilder(com.android.internal.view.menu.MenuBuilder)

Aggregations

MenuBuilder (com.android.internal.view.menu.MenuBuilder)67 SubMenuBuilder (com.android.internal.view.menu.SubMenuBuilder)22 Context (android.content.Context)11 ActionMenuPresenter (android.widget.ActionMenuPresenter)10 ActionMenuView (android.widget.ActionMenuView)10 LayoutInflater (android.view.LayoutInflater)7 View (android.view.View)7 ViewGroup (android.view.ViewGroup)7 TextView (android.widget.TextView)7 TypedValue (android.util.TypedValue)6 ContextMenuInfo (android.view.ContextMenu.ContextMenuInfo)6 ContextThemeWrapper (android.view.ContextThemeWrapper)6 ContextMenuBuilder (com.android.internal.view.menu.ContextMenuBuilder)6 Theme (android.content.res.Resources.Theme)5 TypedArray (android.content.res.TypedArray)5 DisplayMetrics (android.util.DisplayMetrics)5 Menu (android.view.Menu)5 MenuInflater (android.view.MenuInflater)5 LayoutParams (android.view.ViewGroup.LayoutParams)5 ListView (android.widget.ListView)5