Methods Summary |
---|
public android.view.MenuItem | add(java.lang.CharSequence title)
return addInternal(0, 0, 0, title);
|
public android.view.MenuItem | add(int titleRes)
return addInternal(0, 0, 0, mResources.getString(titleRes));
|
public android.view.MenuItem | add(int group, int id, int categoryOrder, java.lang.CharSequence title)
return addInternal(group, id, categoryOrder, title);
|
public android.view.MenuItem | add(int group, int id, int categoryOrder, int title)
return addInternal(group, id, categoryOrder, mResources.getString(title));
|
public int | addIntentOptions(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.MenuItem | addInternal(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 = createNewMenuItem(group, id, categoryOrder, ordering, title,
mDefaultShowAsAction);
if (mCurrentMenuInfo != null) {
// Pass along the current menu info
item.setMenuInfo(mCurrentMenuInfo);
}
mItems.add(findInsertIndex(mItems, ordering), item);
onItemsChanged(true);
return item;
|
public void | addMenuPresenter(MenuPresenter presenter)Add a presenter to this menu. This will only hold a WeakReference;
you do not need to explicitly remove a presenter, but you can using
{@link #removeMenuPresenter(MenuPresenter)}.
addMenuPresenter(presenter, mContext);
|
public void | addMenuPresenter(MenuPresenter presenter, android.content.Context menuContext)Add a presenter to this menu that uses an alternate context for
inflating menu items. This will only hold a WeakReference; you do not
need to explicitly remove a presenter, but you can using
{@link #removeMenuPresenter(MenuPresenter)}.
mPresenters.add(new WeakReference<MenuPresenter>(presenter));
presenter.initForMenu(menuContext, this);
mIsActionItemsStale = true;
|
public android.view.SubMenu | addSubMenu(java.lang.CharSequence title)
return addSubMenu(0, 0, 0, title);
|
public android.view.SubMenu | addSubMenu(int titleRes)
return addSubMenu(0, 0, 0, mResources.getString(titleRes));
|
public android.view.SubMenu | addSubMenu(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.SubMenu | addSubMenu(int group, int id, int categoryOrder, int title)
return addSubMenu(group, id, categoryOrder, mResources.getString(title));
|
public void | changeMenuMode()Dispatch a mode change event to this menu's callback.
if (mCallback != null) {
mCallback.onMenuModeChange(this);
}
|
public void | clear()
if (mExpandedItem != null) {
collapseItemActionView(mExpandedItem);
}
mItems.clear();
onItemsChanged(true);
|
public void | clearAll()
mPreventDispatchingItemsChanged = true;
clear();
clearHeader();
mPreventDispatchingItemsChanged = false;
mItemsChangedWhileDispatchPrevented = false;
onItemsChanged(true);
|
public void | clearHeader()
mHeaderIcon = null;
mHeaderTitle = null;
mHeaderView = null;
onItemsChanged(false);
|
public final void | close(boolean allMenusAreClosing)Closes the visible menu.
if (mIsClosing) return;
mIsClosing = true;
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else {
presenter.onCloseMenu(this, allMenusAreClosing);
}
}
mIsClosing = false;
|
public void | close(){@inheritDoc}
close(true);
|
public boolean | collapseItemActionView(MenuItemImpl item)
if (mPresenters.isEmpty() || mExpandedItem != item) return false;
boolean collapsed = false;
stopDispatchingItemsChanged();
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else if ((collapsed = presenter.collapseItemActionView(this, item))) {
break;
}
}
startDispatchingItemsChanged();
if (collapsed) {
mExpandedItem = null;
}
return collapsed;
|
private MenuItemImpl | createNewMenuItem(int group, int id, int categoryOrder, int ordering, java.lang.CharSequence title, int defaultShowAsAction)
return new MenuItemImpl(this, group, id, categoryOrder, ordering, title,
defaultShowAsAction);
|
boolean | dispatchMenuItemSelected(com.android.internal.view.menu.MenuBuilder menu, android.view.MenuItem item)
return mCallback != null && mCallback.onMenuItemSelected(menu, item);
|
private void | dispatchPresenterUpdate(boolean cleared)
if (mPresenters.isEmpty()) return;
stopDispatchingItemsChanged();
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else {
presenter.updateMenuView(cleared);
}
}
startDispatchingItemsChanged();
|
private void | dispatchRestoreInstanceState(android.os.Bundle state)
SparseArray<Parcelable> presenterStates = state.getSparseParcelableArray(PRESENTER_KEY);
if (presenterStates == null || mPresenters.isEmpty()) return;
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else {
final int id = presenter.getId();
if (id > 0) {
Parcelable parcel = presenterStates.get(id);
if (parcel != null) {
presenter.onRestoreInstanceState(parcel);
}
}
}
}
|
private void | dispatchSaveInstanceState(android.os.Bundle outState)
if (mPresenters.isEmpty()) return;
SparseArray<Parcelable> presenterStates = new SparseArray<Parcelable>();
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else {
final int id = presenter.getId();
if (id > 0) {
final Parcelable state = presenter.onSaveInstanceState();
if (state != null) {
presenterStates.put(id, state);
}
}
}
}
outState.putSparseParcelableArray(PRESENTER_KEY, presenterStates);
|
private boolean | dispatchSubMenuSelected(SubMenuBuilder subMenu, MenuPresenter preferredPresenter)
if (mPresenters.isEmpty()) return false;
boolean result = false;
// Try the preferred presenter first.
if (preferredPresenter != null) {
result = preferredPresenter.onSubMenuSelected(subMenu);
}
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else if (!result) {
result = presenter.onSubMenuSelected(subMenu);
}
}
return result;
|
public boolean | expandItemActionView(MenuItemImpl item)
if (mPresenters.isEmpty()) return false;
boolean expanded = false;
stopDispatchingItemsChanged();
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else if ((expanded = presenter.expandItemActionView(this, item))) {
break;
}
}
startDispatchingItemsChanged();
if (expanded) {
mExpandedItem = item;
}
return expanded;
|
public int | findGroupIndex(int group)
return findGroupIndex(group, 0);
|
public int | findGroupIndex(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 int | findInsertIndex(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.MenuItem | findItem(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 int | findItemIndex(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;
|
MenuItemImpl | findItemWithShortcutForKey(int keyCode, android.view.KeyEvent event)
// Get all items that can be associated directly or indirectly with the keyCode
ArrayList<MenuItemImpl> items = mTempShortcutItemList;
items.clear();
findItemsWithShortcutForKey(items, keyCode, event);
if (items.isEmpty()) {
return null;
}
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)
event.getKeyData(possibleChars);
// If we have only one element, we can safely returns it
final int size = items.size();
if (size == 1) {
return items.get(0);
}
final boolean qwerty = isQwertyMode();
// If we found more than one item associated with the key,
// we have to return the exact match
for (int i = 0; i < size; i++) {
final MenuItemImpl item = items.get(i);
final char shortcutChar = qwerty ? item.getAlphabeticShortcut() :
item.getNumericShortcut();
if ((shortcutChar == possibleChars.meta[0] &&
(metaState & KeyEvent.META_ALT_ON) == 0)
|| (shortcutChar == possibleChars.meta[2] &&
(metaState & KeyEvent.META_ALT_ON) != 0)
|| (qwerty && shortcutChar == '\b" &&
keyCode == KeyEvent.KEYCODE_DEL)) {
return item;
}
}
return null;
|
void | findItemsWithShortcutForKey(java.util.List items, 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;
}
// 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()) {
((MenuBuilder)item.getSubMenu()).findItemsWithShortcutForKey(items, keyCode, event);
}
final char shortcutChar = qwerty ? item.getAlphabeticShortcut() : item.getNumericShortcut();
if (((metaState & (KeyEvent.META_SHIFT_ON | KeyEvent.META_SYM_ON)) == 0) &&
(shortcutChar != 0) &&
(shortcutChar == possibleChars.meta[0]
|| shortcutChar == possibleChars.meta[2]
|| (qwerty && shortcutChar == '\b" &&
keyCode == KeyEvent.KEYCODE_DEL)) &&
item.isEnabled()) {
items.add(item);
}
}
|
public void | flagActionItems()This method determines which menu items get to be 'action items' that will appear
in an action bar and which items should be 'overflow items' in a secondary menu.
The rules are as follows:
Items are considered for inclusion in the order specified within the menu.
There is a limit of mMaxActionItems as a total count, optionally including the overflow
menu button itself. This is a soft limit; if an item shares a group ID with an item
previously included as an action item, the new item will stay with its group and become
an action item itself even if it breaks the max item count limit. This is done to
limit the conceptual complexity of the items presented within an action bar. Only a few
unrelated concepts should be presented to the user in this space, and groups are treated
as a single concept.
There is also a hard limit of consumed measurable space: mActionWidthLimit. This
limit may be broken by a single item that exceeds the remaining space, but no further
items may be added. If an item that is part of a group cannot fit within the remaining
measured width, the entire group will be demoted to overflow. This is done to ensure room
for navigation and other affordances in the action bar as well as reduce general UI clutter.
The space freed by demoting a full group cannot be consumed by future menu items.
Once items begin to overflow, all future items become overflow items as well. This is
to avoid inadvertent reordering that may break the app's intended design.
// Important side effect: if getVisibleItems is stale it may refresh,
// which can affect action items staleness.
final ArrayList<MenuItemImpl> visibleItems = getVisibleItems();
if (!mIsActionItemsStale) {
return;
}
// Presenters flag action items as needed.
boolean flagged = false;
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else {
flagged |= presenter.flagActionItems();
}
}
if (flagged) {
mActionItems.clear();
mNonActionItems.clear();
final int itemsSize = visibleItems.size();
for (int i = 0; i < itemsSize; i++) {
MenuItemImpl item = visibleItems.get(i);
if (item.isActionButton()) {
mActionItems.add(item);
} else {
mNonActionItems.add(item);
}
}
} else {
// Nobody flagged anything, everything is a non-action item.
// (This happens during a first pass with no action-item presenters.)
mActionItems.clear();
mNonActionItems.clear();
mNonActionItems.addAll(getVisibleItems());
}
mIsActionItemsStale = false;
|
public java.util.ArrayList | getActionItems()
flagActionItems();
return mActionItems;
|
protected java.lang.String | getActionViewStatesKey()
return ACTION_VIEW_STATES_KEY;
|
public android.content.Context | getContext()
return mContext;
|
public MenuItemImpl | getExpandedItem()
return mExpandedItem;
|
public android.graphics.drawable.Drawable | getHeaderIcon()
return mHeaderIcon;
|
public java.lang.CharSequence | getHeaderTitle()
return mHeaderTitle;
|
public android.view.View | getHeaderView()
return mHeaderView;
|
public android.view.MenuItem | getItem(int index){@inheritDoc}
return mItems.get(index);
|
public java.util.ArrayList | getNonActionItems()
flagActionItems();
return mNonActionItems;
|
boolean | getOptionalIconsVisible()
return mOptionalIconsVisible;
|
private static int | getOrdering(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.
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.Resources | getResources()
return mResources;
|
public com.android.internal.view.menu.MenuBuilder | getRootMenu()Gets the root menu (if this is a submenu, find its root menu).
return this;
|
public java.util.ArrayList | getVisibleItems()
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;
mIsActionItemsStale = true;
return mVisibleItems;
|
public boolean | hasVisibleItems()
final int size = size();
for (int i = 0; i < size; i++) {
MenuItemImpl item = mItems.get(i);
if (item.isVisible()) {
return true;
}
}
return false;
|
boolean | isQwertyMode()
return mQwertyMode;
|
public boolean | isShortcutKey(int keyCode, android.view.KeyEvent event)
return findItemWithShortcutForKey(keyCode, event) != null;
|
public boolean | isShortcutsVisible()
return mShortcutsVisible;
|
void | onItemActionRequestChanged(MenuItemImpl item)Called by {@link MenuItemImpl} when its action request status is changed.
// Notify of items being changed
mIsActionItemsStale = true;
onItemsChanged(true);
|
void | onItemVisibleChanged(MenuItemImpl item)Called by {@link MenuItemImpl} when its visible flag is changed.
// Notify of items being changed
mIsVisibleItemsStale = true;
onItemsChanged(true);
|
public void | onItemsChanged(boolean structureChanged)Called when an item is added or removed.
if (!mPreventDispatchingItemsChanged) {
if (structureChanged) {
mIsVisibleItemsStale = true;
mIsActionItemsStale = true;
}
dispatchPresenterUpdate(structureChanged);
} else {
mItemsChangedWhileDispatchPrevented = true;
}
|
public boolean | performIdentifierAction(int id, int flags)
// Look for an item whose identifier is the id.
return performItemAction(findItem(id), flags);
|
public boolean | performItemAction(android.view.MenuItem item, int flags)
return performItemAction(item, null, flags);
|
public boolean | performItemAction(android.view.MenuItem item, MenuPresenter preferredPresenter, int flags)
MenuItemImpl itemImpl = (MenuItemImpl) item;
if (itemImpl == null || !itemImpl.isEnabled()) {
return false;
}
boolean invoked = itemImpl.invoke();
final ActionProvider provider = item.getActionProvider();
final boolean providerHasSubMenu = provider != null && provider.hasSubMenu();
if (itemImpl.hasCollapsibleActionView()) {
invoked |= itemImpl.expandActionView();
if (invoked) close(true);
} else if (itemImpl.hasSubMenu() || providerHasSubMenu) {
close(false);
if (!itemImpl.hasSubMenu()) {
itemImpl.setSubMenu(new SubMenuBuilder(getContext(), this, itemImpl));
}
final SubMenuBuilder subMenu = (SubMenuBuilder) itemImpl.getSubMenu();
if (providerHasSubMenu) {
provider.onPrepareSubMenu(subMenu);
}
invoked |= dispatchSubMenuSelected(subMenu, preferredPresenter);
if (!invoked) close(true);
} else {
if ((flags & FLAG_PERFORM_NO_CLOSE) == 0) {
close(true);
}
}
return invoked;
|
public boolean | performShortcut(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;
|
public void | removeGroup(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(true);
}
|
public void | removeItem(int id)
removeItemAtInt(findItemIndex(id), true);
|
public void | removeItemAt(int index)
removeItemAtInt(index, true);
|
private void | removeItemAtInt(int index, boolean updateChildrenOnMenuViews)Remove the item at the given index and optionally forces menu views to
update.
if ((index < 0) || (index >= mItems.size())) return;
mItems.remove(index);
if (updateChildrenOnMenuViews) onItemsChanged(true);
|
public void | removeMenuPresenter(MenuPresenter presenter)Remove a presenter from this menu. That presenter will no longer
receive notifications of updates to this menu's data.
for (WeakReference<MenuPresenter> ref : mPresenters) {
final MenuPresenter item = ref.get();
if (item == null || item == presenter) {
mPresenters.remove(ref);
}
}
|
public void | restoreActionViewStates(android.os.Bundle states)
if (states == null) {
return;
}
SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(
getActionViewStatesKey());
final int itemCount = size();
for (int i = 0; i < itemCount; i++) {
final MenuItem item = getItem(i);
final View v = item.getActionView();
if (v != null && v.getId() != View.NO_ID) {
v.restoreHierarchyState(viewStates);
}
if (item.hasSubMenu()) {
final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
subMenu.restoreActionViewStates(states);
}
}
final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
if (expandedId > 0) {
MenuItem itemToExpand = findItem(expandedId);
if (itemToExpand != null) {
itemToExpand.expandActionView();
}
}
|
public void | restorePresenterStates(android.os.Bundle state)
dispatchRestoreInstanceState(state);
|
public void | saveActionViewStates(android.os.Bundle outStates)
SparseArray<Parcelable> viewStates = null;
final int itemCount = size();
for (int i = 0; i < itemCount; i++) {
final MenuItem item = getItem(i);
final View v = item.getActionView();
if (v != null && v.getId() != View.NO_ID) {
if (viewStates == null) {
viewStates = new SparseArray<Parcelable>();
}
v.saveHierarchyState(viewStates);
if (item.isActionViewExpanded()) {
outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId());
}
}
if (item.hasSubMenu()) {
final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
subMenu.saveActionViewStates(outStates);
}
}
if (viewStates != null) {
outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates);
}
|
public void | savePresenterStates(android.os.Bundle outState)
dispatchSaveInstanceState(outState);
|
public void | setCallback(com.android.internal.view.menu.MenuBuilder$Callback cb)
mCallback = cb;
|
public void | setCurrentMenuInfo(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).
mCurrentMenuInfo = menuInfo;
|
public com.android.internal.view.menu.MenuBuilder | setDefaultShowAsAction(int defaultShowAsAction)
mDefaultShowAsAction = defaultShowAsAction;
return this;
|
void | setExclusiveItemChecked(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 void | setGroupCheckable(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 void | setGroupEnabled(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 void | setGroupVisible(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(true);
|
protected com.android.internal.view.menu.MenuBuilder | setHeaderIconInt(android.graphics.drawable.Drawable icon)Sets the header's icon. This replaces the header view. Called by the
builder-style methods of subclasses.
setHeaderInternal(0, null, 0, icon, null);
return this;
|
protected com.android.internal.view.menu.MenuBuilder | setHeaderIconInt(int iconRes)Sets the header's icon. This replaces the header view. Called by the
builder-style methods of subclasses.
setHeaderInternal(0, null, iconRes, null, null);
return this;
|
private void | setHeaderInternal(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 = getContext().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.MenuBuilder | setHeaderTitleInt(java.lang.CharSequence title)Sets the header's title. This replaces the header view. Called by the
builder-style methods of subclasses.
setHeaderInternal(0, title, 0, null, null);
return this;
|
protected com.android.internal.view.menu.MenuBuilder | setHeaderTitleInt(int titleRes)Sets the header's title. This replaces the header view. Called by the
builder-style methods of subclasses.
setHeaderInternal(titleRes, null, 0, null, null);
return this;
|
protected com.android.internal.view.menu.MenuBuilder | setHeaderViewInt(android.view.View view)Sets the header's view. This replaces the title and icon. Called by the
builder-style methods of subclasses.
setHeaderInternal(0, null, 0, null, view);
return this;
|
void | setOptionalIconsVisible(boolean visible)
mOptionalIconsVisible = visible;
|
public void | setQwertyMode(boolean isQwerty)
mQwertyMode = isQwerty;
onItemsChanged(false);
|
public void | setShortcutsVisible(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'.
if (mShortcutsVisible == shortcutsVisible) return;
setShortcutsVisibleInner(shortcutsVisible);
onItemsChanged(false);
|
private void | setShortcutsVisibleInner(boolean shortcutsVisible)
mShortcutsVisible = shortcutsVisible
&& mResources.getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS
&& mResources.getBoolean(
com.android.internal.R.bool.config_showMenuShortcutsWhenKeyboardPresent);
|
public int | size()
return mItems.size();
|
public void | startDispatchingItemsChanged()
mPreventDispatchingItemsChanged = false;
if (mItemsChangedWhileDispatchPrevented) {
mItemsChangedWhileDispatchPrevented = false;
onItemsChanged(true);
}
|
public void | stopDispatchingItemsChanged()Stop dispatching item changed events to presenters until
{@link #startDispatchingItemsChanged()} is called. Useful when
many menu operations are going to be performed as a batch.
if (!mPreventDispatchingItemsChanged) {
mPreventDispatchingItemsChanged = true;
mItemsChangedWhileDispatchPrevented = false;
}
|