Search in sources :

Example 21 with MenuBuilder

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

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 22 with MenuBuilder

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

the class Toolbar method ensureMenu.

private void ensureMenu() {
    ensureMenuView();
    if (mMenuView.peekMenu() == null) {
        // Initialize a new menu for the first time.
        final MenuBuilder menu = (MenuBuilder) mMenuView.getMenu();
        if (mExpandedMenuPresenter == null) {
            mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
        }
        mMenuView.setExpandedActionViewsExclusive(true);
        menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext);
    }
}
Also used : SubMenuBuilder(com.android.internal.view.menu.SubMenuBuilder) MenuBuilder(com.android.internal.view.menu.MenuBuilder)

Example 23 with MenuBuilder

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

the class ActionMenuView method getMenu.

/**
     * Returns the Menu object that this ActionMenuView is currently presenting.
     *
     * <p>Applications should use this method to obtain the ActionMenuView's Menu object
     * and inflate or add content to it as necessary.</p>
     *
     * @return the Menu presented by this view
     */
public Menu getMenu() {
    if (mMenu == null) {
        final Context context = getContext();
        mMenu = new MenuBuilder(context);
        mMenu.setCallback(new MenuBuilderCallback());
        mPresenter = new ActionMenuPresenter(context);
        mPresenter.setReserveOverflow(true);
        mPresenter.setCallback(mActionMenuPresenterCallback != null ? mActionMenuPresenterCallback : new ActionMenuPresenterCallback());
        mMenu.addMenuPresenter(mPresenter, mPopupContext);
        mPresenter.setMenuView(this);
    }
    return mMenu;
}
Also used : Context(android.content.Context) MenuBuilder(com.android.internal.view.menu.MenuBuilder)

Example 24 with MenuBuilder

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

the class MenuTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    mMenu = new MenuBuilder(super.getContext());
}
Also used : MenuBuilder(com.android.internal.view.menu.MenuBuilder)

Example 25 with MenuBuilder

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

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)

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