com.actionbarsherlock.internal.view.menu
Class MenuItemImpl

java.lang.Object
  extended by com.actionbarsherlock.internal.view.menu.MenuItemImpl
All Implemented Interfaces:
MenuItem

public final class MenuItemImpl
extends Object
implements MenuItem


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.actionbarsherlock.view.MenuItem
MenuItem.OnActionExpandListener, MenuItem.OnMenuItemClickListener
 
Field Summary
 
Fields inherited from interface com.actionbarsherlock.view.MenuItem
SHOW_AS_ACTION_ALWAYS, SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW, SHOW_AS_ACTION_IF_ROOM, SHOW_AS_ACTION_NEVER, SHOW_AS_ACTION_WITH_TEXT
 
Method Summary
 void actionFormatChanged()
           
 boolean collapseActionView()
          Collapse the action view associated with this menu item.
 boolean expandActionView()
          Expand the action view associated with this menu item.
 ActionProvider getActionProvider()
          Gets the ActionProvider.
 android.view.View getActionView()
          Returns the currently set action view for this menu item.
 char getAlphabeticShortcut()
          Return the char for this menu item's alphabetic shortcut.
 int getGroupId()
          Return the group identifier that this menu item is part of.
 android.graphics.drawable.Drawable getIcon()
          Returns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before).
 android.content.Intent getIntent()
          Return the Intent associated with this item.
 int getItemId()
          Return the identifier for this menu item.
 android.view.ContextMenu.ContextMenuInfo getMenuInfo()
          Gets the extra information linked to this menu item.
 char getNumericShortcut()
          Return the char for this menu item's numeric (12-key) shortcut.
 int getOrder()
          Return the category and order within the category of this item.
 int getOrdering()
           
 SubMenu getSubMenu()
          Get the sub-menu to be invoked when this item is selected, if it has one.
 CharSequence getTitle()
          Retrieve the current title of the item.
 CharSequence getTitleCondensed()
          Retrieve the current condensed title of the item.
 boolean hasCollapsibleActionView()
           
 boolean hasSubMenu()
          Check whether this item has an associated sub-menu.
 boolean invoke()
          Invokes the item by calling various listeners or callbacks.
 boolean isActionButton()
           
 boolean isActionViewExpanded()
          Returns true if this menu item's action view has been expanded.
 boolean isCheckable()
          Return whether the item can currently display a check mark.
 boolean isChecked()
          Return whether the item is currently displaying a check mark.
 boolean isEnabled()
          Return the enabled state of the menu item.
 boolean isExclusiveCheckable()
           
 boolean isVisible()
          Return the visibility of the menu item.
 boolean requestsActionButton()
           
 boolean requiresActionButton()
           
 MenuItem setActionProvider(ActionProvider actionProvider)
          Sets the ActionProvider responsible for creating an action view if the item is placed on the action bar.
 MenuItem setActionView(int resId)
          Set an action view for this menu item.
 MenuItem setActionView(android.view.View view)
          Set an action view for this menu item.
 void setActionViewExpanded(boolean isExpanded)
           
 MenuItem setAlphabeticShortcut(char alphaChar)
          Change the alphabetic shortcut associated with this item.
 MenuItem setCallback(Runnable callback)
           
 MenuItem setCheckable(boolean checkable)
          Control whether this item can display a check mark.
 MenuItem setChecked(boolean checked)
          Control whether this item is shown with a check mark.
 MenuItem setEnabled(boolean enabled)
          Sets whether the menu item is enabled.
 void setExclusiveCheckable(boolean exclusive)
           
 MenuItem setIcon(android.graphics.drawable.Drawable icon)
          Change the icon associated with this item.
 MenuItem setIcon(int iconResId)
          Change the icon associated with this item.
 MenuItem setIntent(android.content.Intent intent)
          Change the Intent associated with this item.
 void setIsActionButton(boolean isActionButton)
           
 MenuItem setNumericShortcut(char numericChar)
          Change the numeric shortcut associated with this item.
 MenuItem setOnActionExpandListener(MenuItem.OnActionExpandListener listener)
          Set an MenuItem.OnActionExpandListener on this menu item to be notified when the associated action view is expanded or collapsed.
 MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener clickListener)
          Set a custom listener for invocation of this menu item.
 MenuItem setShortcut(char numericChar, char alphaChar)
          Change both the numeric and alphabetic shortcut associated with this item.
 void setShowAsAction(int actionEnum)
          Sets how this item should display in the presence of an Action Bar.
 MenuItem setShowAsActionFlags(int actionEnum)
          Sets how this item should display in the presence of an Action Bar.
 MenuItem setTitle(CharSequence title)
          Change the title associated with this item.
 MenuItem setTitle(int title)
          Change the title associated with this item.
 MenuItem setTitleCondensed(CharSequence title)
          Change the condensed title associated with this item.
 MenuItem setVisible(boolean shown)
          Sets the visibility of the menu item.
 boolean shouldShowIcon()
           
 boolean showsTextAsAction()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

invoke

public boolean invoke()
Invokes the item by calling various listeners or callbacks.

Returns:
true if the invocation was handled, false otherwise

isEnabled

public boolean isEnabled()
Description copied from interface: MenuItem
Return the enabled state of the menu item.

Specified by:
isEnabled in interface MenuItem
Returns:
If true the item is enabled and hence invokable; else it is not.

setEnabled

public MenuItem setEnabled(boolean enabled)
Description copied from interface: MenuItem
Sets whether the menu item is enabled. Disabling a menu item will not allow it to be invoked via its shortcut. The menu item will still be visible.

Specified by:
setEnabled in interface MenuItem
Parameters:
enabled - If true then the item will be invokable; if false it is won't be invokable.
Returns:
This Item so additional setters can be called.

getGroupId

public int getGroupId()
Description copied from interface: MenuItem
Return the group identifier that this menu item is part of. The group identifier can not be changed after the menu is created.

Specified by:
getGroupId in interface MenuItem
Returns:
The menu item's group identifier.

getItemId

public int getItemId()
Description copied from interface: MenuItem
Return the identifier for this menu item. The identifier can not be changed after the menu is created.

Specified by:
getItemId in interface MenuItem
Returns:
The menu item's identifier.

getOrder

public int getOrder()
Description copied from interface: MenuItem
Return the category and order within the category of this item. This item will be shown before all items (within its category) that have order greater than this value.

An order integer contains the item's category (the upper bits of the integer; set by or/add the category with the order within the category) and the ordering of the item within that category (the lower bits). Example categories are Menu.CATEGORY_SYSTEM, Menu.CATEGORY_SECONDARY, Menu.CATEGORY_ALTERNATIVE, Menu.CATEGORY_CONTAINER. See Menu for a full list.

Specified by:
getOrder in interface MenuItem
Returns:
The order of this item.

getOrdering

public int getOrdering()

getIntent

public android.content.Intent getIntent()
Description copied from interface: MenuItem
Return the Intent associated with this item. This returns a reference to the Intent which you can change as desired to modify what the Item is holding.

Specified by:
getIntent in interface MenuItem
Returns:
Returns the last value supplied to MenuItem.setIntent(android.content.Intent), or null.
See Also:
MenuItem.setIntent(android.content.Intent)

setIntent

public MenuItem setIntent(android.content.Intent intent)
Description copied from interface: MenuItem
Change the Intent associated with this item. By default there is no Intent associated with a menu item. If you set one, and nothing else handles the item, then the default behavior will be to call Context.startActivity(android.content.Intent) with the given Intent.

Note that setIntent() can not be used with the versions of Menu.add(java.lang.CharSequence) that take a Runnable, because Runnable.run() does not return a value so there is no way to tell if it handled the item. In this case it is assumed that the Runnable always handles the item, and the intent will never be started.

Specified by:
setIntent in interface MenuItem
Parameters:
intent - The Intent to associated with the item. This Intent object is not copied, so be careful not to modify it later.
Returns:
This Item so additional setters can be called.
See Also:
MenuItem.getIntent()

setCallback

public MenuItem setCallback(Runnable callback)

getAlphabeticShortcut

public char getAlphabeticShortcut()
Description copied from interface: MenuItem
Return the char for this menu item's alphabetic shortcut.

Specified by:
getAlphabeticShortcut in interface MenuItem
Returns:
Alphabetic character to use as a shortcut.

setAlphabeticShortcut

public MenuItem setAlphabeticShortcut(char alphaChar)
Description copied from interface: MenuItem
Change the alphabetic shortcut associated with this item. The shortcut will be triggered when the key that generates the given character is pressed alone or along with with the alt key. Case is not significant and shortcut characters will be displayed in lower case. Note that menu items with the characters '\b' or '\n' as shortcuts will get triggered by the Delete key or Carriage Return key, respectively.

See Menu for the menu types that support shortcuts.

Specified by:
setAlphabeticShortcut in interface MenuItem
Parameters:
alphaChar - The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.
Returns:
This Item so additional setters can be called.

getNumericShortcut

public char getNumericShortcut()
Description copied from interface: MenuItem
Return the char for this menu item's numeric (12-key) shortcut.

Specified by:
getNumericShortcut in interface MenuItem
Returns:
Numeric character to use as a shortcut.

setNumericShortcut

public MenuItem setNumericShortcut(char numericChar)
Description copied from interface: MenuItem
Change the numeric shortcut associated with this item.

See Menu for the menu types that support shortcuts.

Specified by:
setNumericShortcut in interface MenuItem
Parameters:
numericChar - The numeric shortcut key. This is the shortcut when using a 12-key (numeric) keyboard.
Returns:
This Item so additional setters can be called.

setShortcut

public MenuItem setShortcut(char numericChar,
                            char alphaChar)
Description copied from interface: MenuItem
Change both the numeric and alphabetic shortcut associated with this item. Note that the shortcut will be triggered when the key that generates the given character is pressed alone or along with with the alt key. Also note that case is not significant and that alphabetic shortcut characters will be displayed in lower case.

See Menu for the menu types that support shortcuts.

Specified by:
setShortcut in interface MenuItem
Parameters:
numericChar - The numeric shortcut key. This is the shortcut when using a numeric (e.g., 12-key) keyboard.
alphaChar - The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.
Returns:
This Item so additional setters can be called.

getSubMenu

public SubMenu getSubMenu()
Description copied from interface: MenuItem
Get the sub-menu to be invoked when this item is selected, if it has one. See MenuItem.hasSubMenu().

Specified by:
getSubMenu in interface MenuItem
Returns:
The associated menu if there is one, else null

hasSubMenu

public boolean hasSubMenu()
Description copied from interface: MenuItem
Check whether this item has an associated sub-menu. I.e. it is a sub-menu of another menu.

Specified by:
hasSubMenu in interface MenuItem
Returns:
If true this item has a menu; else it is a normal item.

getTitle

public CharSequence getTitle()
Description copied from interface: MenuItem
Retrieve the current title of the item.

Specified by:
getTitle in interface MenuItem
Returns:
The title.

setTitle

public MenuItem setTitle(CharSequence title)
Description copied from interface: MenuItem
Change the title associated with this item.

Specified by:
setTitle in interface MenuItem
Parameters:
title - The new text to be displayed.
Returns:
This Item so additional setters can be called.

setTitle

public MenuItem setTitle(int title)
Description copied from interface: MenuItem
Change the title associated with this item.

Some menu types do not sufficient space to show the full title, and instead a condensed title is preferred. See Menu for more information.

Specified by:
setTitle in interface MenuItem
Parameters:
title - The resource id of the new text to be displayed.
Returns:
This Item so additional setters can be called.
See Also:
MenuItem.setTitleCondensed(CharSequence)

getTitleCondensed

public CharSequence getTitleCondensed()
Description copied from interface: MenuItem
Retrieve the current condensed title of the item. If a condensed title was never set, it will return the normal title.

Specified by:
getTitleCondensed in interface MenuItem
Returns:
The condensed title, if it exists. Otherwise the normal title.

setTitleCondensed

public MenuItem setTitleCondensed(CharSequence title)
Description copied from interface: MenuItem
Change the condensed title associated with this item. The condensed title is used in situations where the normal title may be too long to be displayed.

Specified by:
setTitleCondensed in interface MenuItem
Parameters:
title - The new text to be displayed as the condensed title.
Returns:
This Item so additional setters can be called.

getIcon

public android.graphics.drawable.Drawable getIcon()
Description copied from interface: MenuItem
Returns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before).

Specified by:
getIcon in interface MenuItem
Returns:
The icon as a Drawable.

setIcon

public MenuItem setIcon(android.graphics.drawable.Drawable icon)
Description copied from interface: MenuItem
Change the icon associated with this item. This icon will not always be shown, so the title should be sufficient in describing this item. See Menu for the menu types that support icons.

Specified by:
setIcon in interface MenuItem
Parameters:
icon - The new icon (as a Drawable) to be displayed.
Returns:
This Item so additional setters can be called.

setIcon

public MenuItem setIcon(int iconResId)
Description copied from interface: MenuItem
Change the icon associated with this item. This icon will not always be shown, so the title should be sufficient in describing this item. See Menu for the menu types that support icons.

This method will set the resource ID of the icon which will be used to lazily get the Drawable when this item is being shown.

Specified by:
setIcon in interface MenuItem
Parameters:
iconResId - The new icon (as a resource ID) to be displayed.
Returns:
This Item so additional setters can be called.

isCheckable

public boolean isCheckable()
Description copied from interface: MenuItem
Return whether the item can currently display a check mark.

Specified by:
isCheckable in interface MenuItem
Returns:
If a check mark can be displayed, returns true.
See Also:
MenuItem.setCheckable(boolean)

setCheckable

public MenuItem setCheckable(boolean checkable)
Description copied from interface: MenuItem
Control whether this item can display a check mark. Setting this does not actually display a check mark (see MenuItem.setChecked(boolean) for that); rather, it ensures there is room in the item in which to display a check mark.

See Menu for the menu types that support check marks.

Specified by:
setCheckable in interface MenuItem
Parameters:
checkable - Set to true to allow a check mark, false to disallow. The default is false.
Returns:
This Item so additional setters can be called.
See Also:
MenuItem.setChecked(boolean), MenuItem.isCheckable(), Menu.setGroupCheckable(int, boolean, boolean)

setExclusiveCheckable

public void setExclusiveCheckable(boolean exclusive)

isExclusiveCheckable

public boolean isExclusiveCheckable()

isChecked

public boolean isChecked()
Description copied from interface: MenuItem
Return whether the item is currently displaying a check mark.

Specified by:
isChecked in interface MenuItem
Returns:
If a check mark is displayed, returns true.
See Also:
MenuItem.setChecked(boolean)

setChecked

public MenuItem setChecked(boolean checked)
Description copied from interface: MenuItem
Control whether this item is shown with a check mark. Note that you must first have enabled checking with MenuItem.setCheckable(boolean) or else the check mark will not appear. If this item is a member of a group that contains mutually-exclusive items (set via Menu.setGroupCheckable(int, boolean, boolean), the other items in the group will be unchecked.

See Menu for the menu types that support check marks.

Specified by:
setChecked in interface MenuItem
Parameters:
checked - Set to true to display a check mark, false to hide it. The default value is false.
Returns:
This Item so additional setters can be called.
See Also:
MenuItem.setCheckable(boolean), MenuItem.isChecked(), Menu.setGroupCheckable(int, boolean, boolean)

isVisible

public boolean isVisible()
Description copied from interface: MenuItem
Return the visibility of the menu item.

Specified by:
isVisible in interface MenuItem
Returns:
If true the item is visible; else it is hidden.

setVisible

public MenuItem setVisible(boolean shown)
Description copied from interface: MenuItem
Sets the visibility of the menu item. Even if a menu item is not visible, it may still be invoked via its shortcut (to completely disable an item, set it to invisible and disabled).

Specified by:
setVisible in interface MenuItem
Parameters:
shown - If true then the item will be visible; if false it is hidden.
Returns:
This Item so additional setters can be called.

setOnMenuItemClickListener

public MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener clickListener)
Description copied from interface: MenuItem
Set a custom listener for invocation of this menu item. In most situations, it is more efficient and easier to use Activity#onOptionsItemSelected(MenuItem) or Activity#onContextItemSelected(MenuItem).

Specified by:
setOnMenuItemClickListener in interface MenuItem
Parameters:
clickListener - The object to receive invokations.
Returns:
This Item so additional setters can be called.
See Also:
Activity#onOptionsItemSelected(MenuItem), Activity#onContextItemSelected(MenuItem)

toString

public String toString()
Overrides:
toString in class Object

getMenuInfo

public android.view.ContextMenu.ContextMenuInfo getMenuInfo()
Description copied from interface: MenuItem
Gets the extra information linked to this menu item. This extra information is set by the View that added this menu item to the menu.

Specified by:
getMenuInfo in interface MenuItem
Returns:
The extra information linked to the View that added this menu item to the menu. This can be null.
See Also:
OnCreateContextMenuListener

actionFormatChanged

public void actionFormatChanged()

shouldShowIcon

public boolean shouldShowIcon()
Returns:
Whether the menu should show icons for menu items.

isActionButton

public boolean isActionButton()

requestsActionButton

public boolean requestsActionButton()

requiresActionButton

public boolean requiresActionButton()

setIsActionButton

public void setIsActionButton(boolean isActionButton)

showsTextAsAction

public boolean showsTextAsAction()

setShowAsAction

public void setShowAsAction(int actionEnum)
Description copied from interface: MenuItem
Sets how this item should display in the presence of an Action Bar. The parameter actionEnum is a flag set. One of MenuItem.SHOW_AS_ACTION_ALWAYS, MenuItem.SHOW_AS_ACTION_IF_ROOM, or MenuItem.SHOW_AS_ACTION_NEVER should be used, and you may optionally OR the value with MenuItem.SHOW_AS_ACTION_WITH_TEXT. SHOW_AS_ACTION_WITH_TEXT requests that when the item is shown as an action, it should be shown with a text label.

Specified by:
setShowAsAction in interface MenuItem
Parameters:
actionEnum - How the item should display. One of MenuItem.SHOW_AS_ACTION_ALWAYS, MenuItem.SHOW_AS_ACTION_IF_ROOM, or MenuItem.SHOW_AS_ACTION_NEVER. SHOW_AS_ACTION_NEVER is the default.
See Also:
ActionBar, MenuItem.setActionView(View)

setActionView

public MenuItem setActionView(android.view.View view)
Description copied from interface: MenuItem
Set an action view for this menu item. An action view will be displayed in place of an automatically generated menu item element in the UI when this item is shown as an action within a parent.

Note: Setting an action view overrides the action provider set via MenuItem.setActionProvider(ActionProvider).

Specified by:
setActionView in interface MenuItem
Parameters:
view - View to use for presenting this item to the user.
Returns:
This Item so additional setters can be called.
See Also:
MenuItem.setShowAsAction(int)

setActionView

public MenuItem setActionView(int resId)
Description copied from interface: MenuItem
Set an action view for this menu item. An action view will be displayed in place of an automatically generated menu item element in the UI when this item is shown as an action within a parent.

Note: Setting an action view overrides the action provider set via MenuItem.setActionProvider(ActionProvider).

Specified by:
setActionView in interface MenuItem
Parameters:
resId - Layout resource to use for presenting this item to the user.
Returns:
This Item so additional setters can be called.
See Also:
MenuItem.setShowAsAction(int)

getActionView

public android.view.View getActionView()
Description copied from interface: MenuItem
Returns the currently set action view for this menu item.

Specified by:
getActionView in interface MenuItem
Returns:
This item's action view
See Also:
MenuItem.setActionView(View), MenuItem.setShowAsAction(int)

getActionProvider

public ActionProvider getActionProvider()
Description copied from interface: MenuItem
Gets the ActionProvider.

Specified by:
getActionProvider in interface MenuItem
Returns:
The action provider.
See Also:
ActionProvider, MenuItem.setActionProvider(ActionProvider)

setActionProvider

public MenuItem setActionProvider(ActionProvider actionProvider)
Description copied from interface: MenuItem
Sets the ActionProvider responsible for creating an action view if the item is placed on the action bar. The provider also provides a default action invoked if the item is placed in the overflow menu.

Note: Setting an action provider overrides the action view set via MenuItem.setActionView(int) or MenuItem.setActionView(View).

Specified by:
setActionProvider in interface MenuItem
Parameters:
actionProvider - The action provider.
Returns:
This Item so additional setters can be called.
See Also:
ActionProvider

setShowAsActionFlags

public MenuItem setShowAsActionFlags(int actionEnum)
Description copied from interface: MenuItem
Sets how this item should display in the presence of an Action Bar. The parameter actionEnum is a flag set. One of MenuItem.SHOW_AS_ACTION_ALWAYS, MenuItem.SHOW_AS_ACTION_IF_ROOM, or MenuItem.SHOW_AS_ACTION_NEVER should be used, and you may optionally OR the value with MenuItem.SHOW_AS_ACTION_WITH_TEXT. SHOW_AS_ACTION_WITH_TEXT requests that when the item is shown as an action, it should be shown with a text label.

Note: This method differs from MenuItem.setShowAsAction(int) only in that it returns the current MenuItem instance for call chaining.

Specified by:
setShowAsActionFlags in interface MenuItem
Parameters:
actionEnum - How the item should display. One of MenuItem.SHOW_AS_ACTION_ALWAYS, MenuItem.SHOW_AS_ACTION_IF_ROOM, or MenuItem.SHOW_AS_ACTION_NEVER. SHOW_AS_ACTION_NEVER is the default.
Returns:
This MenuItem instance for call chaining.
See Also:
ActionBar, MenuItem.setActionView(View)

expandActionView

public boolean expandActionView()
Description copied from interface: MenuItem
Expand the action view associated with this menu item. The menu item must have an action view set, as well as the showAsAction flag MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW. If a listener has been set using MenuItem.setOnActionExpandListener(OnActionExpandListener) it will have its MenuItem.OnActionExpandListener.onMenuItemActionExpand(MenuItem) method invoked. The listener may return false from this method to prevent expanding the action view.

Specified by:
expandActionView in interface MenuItem
Returns:
true if the action view was expanded, false otherwise.

collapseActionView

public boolean collapseActionView()
Description copied from interface: MenuItem
Collapse the action view associated with this menu item. The menu item must have an action view set, as well as the showAsAction flag MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW. If a listener has been set using MenuItem.setOnActionExpandListener(OnActionExpandListener) it will have its MenuItem.OnActionExpandListener.onMenuItemActionCollapse(MenuItem) method invoked. The listener may return false from this method to prevent collapsing the action view.

Specified by:
collapseActionView in interface MenuItem
Returns:
true if the action view was collapsed, false otherwise.

setOnActionExpandListener

public MenuItem setOnActionExpandListener(MenuItem.OnActionExpandListener listener)
Description copied from interface: MenuItem
Set an MenuItem.OnActionExpandListener on this menu item to be notified when the associated action view is expanded or collapsed. The menu item must be configured to expand or collapse its action view using the flag MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW.

Specified by:
setOnActionExpandListener in interface MenuItem
Parameters:
listener - Listener that will respond to expand/collapse events
Returns:
This menu item instance for call chaining

hasCollapsibleActionView

public boolean hasCollapsibleActionView()

setActionViewExpanded

public void setActionViewExpanded(boolean isExpanded)

isActionViewExpanded

public boolean isActionViewExpanded()
Description copied from interface: MenuItem
Returns true if this menu item's action view has been expanded.

Specified by:
isActionViewExpanded in interface MenuItem
Returns:
true if the item's action view is expanded, false otherwise.
See Also:
MenuItem.expandActionView(), MenuItem.collapseActionView(), MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW, MenuItem.OnActionExpandListener


Copyright © 2012-2013. All Rights Reserved.