Methods Summary |
---|
void | clearItemViews()
for (int i = mItemViews.length - 1; i >= 0; i--) {
mItemViews[i] = null;
}
|
private com.android.internal.view.menu.MenuView.ItemView | createItemView(int menuType, android.view.ViewGroup parent)Create and initializes a menu item view that implements {@link MenuView.ItemView}.
// Create the MenuView
MenuView.ItemView itemView = (MenuView.ItemView) getLayoutInflater(menuType)
.inflate(MenuBuilder.ITEM_LAYOUT_RES_FOR_TYPE[menuType], parent, false);
itemView.initialize(this, menuType);
return itemView;
|
public char | getAlphabeticShortcut()
return mShortcutAlphabeticChar;
|
java.lang.Runnable | getCallback()
return mItemCallback;
|
public int | getGroupId()
return mGroup;
|
public android.graphics.drawable.Drawable | getIcon()
if (mIconDrawable != null) {
return mIconDrawable;
}
if (mIconResId != NO_ICON) {
return mMenu.getResources().getDrawable(mIconResId);
}
return null;
|
public android.content.Intent | getIntent()
return mIntent;
|
public int | getItemId()
return mId;
|
android.view.View | getItemView(int menuType, android.view.ViewGroup parent)
if (!hasItemView(menuType)) {
mItemViews[menuType] = new WeakReference<ItemView>(createItemView(menuType, parent));
}
return (View) mItemViews[menuType].get();
|
public android.view.LayoutInflater | getLayoutInflater(int menuType)Returns a LayoutInflater that is themed for the given menu type.
return mMenu.getMenuType(menuType).getInflater();
|
public android.view.ContextMenu.ContextMenuInfo | getMenuInfo()
return mMenuInfo;
|
public char | getNumericShortcut()
return mShortcutNumericChar;
|
public int | getOrder()
return mCategoryOrder;
|
public int | getOrdering()
return mOrdering;
|
char | getShortcut()
return (mMenu.isQwertyMode() ? mShortcutAlphabeticChar : mShortcutNumericChar);
|
java.lang.String | getShortcutLabel()
char shortcut = getShortcut();
if (shortcut == 0) {
return "";
}
StringBuilder sb = new StringBuilder(sPrependShortcutLabel);
switch (shortcut) {
case '\n":
sb.append(sEnterShortcutLabel);
break;
case '\b":
sb.append(sDeleteShortcutLabel);
break;
case ' ":
sb.append(sSpaceShortcutLabel);
break;
default:
sb.append(shortcut);
break;
}
return sb.toString();
|
public android.view.SubMenu | getSubMenu()
return mSubMenu;
|
public java.lang.CharSequence | getTitle()
return mTitle;
|
public java.lang.CharSequence | getTitleCondensed()
return mTitleCondensed != null ? mTitleCondensed : mTitle;
|
java.lang.CharSequence | getTitleForItemView(com.android.internal.view.menu.MenuView.ItemView itemView)Gets the title for a particular {@link ItemView}
return ((itemView != null) && itemView.prefersCondensedTitle())
? getTitleCondensed()
: getTitle();
|
private boolean | hasItemView(int menuType)
return mItemViews[menuType] != null && mItemViews[menuType].get() != null;
|
public boolean | hasSubMenu()
return mSubMenu != null;
|
private boolean | haveAnyOpenedIconCapableItemViews()
for (int i = MenuBuilder.NUM_TYPES - 1; i >= 0; i--) {
if (hasItemView(i) && mItemViews[i].get().showsIcon()) {
return true;
}
}
return false;
|
public boolean | invoke()Invokes the item by calling various listeners or callbacks.
if (mClickListener != null &&
mClickListener.onMenuItemClick(this)) {
return true;
}
MenuBuilder.Callback callback = mMenu.getCallback();
if (callback != null &&
callback.onMenuItemSelected(mMenu.getRootMenu(), this)) {
return true;
}
if (mItemCallback != null) {
mItemCallback.run();
return true;
}
if (mIntent != null) {
mMenu.getContext().startActivity(mIntent);
return true;
}
return false;
|
public boolean | isCheckable()
return (mFlags & CHECKABLE) == CHECKABLE;
|
public boolean | isChecked()
return (mFlags & CHECKED) == CHECKED;
|
public boolean | isEnabled()
return (mFlags & ENABLED) != 0;
|
public boolean | isExclusiveCheckable()
return (mFlags & EXCLUSIVE) != 0;
|
public boolean | isVisible()
return (mFlags & HIDDEN) == 0;
|
private void | refreshShortcutOnItemViews()Refreshes the shortcut shown on the ItemViews. This method retrieves current
shortcut state (mode and shown) from the menu that contains this item.
refreshShortcutOnItemViews(mMenu.isShortcutsVisible(), mMenu.isQwertyMode());
|
void | refreshShortcutOnItemViews(boolean menuShortcutShown, boolean isQwertyMode)Refreshes the shortcut shown on the ItemViews. This is usually called by
the {@link MenuBuilder} when it is refreshing the shortcuts on all item
views, so it passes arguments rather than each item calling a method on the menu to get
the same values.
final char shortcutKey = (isQwertyMode) ? mShortcutAlphabeticChar : mShortcutNumericChar;
// Show shortcuts if the menu is supposed to show shortcuts AND this item has a shortcut
final boolean showShortcut = menuShortcutShown && (shortcutKey != 0);
for (int i = MenuBuilder.NUM_TYPES - 1; i >= 0; i--) {
if (hasItemView(i)) {
mItemViews[i].get().setShortcut(showShortcut, shortcutKey);
}
}
|
public android.view.MenuItem | setAlphabeticShortcut(char alphaChar)
if (mShortcutAlphabeticChar == alphaChar) return this;
mShortcutAlphabeticChar = Character.toLowerCase(alphaChar);
refreshShortcutOnItemViews();
return this;
|
public android.view.MenuItem | setCallback(java.lang.Runnable callback)
mItemCallback = callback;
return this;
|
public android.view.MenuItem | setCheckable(boolean checkable)
final int oldFlags = mFlags;
mFlags = (mFlags & ~CHECKABLE) | (checkable ? CHECKABLE : 0);
if (oldFlags != mFlags) {
for (int i = MenuBuilder.NUM_TYPES - 1; i >= 0; i--) {
if (hasItemView(i)) {
mItemViews[i].get().setCheckable(checkable);
}
}
}
return this;
|
public android.view.MenuItem | setChecked(boolean checked)
if ((mFlags & EXCLUSIVE) != 0) {
// Call the method on the Menu since it knows about the others in this
// exclusive checkable group
mMenu.setExclusiveItemChecked(this);
} else {
setCheckedInt(checked);
}
return this;
|
void | setCheckedInt(boolean checked)
final int oldFlags = mFlags;
mFlags = (mFlags & ~CHECKED) | (checked ? CHECKED : 0);
if (oldFlags != mFlags) {
for (int i = MenuBuilder.NUM_TYPES - 1; i >= 0; i--) {
if (hasItemView(i)) {
mItemViews[i].get().setChecked(checked);
}
}
}
|
public android.view.MenuItem | setEnabled(boolean enabled)
if (enabled) {
mFlags |= ENABLED;
} else {
mFlags &= ~ENABLED;
}
for (int i = MenuBuilder.NUM_TYPES - 1; i >= 0; i--) {
// If the item view prefers a condensed title, only set this title if there
// is no condensed title for this item
if (hasItemView(i)) {
mItemViews[i].get().setEnabled(enabled);
}
}
return this;
|
public void | setExclusiveCheckable(boolean exclusive)
mFlags = (mFlags&~EXCLUSIVE) | (exclusive ? EXCLUSIVE : 0);
|
public android.view.MenuItem | setIcon(android.graphics.drawable.Drawable icon)
mIconResId = NO_ICON;
mIconDrawable = icon;
setIconOnViews(icon);
return this;
|
public android.view.MenuItem | setIcon(int iconResId)
mIconDrawable = null;
mIconResId = iconResId;
// If we have a view, we need to push the Drawable to them
if (haveAnyOpenedIconCapableItemViews()) {
Drawable drawable = iconResId != NO_ICON ? mMenu.getResources().getDrawable(iconResId)
: null;
setIconOnViews(drawable);
}
return this;
|
private void | setIconOnViews(android.graphics.drawable.Drawable icon)
for (int i = MenuBuilder.NUM_TYPES - 1; i >= 0; i--) {
// Refresh those item views that are able to display an icon
if (hasItemView(i) && mItemViews[i].get().showsIcon()) {
mItemViews[i].get().setIcon(icon);
}
}
|
public android.view.MenuItem | setIntent(android.content.Intent intent)
mIntent = intent;
return this;
|
void | setMenuInfo(android.view.ContextMenu.ContextMenuInfo menuInfo)
mMenuInfo = menuInfo;
|
public android.view.MenuItem | setNumericShortcut(char numericChar)
if (mShortcutNumericChar == numericChar) return this;
mShortcutNumericChar = numericChar;
refreshShortcutOnItemViews();
return this;
|
public android.view.MenuItem | setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener clickListener)
mClickListener = clickListener;
return this;
|
public android.view.MenuItem | setShortcut(char numericChar, char alphaChar)
mShortcutNumericChar = numericChar;
mShortcutAlphabeticChar = Character.toLowerCase(alphaChar);
refreshShortcutOnItemViews();
return this;
|
void | setSubMenu(SubMenuBuilder subMenu)
if ((mMenu != null) && (mMenu instanceof SubMenu)) {
throw new UnsupportedOperationException(
"Attempt to add a sub-menu to a sub-menu.");
}
mSubMenu = subMenu;
subMenu.setHeaderTitle(getTitle());
|
public android.view.MenuItem | setTitle(java.lang.CharSequence title)
mTitle = title;
for (int i = MenuBuilder.NUM_TYPES - 1; i >= 0; i--) {
// If the item view prefers a condensed title, only set this title if there
// is no condensed title for this item
if (!hasItemView(i)) {
continue;
}
ItemView itemView = mItemViews[i].get();
if (!itemView.prefersCondensedTitle() || mTitleCondensed == null) {
itemView.setTitle(title);
}
}
if (mSubMenu != null) {
mSubMenu.setHeaderTitle(title);
}
return this;
|
public android.view.MenuItem | setTitle(int title)
return setTitle(mMenu.getContext().getString(title));
|
public android.view.MenuItem | setTitleCondensed(java.lang.CharSequence title)
mTitleCondensed = title;
// Could use getTitle() in the loop below, but just cache what it would do here
if (title == null) {
title = mTitle;
}
for (int i = MenuBuilder.NUM_TYPES - 1; i >= 0; i--) {
// Refresh those item views that prefer a condensed title
if (hasItemView(i) && (mItemViews[i].get().prefersCondensedTitle())) {
mItemViews[i].get().setTitle(title);
}
}
return this;
|
public android.view.MenuItem | setVisible(boolean shown)
// Try to set the shown state to the given state. If the shown state was changed
// (i.e. the previous state isn't the same as given state), notify the parent menu that
// the shown state has changed for this item
if (setVisibleInt(shown)) mMenu.onItemVisibleChanged(this);
return this;
|
boolean | setVisibleInt(boolean shown)Changes the visibility of the item. This method DOES NOT notify the
parent menu of a change in this item, so this should only be called from
methods that will eventually trigger this change. If unsure, use {@link #setVisible(boolean)}
instead.
final int oldFlags = mFlags;
mFlags = (mFlags & ~HIDDEN) | (shown ? 0 : HIDDEN);
return oldFlags != mFlags;
|
public boolean | shouldShowIcon(int menuType)
return menuType == MenuBuilder.TYPE_ICON || mMenu.getOptionalIconsVisible();
|
boolean | shouldShowShortcut()
// Show shortcuts if the menu is supposed to show shortcuts AND this item has a shortcut
return mMenu.isShortcutsVisible() && (getShortcut() != 0);
|
public java.lang.String | toString()
return mTitle.toString();
|