Example usage for android.widget ActionMenuPresenter initForMenu

List of usage examples for android.widget ActionMenuPresenter initForMenu

Introduction

In this page you can find the example usage for android.widget ActionMenuPresenter initForMenu.

Prototype

@Override
    public void initForMenu(@NonNull Context context, @Nullable MenuBuilder menu) 

Source Link

Usage

From source file:android.support.v7.widget.Toolbar.java

/** @hide */
public void setMenu(MenuBuilder menu, ActionMenuPresenter outerPresenter) {
    if (menu == null && mMenuView == null) {
        return;//  w w w  .j  ava  2 s.c  o m
    }

    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;
}

From source file:lewa.support.v7.widget.Toolbar.java

public void setMenu(MenuBuilder menu, ActionMenuPresenter outerPresenter) {
    if (menu == null && mMenuView == null) {
        return;//w w w.  jav a2 s .  c  om
    }

    //       ensureMenuView();
    if (mMenuView != null) {
        final MenuBuilder oldMenu = mMenuView.peekMenu();
        if (oldMenu == menu) {
            return;
        }

        if (oldMenu != null) {
            oldMenu.removeMenuPresenter(mOuterActionMenuPresenter);
            //                oldMenu.removeMenuPresenter(mExpandedMenuPresenter);
        }
    }

    if (mExpandedMenuPresenter == null) {
        mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
    }
    mActionMenuPresenter = outerPresenter;
    outerPresenter.setExpandedActionViewsExclusive(false);
    if (menu != null) {
        menu.addMenuPresenter(outerPresenter, mPopupContext);
        final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.MATCH_PARENT);
        mActionMenuPresenter.setReserveOverflow(true);
        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;
        int actionbarHeight = ActionBarPolicy.get(mContext).getTabContainerHeight();
        layoutParams.height = actionbarHeight;
        //            layoutParams.height = mContentHeight;
        mMenuView = (ActionMenuView) outerPresenter.getMenuView(this);
        //            menu.addMenuPresenter(mExpandedMenuPresenter, mPopupContext);
        //            final LayoutParams lp = generateDefaultLayoutParams();
        //            lp.gravity = GravityCompat.END | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK);
        //            lp.gravity = 
        //            lp.width = LayoutParams.MATCH_PARENT;
        //            mMenuView.setLayoutParams(lp);
        //            ((LewaActionBarContainer) mSplitView)
        //            .getActionMenuBar().addView(mMenuView, layoutParams);
        Injector.addActionOptionMenu(this, menu, layoutParams);
    } else {
        outerPresenter.initForMenu(mPopupContext, null);
        mExpandedMenuPresenter.initForMenu(mPopupContext, null);
        outerPresenter.updateMenuView(true);
        mExpandedMenuPresenter.updateMenuView(true);
    }
    //        mMenuView.setPopupTheme(mPopupTheme);
    //        mMenuView.setPresenter(outerPresenter);

}