FileDocCategorySizeDatePackage
IconMenuPresenter.javaAPI DocAndroid 5.1 API6812Thu Mar 12 22:22:10 GMT 2015com.android.internal.view.menu

IconMenuPresenter

public class IconMenuPresenter extends BaseMenuPresenter
MenuPresenter for the classic "six-pack" icon menu.

Fields Summary
private IconMenuItemView
mMoreView
private int
mMaxItems
int
mOpenSubMenuId
SubMenuPresenterCallback
mSubMenuPresenterCallback
MenuDialogHelper
mOpenSubMenu
private static final String
VIEWS_TAG
private static final String
OPEN_SUBMENU_KEY
Constructors Summary
public IconMenuPresenter(android.content.Context context)


       
        super(new ContextThemeWrapper(context, com.android.internal.R.style.Theme_IconMenu),
                com.android.internal.R.layout.icon_menu_layout,
                com.android.internal.R.layout.icon_menu_item_layout);
    
Methods Summary
protected voidaddItemView(android.view.View itemView, int childIndex)

        final IconMenuItemView v = (IconMenuItemView) itemView;
        final IconMenuView parent = (IconMenuView) mMenuView;

        v.setIconMenuView(parent);
        v.setItemInvoker(parent);
        v.setBackgroundDrawable(parent.getItemBackgroundDrawable());
        super.addItemView(itemView, childIndex);
    
public voidbindItemView(MenuItemImpl item, com.android.internal.view.menu.MenuView.ItemView itemView)

        final IconMenuItemView view = (IconMenuItemView) itemView;
        view.setItemData(item);

        view.initialize(item.getTitleForItemView(view), item.getIcon());

        view.setVisibility(item.isVisible() ? View.VISIBLE : View.GONE);
        view.setEnabled(view.isEnabled());
        view.setLayoutParams(view.getTextAppropriateLayoutParams());
    
protected booleanfilterLeftoverView(android.view.ViewGroup parent, int childIndex)

        if (parent.getChildAt(childIndex) != mMoreView) {
            return super.filterLeftoverView(parent, childIndex);
        }
        return false;
    
public intgetNumActualItemsShown()

        return ((IconMenuView) mMenuView).getNumActualItemsShown();
    
public voidinitForMenu(android.content.Context context, MenuBuilder menu)

        super.initForMenu(context, menu);
        mMaxItems = -1;
    
public voidonRestoreInstanceState(android.os.Parcelable state)

        restoreHierarchyState((Bundle) state);
    
public android.os.ParcelableonSaveInstanceState()

        if (mMenuView == null) {
            return null;
        }

        Bundle state = new Bundle();
        saveHierarchyState(state);
        if (mOpenSubMenuId > 0) {
            state.putInt(OPEN_SUBMENU_KEY, mOpenSubMenuId);
        }
        return state;
    
public booleanonSubMenuSelected(SubMenuBuilder subMenu)

        if (!subMenu.hasVisibleItems()) return false;

        // The window manager will give us a token.
        MenuDialogHelper helper = new MenuDialogHelper(subMenu);
        helper.setPresenterCallback(mSubMenuPresenterCallback);
        helper.show(null);
        mOpenSubMenu = helper;
        mOpenSubMenuId = subMenu.getItem().getItemId();
        super.onSubMenuSelected(subMenu);
        return true;
    
public voidrestoreHierarchyState(android.os.Bundle inState)

        SparseArray<Parcelable> viewStates = inState.getSparseParcelableArray(VIEWS_TAG);
        if (viewStates != null) {
            ((View) mMenuView).restoreHierarchyState(viewStates);
        }
        int subMenuId = inState.getInt(OPEN_SUBMENU_KEY, 0);
        if (subMenuId > 0 && mMenu != null) {
            MenuItem item = mMenu.findItem(subMenuId);
            if (item != null) {
                onSubMenuSelected((SubMenuBuilder) item.getSubMenu());
            }
        }
    
public voidsaveHierarchyState(android.os.Bundle outState)

        SparseArray<Parcelable> viewStates = new SparseArray<Parcelable>();
        if (mMenuView != null) {
            ((View) mMenuView).saveHierarchyState(viewStates);
        }
        outState.putSparseParcelableArray(VIEWS_TAG, viewStates);
    
public booleanshouldIncludeItem(int childIndex, MenuItemImpl item)

        final ArrayList<MenuItemImpl> itemsToShow = mMenu.getNonActionItems();
        boolean fits = (itemsToShow.size() == mMaxItems && childIndex < mMaxItems) ||
                childIndex < mMaxItems - 1;
        return fits && !item.isActionButton();
    
public voidupdateMenuView(boolean cleared)

        final IconMenuView menuView = (IconMenuView) mMenuView;
        if (mMaxItems < 0) mMaxItems = menuView.getMaxItems();
        final ArrayList<MenuItemImpl> itemsToShow = mMenu.getNonActionItems();
        final boolean needsMore = itemsToShow.size() > mMaxItems;
        super.updateMenuView(cleared);

        if (needsMore && (mMoreView == null || mMoreView.getParent() != menuView)) {
            if (mMoreView == null) {
                mMoreView = menuView.createMoreItemView();
                mMoreView.setBackgroundDrawable(menuView.getItemBackgroundDrawable());
            }
            menuView.addView(mMoreView);
        } else if (!needsMore && mMoreView != null) {
            menuView.removeView(mMoreView);
        }

        menuView.setNumActualItemsShown(needsMore ? mMaxItems - 1 : itemsToShow.size());