FileDocCategorySizeDatePackage
MenuBuilder.javaAPI DocAndroid 1.5 API37962Wed May 06 22:41:56 BST 2009com.android.internal.view.menu

MenuBuilder

public class MenuBuilder extends Object implements android.view.Menu
Implementation of the {@link android.view.Menu} interface for creating a standard menu UI.

Fields Summary
private static final String
LOGTAG
public static final int
NUM_TYPES
The number of different menu types
public static final int
TYPE_ICON
The menu type that represents the icon menu view
public static final int
TYPE_EXPANDED
The menu type that represents the expanded menu view
public static final int
TYPE_DIALOG
The menu type that represents a menu dialog. Examples are context and sub menus. This menu type will not have a corresponding MenuView, but it will have an ItemView.
private static final String
VIEWS_TAG
static final int[]
THEME_RES_FOR_TYPE
static final int[]
LAYOUT_RES_FOR_TYPE
static final int[]
ITEM_LAYOUT_RES_FOR_TYPE
private static final int[]
sCategoryToOrder
private final android.content.Context
mContext
private final android.content.res.Resources
mResources
private boolean
mQwertyMode
Whether the shortcuts should be qwerty-accessible. Use isQwertyMode() instead of accessing this directly.
private boolean
mShortcutsVisible
Whether the shortcuts should be visible on menus. Use isShortcutsVisible() instead of accessing this directly.
private Callback
mCallback
Callback that will receive the various menu-related events generated by this class. Use getCallback to get a reference to the callback.
private ArrayList
mItems
Contains all of the items for this menu
private ArrayList
mVisibleItems
Contains only the items that are currently visible. This will be created/refreshed from {@link #getVisibleItems()}
private boolean
mIsVisibleItemsStale
Whether or not the items (or any one item's shown state) has changed since it was last fetched from {@link #getVisibleItems()}
private android.view.ContextMenu.ContextMenuInfo
mCurrentMenuInfo
Current use case is Context Menus: As Views populate the context menu, each one has extra information that should be passed along. This is the current menu info that should be set on all items added to this menu.
CharSequence
mHeaderTitle
Header title for menu types that have a header (context and submenus)
android.graphics.drawable.Drawable
mHeaderIcon
Header icon for menu types that have a header and support icons (context)
android.view.View
mHeaderView
Header custom view for menu types that have a header and support custom views (context)
private android.util.SparseArray
mFrozenViewStates
Contains the state of the View hierarchy for all menu views when the menu was frozen.
private boolean
mPreventDispatchingItemsChanged
Prevents onItemsChanged from doing its junk, useful for batching commands that may individually call onItemsChanged.
private boolean
mOptionalIconsVisible
private MenuType[]
mMenuTypes
Constructors Summary
public MenuBuilder(android.content.Context context)

        mMenuTypes = new MenuType[NUM_TYPES];
        
        mContext = context;
        mResources = context.getResources();
        
        mItems = new ArrayList<MenuItemImpl>();
        
        mVisibleItems = new ArrayList<MenuItemImpl>();
        mIsVisibleItemsStale = true;
        
        mShortcutsVisible =
                (mResources.getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS);
    
Methods Summary
public android.view.MenuItemadd(int group, int id, int categoryOrder, java.lang.CharSequence title)

        return addInternal(group, id, categoryOrder, title);
    
public android.view.MenuItemadd(int group, int id, int categoryOrder, int title)

        return addInternal(group, id, categoryOrder, mResources.getString(title));
    
public android.view.MenuItemadd(java.lang.CharSequence title)

        return addInternal(0, 0, 0, title);
    
public android.view.MenuItemadd(int titleRes)

        return addInternal(0, 0, 0, mResources.getString(titleRes));
    
public intaddIntentOptions(int group, int id, int categoryOrder, android.content.ComponentName caller, android.content.Intent[] specifics, android.content.Intent intent, int flags, android.view.MenuItem[] outSpecificItems)

        PackageManager pm = mContext.getPackageManager();
        final List<ResolveInfo> lri =
                pm.queryIntentActivityOptions(caller, specifics, intent, 0);
        final int N = lri != null ? lri.size() : 0;

        if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
            removeGroup(group);
        }

        for (int i=0; i<N; i++) {
            final ResolveInfo ri = lri.get(i);
            Intent rintent = new Intent(
                ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
            rintent.setComponent(new ComponentName(
                    ri.activityInfo.applicationInfo.packageName,
                    ri.activityInfo.name));
            final MenuItem item = add(group, id, categoryOrder, ri.loadLabel(pm))
                    .setIcon(ri.loadIcon(pm))
                    .setIntent(rintent);
            if (outSpecificItems != null && ri.specificIndex >= 0) {
                outSpecificItems[ri.specificIndex] = item;
            }
        }

        return N;
    
private android.view.MenuItemaddInternal(int group, int id, int categoryOrder, java.lang.CharSequence title)
Adds an item to the menu. The other add methods funnel to this.

        final int ordering = getOrdering(categoryOrder);
        
        final MenuItemImpl item = new MenuItemImpl(this, group, id, categoryOrder, ordering, title);

        if (mCurrentMenuInfo != null) {
            // Pass along the current menu info
            item.setMenuInfo(mCurrentMenuInfo);
        }
        
        mItems.add(findInsertIndex(mItems, ordering), item);
        onItemsChanged(false);
        
        return item;
    
public android.view.SubMenuaddSubMenu(java.lang.CharSequence title)

        return addSubMenu(0, 0, 0, title);
    
public android.view.SubMenuaddSubMenu(int titleRes)

        return addSubMenu(0, 0, 0, mResources.getString(titleRes));
    
public android.view.SubMenuaddSubMenu(int group, int id, int categoryOrder, java.lang.CharSequence title)

        final MenuItemImpl item = (MenuItemImpl) addInternal(group, id, categoryOrder, title);
        final SubMenuBuilder subMenu = new SubMenuBuilder(mContext, this, item);
        item.setSubMenu(subMenu);
        
        return subMenu;
    
public android.view.SubMenuaddSubMenu(int group, int id, int categoryOrder, int title)

        return addSubMenu(group, id, categoryOrder, mResources.getString(title));
    
public voidclear()

        mItems.clear();
        
        onItemsChanged(true);
    
public voidclearAll()

        mPreventDispatchingItemsChanged = true;
        clear();
        clearHeader();
        mPreventDispatchingItemsChanged = false;
        onItemsChanged(true);
    
public voidclearHeader()

        mHeaderIcon = null;
        mHeaderTitle = null;
        mHeaderView = null;
        
        onItemsChanged(false);
    
public voidclearMenuViews()
Clears the cached menu views. Call this if the menu views need to another layout (for example, if the screen size has changed).

        for (int i = NUM_TYPES - 1; i >= 0; i--) {
            if (mMenuTypes[i] != null) {
                mMenuTypes[i].mMenuView = null;
            }
        }
        
        for (int i = mItems.size() - 1; i >= 0; i--) {
            MenuItemImpl item = mItems.get(i);
            if (item.hasSubMenu()) {
                ((SubMenuBuilder) item.getSubMenu()).clearMenuViews();
            }
            item.clearItemViews();
        }
    
final voidclose(boolean allMenusAreClosing)
Closes the visible menu.

param
allMenusAreClosing Whether the menus are completely closing (true), or whether there is another menu coming in this menu's place (false). For example, if the menu is closing because a sub menu is about to be shown, allMenusAreClosing is false.

        Callback callback = getCallback();
        if (callback != null) {
            callback.onCloseMenu(this, allMenusAreClosing);
        }
    
public voidclose()
{@inheritDoc}

        close(true);
    
public intfindGroupIndex(int group)

        return findGroupIndex(group, 0);
    
public intfindGroupIndex(int group, int start)

        final int size = size();
        
        if (start < 0) {
            start = 0;
        }
        
        for (int i = start; i < size; i++) {
            final MenuItemImpl item = mItems.get(i);
            
            if (item.getGroupId() == group) {
                return i;
            }
        }

        return -1;
    
private static intfindInsertIndex(java.util.ArrayList items, int ordering)

        for (int i = items.size() - 1; i >= 0; i--) {
            MenuItemImpl item = items.get(i);
            if (item.getOrdering() <= ordering) {
                return i + 1;
            }
        }
        
        return 0;
    
public android.view.MenuItemfindItem(int id)

        final int size = size();
        for (int i = 0; i < size; i++) {
            MenuItemImpl item = mItems.get(i);
            if (item.getItemId() == id) {
                return item;
            } else if (item.hasSubMenu()) {
                MenuItem possibleItem = item.getSubMenu().findItem(id);
                
                if (possibleItem != null) {
                    return possibleItem;
                }
            }
        }
        
        return null;
    
public intfindItemIndex(int id)

        final int size = size();

        for (int i = 0; i < size; i++) {
            MenuItemImpl item = mItems.get(i);
            if (item.getItemId() == id) {
                return i;
            }
        }

        return -1;
    
MenuItemImplfindItemWithShortcutForKey(int keyCode, android.view.KeyEvent event)

        final boolean qwerty = isQwertyMode();
        final int metaState = event.getMetaState();
        final KeyCharacterMap.KeyData possibleChars = new KeyCharacterMap.KeyData();
        // Get the chars associated with the keyCode (i.e using any chording combo)
        final boolean isKeyCodeMapped = event.getKeyData(possibleChars);
        // The delete key is not mapped to '\b' so we treat it specially
        if (!isKeyCodeMapped && (keyCode != KeyEvent.KEYCODE_DEL)) {
            return null;
        }

        // Look for an item whose shortcut is this key.
        final int N = mItems.size();
        for (int i = 0; i < N; i++) {
            MenuItemImpl item = mItems.get(i);
            if (item.hasSubMenu()) {
                MenuItemImpl subMenuItem = ((MenuBuilder)item.getSubMenu())
                                .findItemWithShortcutForKey(keyCode, event);
                if (subMenuItem != null) {
                    return subMenuItem;
                }
            }
            if (qwerty) {
                final char shortcutAlphaChar = item.getAlphabeticShortcut();
                if (((metaState & (KeyEvent.META_SHIFT_ON | KeyEvent.META_SYM_ON)) == 0) &&
                        (shortcutAlphaChar != 0) &&
                        (shortcutAlphaChar == possibleChars.meta[0]
                         || shortcutAlphaChar == possibleChars.meta[2]
                         || (shortcutAlphaChar == '\b" && keyCode == KeyEvent.KEYCODE_DEL)) &&
                        item.isEnabled()) {
                    return item;
                }
            } else {
                final char shortcutNumericChar = item.getNumericShortcut();
                if (((metaState & (KeyEvent.META_SHIFT_ON | KeyEvent.META_SYM_ON)) == 0) &&
                        (shortcutNumericChar != 0) &&
                        (shortcutNumericChar == possibleChars.meta[0]
                            || shortcutNumericChar == possibleChars.meta[2]) &&
                        item.isEnabled()) {
                    return item;
                }
            }
        }
        return null;
    
public com.android.internal.view.menu.MenuBuilder$CallbackgetCallback()

        return mCallback;
    
public android.content.ContextgetContext()

        return mContext;
    
public android.graphics.drawable.DrawablegetHeaderIcon()

        return mHeaderIcon;
    
public java.lang.CharSequencegetHeaderTitle()

        return mHeaderTitle;
    
public android.view.ViewgetHeaderView()

        return mHeaderView;
    
public android.view.MenuItemgetItem(int index)
{@inheritDoc}

        return mItems.get(index);
    
public com.android.internal.view.menu.MenuBuilder$MenuAdaptergetMenuAdapter(int menuType)
Gets an adapter for providing items and their views.

param
menuType The type of menu to get an adapter for.
return
A {@link MenuAdapter} for this menu with the given menu type.

        return new MenuAdapter(menuType);
    
com.android.internal.view.menu.MenuBuilder$MenuTypegetMenuType(int menuType)

        if (mMenuTypes[menuType] == null) {
            mMenuTypes[menuType] = new MenuType(menuType);
        }
        
        return mMenuTypes[menuType];
    
public android.view.ViewgetMenuView(int menuType, android.view.ViewGroup parent)
Gets a menu View that contains this menu's items.

param
menuType The type of menu to get a View for (must be one of {@link #TYPE_ICON}, {@link #TYPE_EXPANDED}, {@link #TYPE_DIALOG}).
param
parent The ViewGroup that provides a set of LayoutParams values for this menu view
return
A View for the menu of type menuType

        // The expanded menu depends on the number if items shown in the icon menu (which
        // is adjustable as setters/XML attributes on IconMenuView [imagine a larger LCD
        // wanting to show more icons]). If, for example, the activity goes through
        // an orientation change while the expanded menu is open, the icon menu's view
        // won't have an instance anymore; so here we make sure we have an icon menu view (matching
        // the same parent so the layout parameters from the XML are used). This
        // will create the icon menu view and cache it (if it doesn't already exist). 
        if (menuType == TYPE_EXPANDED
                && (mMenuTypes[TYPE_ICON] == null || !mMenuTypes[TYPE_ICON].hasMenuView())) {
            getMenuType(TYPE_ICON).getMenuView(parent);
        }
        
        return (View) getMenuType(menuType).getMenuView(parent);
    
private intgetNumIconMenuItemsShown()

        ViewGroup parent = null;
        
        if (!mMenuTypes[TYPE_ICON].hasMenuView()) {
            /*
             * There isn't an icon menu view instantiated, so when we get it
             * below, it will lazily instantiate it. We should pass a proper
             * parent so it uses the layout_ attributes present in the XML
             * layout file.
             */
            if (mMenuTypes[TYPE_EXPANDED].hasMenuView()) {
                View expandedMenuView = (View) mMenuTypes[TYPE_EXPANDED].getMenuView(null);
                parent = (ViewGroup) expandedMenuView.getParent();
            }
        }
        
        return ((IconMenuView) getMenuView(TYPE_ICON, parent)).getNumActualItemsShown(); 
    
booleangetOptionalIconsVisible()

        return mOptionalIconsVisible;
    
private static intgetOrdering(int categoryOrder)
Returns the ordering across all items. This will grab the category from the upper bits, find out how to order the category with respect to other categories, and combine it with the lower bits.

param
categoryOrder The category order for a particular item (if it has not been or/add with a category, the default category is assumed).
return
An ordering integer that can be used to order this item across all the items (even from other categories).

        final int index = (categoryOrder & CATEGORY_MASK) >> CATEGORY_SHIFT;
        
        if (index < 0 || index >= sCategoryToOrder.length) {
            throw new IllegalArgumentException("order does not contain a valid category.");
        }
        
        return (sCategoryToOrder[index] << CATEGORY_SHIFT) | (categoryOrder & USER_MASK);
    
android.content.res.ResourcesgetResources()

        return mResources;
    
public com.android.internal.view.menu.MenuBuildergetRootMenu()
Gets the root menu (if this is a submenu, find its root menu).

return
The root menu.

        return this;
    
java.util.ArrayListgetVisibleItems()

        if (!mIsVisibleItemsStale) return mVisibleItems;
        
        // Refresh the visible items
        mVisibleItems.clear();
        
        final int itemsSize = mItems.size(); 
        MenuItemImpl item;
        for (int i = 0; i < itemsSize; i++) {
            item = mItems.get(i);
            if (item.isVisible()) mVisibleItems.add(item);
        }
        
        mIsVisibleItemsStale = false;
        
        return mVisibleItems;
    
public booleanhasVisibleItems()

        final int size = size();

        for (int i = 0; i < size; i++) {
            MenuItemImpl item = mItems.get(i);
            if (item.isVisible()) {
                return true;
            }
        }

        return false;
    
booleanisQwertyMode()

return
whether the menu shortcuts are in qwerty mode or not

        return mQwertyMode;
    
public booleanisShortcutKey(int keyCode, android.view.KeyEvent event)

        return findItemWithShortcutForKey(keyCode, event) != null;
    
public booleanisShortcutsVisible()

return
Whether shortcuts should be visible on menus.

        return mShortcutsVisible;
    
voidonItemVisibleChanged(MenuItemImpl item)
Called by {@link MenuItemImpl} when its visible flag is changed.

param
item The item that has gone through a visibility change.

        // Notify of items being changed
        onItemsChanged(false);
    
private voidonItemsChanged(boolean cleared)
Called when an item is added or removed.

param
cleared Whether the items were cleared or just changed.

        if (!mPreventDispatchingItemsChanged) {
            if (mIsVisibleItemsStale == false) mIsVisibleItemsStale = true;
            
            MenuType[] menuTypes = mMenuTypes;
            for (int i = 0; i < NUM_TYPES; i++) {
                if ((menuTypes[i] != null) && (menuTypes[i].hasMenuView())) {
                    MenuView menuView = menuTypes[i].mMenuView.get();
                    menuView.updateChildren(cleared);
                }
            }
        }
    
public booleanperformIdentifierAction(int id, int flags)

        // Look for an item whose identifier is the id.
        return performItemAction(findItem(id), flags);           
    
public booleanperformItemAction(android.view.MenuItem item, int flags)

        MenuItemImpl itemImpl = (MenuItemImpl) item;
        
        if (itemImpl == null || !itemImpl.isEnabled()) {
            return false;
        }        
        
        boolean invoked = itemImpl.invoke();

        if (item.hasSubMenu()) {
            close(false);

            if (mCallback != null) {
                // Return true if the sub menu was invoked or the item was invoked previously
                invoked = mCallback.onSubMenuSelected((SubMenuBuilder) item.getSubMenu())
                        || invoked;
            }
        } else {
            if ((flags & FLAG_PERFORM_NO_CLOSE) == 0) {
                close(true);
            }
        }
        
        return invoked;
    
public booleanperformShortcut(int keyCode, android.view.KeyEvent event, int flags)

        final MenuItemImpl item = findItemWithShortcutForKey(keyCode, event);

        boolean handled = false;
        
        if (item != null) {
            handled = performItemAction(item, flags);
        }
        
        if ((flags & FLAG_ALWAYS_PERFORM_CLOSE) != 0) {
            close(true);
        }
        
        return handled;
    
private voidrefreshShortcuts(boolean shortcutsVisible, boolean qwertyMode)
Refreshes the shortcut labels on each of the displayed items. Passes the arguments so submenus don't need to call their parent menu for the same values.

        MenuItemImpl item;
        for (int i = mItems.size() - 1; i >= 0; i--) {
            item = mItems.get(i);
            
            if (item.hasSubMenu()) {
                ((MenuBuilder) item.getSubMenu()).refreshShortcuts(shortcutsVisible, qwertyMode);
            }
            
            item.refreshShortcutOnItemViews(shortcutsVisible, qwertyMode);
        }
    
public voidremoveGroup(int group)

        final int i = findGroupIndex(group);

        if (i >= 0) {
            final int maxRemovable = mItems.size() - i;
            int numRemoved = 0;
            while ((numRemoved++ < maxRemovable) && (mItems.get(i).getGroupId() == group)) {
                // Don't force update for each one, this method will do it at the end
                removeItemAtInt(i, false);
            }
            
            // Notify menu views
            onItemsChanged(false);
        }
    
public voidremoveItem(int id)

        removeItemAtInt(findItemIndex(id), true);
    
public voidremoveItemAt(int index)

        removeItemAtInt(index, true);
    
private voidremoveItemAtInt(int index, boolean updateChildrenOnMenuViews)
Remove the item at the given index and optionally forces menu views to update.

param
index The index of the item to be removed. If this index is invalid an exception is thrown.
param
updateChildrenOnMenuViews Whether to force update on menu views. Please make sure you eventually call this after your batch of removals.

        if ((index < 0) || (index >= mItems.size())) return;

        mItems.remove(index);
        
        if (updateChildrenOnMenuViews) onItemsChanged(false);
    
public voidrestoreHierarchyState(android.os.Bundle inState)

        // Save this for menu views opened later
        SparseArray<Parcelable> viewStates = mFrozenViewStates = inState
                .getSparseParcelableArray(VIEWS_TAG);
        
        // Thaw those menu views already open
        MenuType[] menuTypes = mMenuTypes;
        for (int i = NUM_TYPES - 1; i >= 0; i--) {
            if (menuTypes[i] == null) {
                continue;
            }
            
            if (menuTypes[i].hasMenuView()) {
                ((View) menuTypes[i].getMenuView(null)).restoreHierarchyState(viewStates);
            }
        }
    
public voidsaveHierarchyState(android.os.Bundle outState)

        SparseArray<Parcelable> viewStates = new SparseArray<Parcelable>();
        
        MenuType[] menuTypes = mMenuTypes;
        for (int i = NUM_TYPES - 1; i >= 0; i--) {
            if (menuTypes[i] == null) {
                continue;
            }

            if (menuTypes[i].hasMenuView()) {
                ((View) menuTypes[i].getMenuView(null)).saveHierarchyState(viewStates);
            }
        }
        
        outState.putSparseParcelableArray(VIEWS_TAG, viewStates);
    
public voidsetCallback(com.android.internal.view.menu.MenuBuilder$Callback callback)

        mCallback = callback;
    
public voidsetCurrentMenuInfo(android.view.ContextMenu.ContextMenuInfo menuInfo)
Sets the current menu info that is set on all items added to this menu (until this is called again with different menu info, in which case that one will be added to all subsequent item additions).

param
menuInfo The extra menu information to add.

        mCurrentMenuInfo = menuInfo;
    
voidsetExclusiveItemChecked(android.view.MenuItem item)

        final int group = item.getGroupId();
        
        final int N = mItems.size();
        for (int i = 0; i < N; i++) {
            MenuItemImpl curItem = mItems.get(i);
            if (curItem.getGroupId() == group) {
                if (!curItem.isExclusiveCheckable()) continue;
                if (!curItem.isCheckable()) continue;
                
                // Check the item meant to be checked, uncheck the others (that are in the group)
                curItem.setCheckedInt(curItem == item);
            }
        }
    
public voidsetGroupCheckable(int group, boolean checkable, boolean exclusive)

        final int N = mItems.size();
       
        for (int i = 0; i < N; i++) {
            MenuItemImpl item = mItems.get(i);
            if (item.getGroupId() == group) {
                item.setExclusiveCheckable(exclusive);
                item.setCheckable(checkable);
            }
        }
    
public voidsetGroupEnabled(int group, boolean enabled)

        final int N = mItems.size();

        for (int i = 0; i < N; i++) {
            MenuItemImpl item = mItems.get(i);
            if (item.getGroupId() == group) {
                item.setEnabled(enabled);
            }
        }
    
public voidsetGroupVisible(int group, boolean visible)

        final int N = mItems.size();

        // We handle the notification of items being changed ourselves, so we use setVisibleInt rather
        // than setVisible and at the end notify of items being changed
        
        boolean changedAtLeastOneItem = false;
        for (int i = 0; i < N; i++) {
            MenuItemImpl item = mItems.get(i);
            if (item.getGroupId() == group) {
                if (item.setVisibleInt(visible)) changedAtLeastOneItem = true;
            }
        }

        if (changedAtLeastOneItem) onItemsChanged(false);
    
protected com.android.internal.view.menu.MenuBuildersetHeaderIconInt(android.graphics.drawable.Drawable icon)
Sets the header's icon. This replaces the header view. Called by the builder-style methods of subclasses.

param
icon The new icon.
return
This MenuBuilder so additional setters can be called.

        setHeaderInternal(0, null, 0, icon, null);
        return this;
    
protected com.android.internal.view.menu.MenuBuildersetHeaderIconInt(int iconRes)
Sets the header's icon. This replaces the header view. Called by the builder-style methods of subclasses.

param
iconRes The new icon (as a resource ID).
return
This MenuBuilder so additional setters can be called.

        setHeaderInternal(0, null, iconRes, null, null);
        return this;
    
private voidsetHeaderInternal(int titleRes, java.lang.CharSequence title, int iconRes, android.graphics.drawable.Drawable icon, android.view.View view)

        final Resources r = getResources();

        if (view != null) {
            mHeaderView = view;
            
            // If using a custom view, then the title and icon aren't used
            mHeaderTitle = null;
            mHeaderIcon = null;
        } else {
            if (titleRes > 0) {
                mHeaderTitle = r.getText(titleRes);
            } else if (title != null) {
                mHeaderTitle = title;
            }
            
            if (iconRes > 0) {
                mHeaderIcon = r.getDrawable(iconRes);
            } else if (icon != null) {
                mHeaderIcon = icon;
            }
            
            // If using the title or icon, then a custom view isn't used
            mHeaderView = null;
        }
        
        // Notify of change
        onItemsChanged(false);
    
protected com.android.internal.view.menu.MenuBuildersetHeaderTitleInt(java.lang.CharSequence title)
Sets the header's title. This replaces the header view. Called by the builder-style methods of subclasses.

param
title The new title.
return
This MenuBuilder so additional setters can be called.

        setHeaderInternal(0, title, 0, null, null);
        return this;
    
protected com.android.internal.view.menu.MenuBuildersetHeaderTitleInt(int titleRes)
Sets the header's title. This replaces the header view. Called by the builder-style methods of subclasses.

param
titleRes The new title (as a resource ID).
return
This MenuBuilder so additional setters can be called.

        setHeaderInternal(titleRes, null, 0, null, null);
        return this;
    
protected com.android.internal.view.menu.MenuBuildersetHeaderViewInt(android.view.View view)
Sets the header's view. This replaces the title and icon. Called by the builder-style methods of subclasses.

param
view The new view.
return
This MenuBuilder so additional setters can be called.

        setHeaderInternal(0, null, 0, null, view);
        return this;
    
voidsetOptionalIconsVisible(boolean visible)

        mOptionalIconsVisible = visible;
    
public voidsetQwertyMode(boolean isQwerty)

        mQwertyMode = isQwerty;
        
        refreshShortcuts(isShortcutsVisible(), isQwerty);
    
public voidsetShortcutsVisible(boolean shortcutsVisible)
Sets whether the shortcuts should be visible on menus. Devices without hardware key input will never make shortcuts visible even if this method is passed 'true'.

param
shortcutsVisible Whether shortcuts should be visible (if true and a menu item does not have a shortcut defined, that item will still NOT show a shortcut)

        if (mShortcutsVisible == shortcutsVisible) return;
        
        mShortcutsVisible =
            (mResources.getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS)
            && shortcutsVisible;
        
        refreshShortcuts(mShortcutsVisible, isQwertyMode());
    
public intsize()

        return mItems.size();