Search in sources :

Example 16 with ActionMenuPresenter

use of com.actionbarsherlock.internal.view.menu.ActionMenuPresenter in project little-bear-dictionary by daimajia.

the class ActionBarView method setMenu.

public void setMenu(Menu menu, MenuPresenter.Callback cb) {
    if (menu == mOptionsMenu)
        return;
    if (mOptionsMenu != null) {
        mOptionsMenu.removeMenuPresenter(mActionMenuPresenter);
        mOptionsMenu.removeMenuPresenter(mExpandedMenuPresenter);
    }
    MenuBuilder builder = (MenuBuilder) menu;
    mOptionsMenu = builder;
    if (mMenuView != null) {
        final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
        if (oldParent != null) {
            oldParent.removeView(mMenuView);
        }
    }
    if (mActionMenuPresenter == null) {
        mActionMenuPresenter = new ActionMenuPresenter(mContext);
        mActionMenuPresenter.setCallback(cb);
        mActionMenuPresenter.setId(R.id.abs__action_menu_presenter);
        mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
    }
    ActionMenuView menuView;
    final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    if (!mSplitActionBar) {
        mActionMenuPresenter.setExpandedActionViewsExclusive(getResources_getBoolean(getContext(), R.bool.abs__action_bar_expanded_action_views_exclusive));
        configPresenters(builder);
        menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        final ViewGroup oldParent = (ViewGroup) menuView.getParent();
        if (oldParent != null && oldParent != this) {
            oldParent.removeView(menuView);
        }
        addView(menuView, layoutParams);
    } else {
        mActionMenuPresenter.setExpandedActionViewsExclusive(false);
        // 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;
        configPresenters(builder);
        menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
        if (mSplitView != null) {
            final ViewGroup oldParent = (ViewGroup) menuView.getParent();
            if (oldParent != null && oldParent != mSplitView) {
                oldParent.removeView(menuView);
            }
            menuView.setVisibility(getAnimatedVisibility());
            mSplitView.addView(menuView, layoutParams);
        } else {
            // We'll add this later if we missed it this time.
            menuView.setLayoutParams(layoutParams);
        }
    }
    mMenuView = menuView;
}
Also used : ViewGroup(android.view.ViewGroup) ActionMenuView(com.actionbarsherlock.internal.view.menu.ActionMenuView) SubMenuBuilder(com.actionbarsherlock.internal.view.menu.SubMenuBuilder) MenuBuilder(com.actionbarsherlock.internal.view.menu.MenuBuilder) ActionMenuPresenter(com.actionbarsherlock.internal.view.menu.ActionMenuPresenter)

Aggregations

ActionMenuPresenter (com.actionbarsherlock.internal.view.menu.ActionMenuPresenter)16 ActionMenuView (com.actionbarsherlock.internal.view.menu.ActionMenuView)16 MenuBuilder (com.actionbarsherlock.internal.view.menu.MenuBuilder)16 LayoutInflater (android.view.LayoutInflater)8 View (android.view.View)8 ViewGroup (android.view.ViewGroup)8 TextView (android.widget.TextView)8 SubMenuBuilder (com.actionbarsherlock.internal.view.menu.SubMenuBuilder)8