Methods Summary |
---|
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 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 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 = 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.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 | clear()
mItems.clear();
onItemsChanged(true);
|
public void | clearAll()
mPreventDispatchingItemsChanged = true;
clear();
clearHeader();
mPreventDispatchingItemsChanged = false;
onItemsChanged(true);
|
public void | clearHeader()
mHeaderIcon = null;
mHeaderTitle = null;
mHeaderView = null;
onItemsChanged(false);
|
public void | clearMenuViews()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 void | close(boolean allMenusAreClosing)Closes the visible menu.
Callback callback = getCallback();
if (callback != null) {
callback.onCloseMenu(this, allMenusAreClosing);
}
|
public void | close(){@inheritDoc}
close(true);
|
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)
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$Callback | getCallback()
return mCallback;
|
public android.content.Context | getContext()
return mContext;
|
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 com.android.internal.view.menu.MenuBuilder$MenuAdapter | getMenuAdapter(int menuType)Gets an adapter for providing items and their views.
return new MenuAdapter(menuType);
|
com.android.internal.view.menu.MenuBuilder$MenuType | getMenuType(int menuType)
if (mMenuTypes[menuType] == null) {
mMenuTypes[menuType] = new MenuType(menuType);
}
return mMenuTypes[menuType];
|
public android.view.View | getMenuView(int menuType, android.view.ViewGroup parent)Gets a menu View that contains this menu's items.
// 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 int | getNumIconMenuItemsShown()
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();
|
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;
|
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;
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 | onItemVisibleChanged(MenuItemImpl item)Called by {@link MenuItemImpl} when its visible flag is changed.
// Notify of items being changed
onItemsChanged(false);
|
private void | onItemsChanged(boolean cleared)Called when an item is added or removed.
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 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)
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 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;
|
private void | refreshShortcuts(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 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(false);
}
|
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(false);
|
public void | restoreHierarchyState(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 void | saveHierarchyState(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 void | setCallback(com.android.internal.view.menu.MenuBuilder$Callback callback)
mCallback = callback;
|
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;
|
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(false);
|
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 = 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.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;
refreshShortcuts(isShortcutsVisible(), isQwerty);
|
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;
mShortcutsVisible =
(mResources.getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS)
&& shortcutsVisible;
refreshShortcuts(mShortcutsVisible, isQwertyMode());
|
public int | size()
return mItems.size();
|