Example usage for android.widget ActionMenuPresenter getMenuView

List of usage examples for android.widget ActionMenuPresenter getMenuView

Introduction

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

Prototype

@Override
    public MenuView getMenuView(ViewGroup root) 

Source Link

Usage

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

public void setMenu(MenuBuilder menu, ActionMenuPresenter outerPresenter) {
    if (menu == null && mMenuView == null) {
        return;//from w ww .ja  v a2 s.c o  m
    }

    //       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);

}