Class MenuItemImpl
- All Implemented Interfaces:
MenuItem
-
Nested Class Summary
Nested classes/interfaces inherited from interface icyllis.modernui.view.MenuItem
MenuItem.OnActionExpandListener, MenuItem.OnMenuItemClickListener -
Field Summary
Fields inherited from interface icyllis.modernui.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
Modifier and TypeMethodDescriptionvoidbooleanCollapse the action view associated with this menu item.booleanExpand the action view associated with this menu item.Gets theActionProvider.Returns the currently set action view for this menu item.intReturn the modifier for this menu item's alphabetic shortcut.charReturn the char for this menu item's alphabetic shortcut.Retrieve the content description associated with this menu item.intReturn the group identifier that this menu item is part of.getIcon()Returns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before).intReturn the identifier for this menu item.Gets the extra information linked to this menu item.intReturn the modifiers for this menu item's numeric (12-key) shortcut.charReturn the char for this menu item's numeric (12-key) shortcut.intgetOrder()Return the category and order within the category of this item.intGet the sub-menu to be invoked when this item is selected, if it has one.getTitle()Retrieve the current title of the item.Retrieve the current condensed title of the item.Retrieve the tooltip text associated with this menu item.booleanbooleanCheck whether this item has an associated sub-menu.booleaninvoke()Invokes the item by calling various listeners or callbacks.booleanbooleanReturns true if this menu item's action view has been expanded.booleanReturn whether the item can currently display a check mark.booleanReturn whether the item is currently displaying a check mark.booleanReturn the enabled state of the menu item.booleanbooleanReturn the visibility of the menu item.booleanbooleanReturns true ifMenuItem.setShowAsAction(int)was set toMenuItem.SHOW_AS_ACTION_ALWAYS.booleanReturns true ifMenuItem.setShowAsAction(int)was set toMenuItem.SHOW_AS_ACTION_NEVER.setActionProvider(ActionProvider actionProvider) Sets theActionProviderresponsible for creating an action view if the item is placed on the action bar.setActionView(View view) Set an action view for this menu item.voidsetActionViewExpanded(boolean isExpanded) setAlphabeticShortcut(char alphaChar) Change the alphabetic shortcut associated with this item.setAlphabeticShortcut(char alphaChar, int alphaModifiers) Change the alphabetic shortcut associated with this item.setCallback(Runnable callback) setCheckable(boolean checkable) Control whether this item can display a check mark.setChecked(boolean checked) Control whether this item is shown with a check mark.setContentDescription(CharSequence contentDescription) Change the content description associated with this menu item.setEnabled(boolean enabled) Sets whether the menu item is enabled.voidsetExclusiveCheckable(boolean exclusive) Change the icon associated with this item.setIconTintList(ColorStateList iconTintList) Applies a tint to this item's icon.voidsetIsActionButton(boolean isActionButton) setNumericShortcut(char numericChar) Change the numeric shortcut associated with this item.setNumericShortcut(char numericChar, int numericModifiers) Change the numeric shortcut and modifiers associated with this item.Set anMenuItem.OnActionExpandListeneron this menu item to be notified when the associated action view is expanded or collapsed.setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener clickListener) Set a custom listener for invocation of this menu item.setShortcut(char numericChar, char alphaChar) Change both the numeric and alphabetic shortcut associated with this item.setShortcut(char numericChar, char alphaChar, int numericModifiers, int alphaModifiers) Change both the numeric and alphabetic shortcut associated with this item.voidsetShowAsAction(int actionEnum) Sets how this item should display in the presence of an Action Bar.setShowAsActionFlags(int actionEnum) Sets how this item should display in the presence of an Action Bar.setTitle(CharSequence title) Change the title associated with this item.setTitleCondensed(CharSequence title) Change the condensed title associated with this item.setTooltipText(CharSequence tooltipText) Change the tooltip text associated with this menu item.setVisible(boolean shown) Sets the visibility of the menu item.booleanbooleantoString()
-
Method Details
-
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:MenuItemReturn the enabled state of the menu item. -
setEnabled
Description copied from interface:MenuItemSets 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:
setEnabledin interfaceMenuItem- 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:MenuItemReturn the group identifier that this menu item is part of. The group identifier can not be changed after the menu is created.- Specified by:
getGroupIdin interfaceMenuItem- Returns:
- The menu item's group identifier.
-
getItemId
public int getItemId()Description copied from interface:MenuItemReturn the identifier for this menu item. The identifier can not be changed after the menu is created. -
getOrder
public int getOrder()Description copied from interface:MenuItemReturn 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. SeeMenufor a full list. -
getOrdering
public int getOrdering() -
setCallback
-
getAlphabeticShortcut
public char getAlphabeticShortcut()Description copied from interface:MenuItemReturn the char for this menu item's alphabetic shortcut.- Specified by:
getAlphabeticShortcutin interfaceMenuItem- Returns:
- Alphabetic character to use as a shortcut.
-
getAlphabeticModifiers
public int getAlphabeticModifiers()Description copied from interface:MenuItemReturn the modifier for this menu item's alphabetic shortcut. The modifier is a combination ofKeyEvent.META_CTRL_ON,KeyEvent.META_ALT_ON,KeyEvent.META_SHIFT_ON.- Specified by:
getAlphabeticModifiersin interfaceMenuItem- Returns:
- Modifier associated with the keyboard shortcut.
-
setAlphabeticShortcut
Description copied from interface:MenuItemChange the alphabetic shortcut associated with this item. The shortcut will be triggered when the key that generates the given character is pressed along with the corresponding modifier key. The default modifier isKeyEvent.META_CTRL_ONin case nothing is specified. 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
Menufor the menu types that support shortcuts.- Specified by:
setAlphabeticShortcutin interfaceMenuItem- 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.
-
setAlphabeticShortcut
Description copied from interface:MenuItemChange the alphabetic shortcut associated with this item. The shortcut will be triggered when the key that generates the given character is pressed along with the modifier keys. 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
Menufor the menu types that support shortcuts.- Specified by:
setAlphabeticShortcutin interfaceMenuItem- Parameters:
alphaChar- The alphabetic shortcut key. This is the shortcut when using a keyboard with alphabetic keys.alphaModifiers- The modifier associated with the shortcut. It should be a combination ofKeyEvent.META_CTRL_ON,KeyEvent.META_ALT_ON,KeyEvent.META_SHIFT_ON.- Returns:
- This Item so additional setters can be called.
-
getNumericShortcut
public char getNumericShortcut()Description copied from interface:MenuItemReturn the char for this menu item's numeric (12-key) shortcut.- Specified by:
getNumericShortcutin interfaceMenuItem- Returns:
- Numeric character to use as a shortcut.
-
getNumericModifiers
public int getNumericModifiers()Description copied from interface:MenuItemReturn the modifiers for this menu item's numeric (12-key) shortcut. The modifier is a combination ofKeyEvent.META_CTRL_ON,KeyEvent.META_ALT_ON,KeyEvent.META_SHIFT_ON.- Specified by:
getNumericModifiersin interfaceMenuItem- Returns:
- Modifier associated with the numeric shortcut.
-
setNumericShortcut
Description copied from interface:MenuItemChange the numeric shortcut associated with this item.See
Menufor the menu types that support shortcuts.- Specified by:
setNumericShortcutin interfaceMenuItem- 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.
-
setNumericShortcut
Description copied from interface:MenuItemChange the numeric shortcut and modifiers associated with this item.See
Menufor the menu types that support shortcuts.- Specified by:
setNumericShortcutin interfaceMenuItem- Parameters:
numericChar- The numeric shortcut key. This is the shortcut when using a 12-key (numeric) keyboard.numericModifiers- The modifier associated with the shortcut. It should be a combination ofKeyEvent.META_CTRL_ON,KeyEvent.META_ALT_ON,KeyEvent.META_SHIFT_ON.- Returns:
- This Item so additional setters can be called.
-
setShortcut
Description copied from interface:MenuItemChange 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 along with the corresponding modifier key. The default modifier isKeyEvent.META_CTRL_ONin case nothing is specified. Also note that case is not significant and that alphabetic shortcut characters will be handled in lower case.See
Menufor the menu types that support shortcuts.- Specified by:
setShortcutin interfaceMenuItem- 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.
-
setShortcut
public MenuItem setShortcut(char numericChar, char alphaChar, int numericModifiers, int alphaModifiers) Description copied from interface:MenuItemChange 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 along with the corresponding modifier key. Also note that case is not significant and that alphabetic shortcut characters will be handled in lower case.See
Menufor the menu types that support shortcuts.- Specified by:
setShortcutin interfaceMenuItem- 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.numericModifiers- The numeric modifier associated with the shortcut. It should be a combination ofKeyEvent.META_CTRL_ON,KeyEvent.META_ALT_ON,KeyEvent.META_SHIFT_ON.alphaModifiers- The alphabetic modifier associated with the shortcut. It should be a combination ofKeyEvent.META_CTRL_ON,KeyEvent.META_ALT_ON,KeyEvent.META_SHIFT_ON.- Returns:
- This Item so additional setters can be called.
-
getSubMenu
Description copied from interface:MenuItemGet the sub-menu to be invoked when this item is selected, if it has one. SeeMenuItem.hasSubMenu().- Specified by:
getSubMenuin interfaceMenuItem- Returns:
- The associated menu if there is one, else null
-
hasSubMenu
public boolean hasSubMenu()Description copied from interface:MenuItemCheck whether this item has an associated sub-menu. I.e. it is a sub-menu of another menu.- Specified by:
hasSubMenuin interfaceMenuItem- Returns:
- If true this item has a menu; else it is a normal item.
-
getTitle
Description copied from interface:MenuItemRetrieve the current title of the item. -
setTitle
Description copied from interface:MenuItemChange the title associated with this item. -
getTitleCondensed
Description copied from interface:MenuItemRetrieve the current condensed title of the item. If a condensed title was never set, it will return the normal title.- Specified by:
getTitleCondensedin interfaceMenuItem- Returns:
- The condensed title, if it exists. The normal title otherwise.
-
setTitleCondensed
Description copied from interface:MenuItemChange 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:
setTitleCondensedin interfaceMenuItem- Parameters:
title- The new text to be displayed as the condensed title.- Returns:
- This Item so additional setters can be called.
-
getIcon
Description copied from interface:MenuItemReturns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before). Note that if you callMenuItem.setIconTintList(ColorStateList)on this item, and you use a custom menu presenter in your application, you have to apply the tinting explicitly on theDrawablereturned by this method. -
setIcon
Description copied from interface:MenuItemChange the icon associated with this item. This icon will not always be shown, so the title should be sufficient in describing this item. SeeMenufor the menu types that support icons. -
setIconTintList
Description copied from interface:MenuItemApplies a tint to this item's icon.Subsequent calls to
MenuItem.setIcon(Drawable)will automatically mutate the icon and apply the specified tint and tint mode usingDrawable.setTintList(ColorStateList).- Specified by:
setIconTintListin interfaceMenuItem- Parameters:
iconTintList- the tint to apply, may benullto clear tint- See Also:
-
getIconTintList
- Specified by:
getIconTintListin interfaceMenuItem- Returns:
- the tint applied to this item's icon
- See Also:
-
isCheckable
public boolean isCheckable()Description copied from interface:MenuItemReturn whether the item can currently display a check mark.- Specified by:
isCheckablein interfaceMenuItem- Returns:
- If a check mark can be displayed, returns true.
- See Also:
-
setCheckable
Description copied from interface:MenuItemControl whether this item can display a check mark. Setting this does not actually display a check mark (seeMenuItem.setChecked(boolean)for that); rather, it ensures there is room in the item in which to display a check mark.See
Menufor the menu types that support check marks.- Specified by:
setCheckablein interfaceMenuItem- 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:
-
setExclusiveCheckable
public void setExclusiveCheckable(boolean exclusive) -
isExclusiveCheckable
public boolean isExclusiveCheckable() -
isChecked
public boolean isChecked()Description copied from interface:MenuItemReturn whether the item is currently displaying a check mark. -
setChecked
Description copied from interface:MenuItemControl whether this item is shown with a check mark. Note that you must first have enabled checking withMenuItem.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 viaMenu.setGroupCheckable(int, boolean, boolean)), the other items in the group will be unchecked.See
Menufor the menu types that support check marks.- Specified by:
setCheckedin interfaceMenuItem- 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:
-
isVisible
public boolean isVisible()Description copied from interface:MenuItemReturn the visibility of the menu item. -
setVisible
Description copied from interface:MenuItemSets 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 anddisabled).- Specified by:
setVisiblein interfaceMenuItem- 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
Description copied from interface:MenuItemSet a custom listener for invocation of this menu item.- Specified by:
setOnMenuItemClickListenerin interfaceMenuItem- Parameters:
clickListener- The object to receive invokations.- Returns:
- This Item so additional setters can be called.
-
toString
-
getMenuInfo
Description copied from interface:MenuItemGets 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:
getMenuInfoin interfaceMenuItem- Returns:
- The extra information linked to the View that added this menu item to the menu. This can be null.
- See Also:
-
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()Description copied from interface:MenuItemReturns true ifMenuItem.setShowAsAction(int)was set toMenuItem.SHOW_AS_ACTION_ALWAYS. Default value isfalse.- Specified by:
requiresActionButtonin interfaceMenuItem
-
requiresOverflow
public boolean requiresOverflow()Description copied from interface:MenuItemReturns true ifMenuItem.setShowAsAction(int)was set toMenuItem.SHOW_AS_ACTION_NEVER. Default value istrue.- Specified by:
requiresOverflowin interfaceMenuItem
-
setIsActionButton
public void setIsActionButton(boolean isActionButton) -
showsTextAsAction
public boolean showsTextAsAction() -
setShowAsAction
public void setShowAsAction(int actionEnum) Description copied from interface:MenuItemSets how this item should display in the presence of an Action Bar. The parameter actionEnum is a flag set. One ofMenuItem.SHOW_AS_ACTION_ALWAYS,MenuItem.SHOW_AS_ACTION_IF_ROOM, orMenuItem.SHOW_AS_ACTION_NEVERshould be used, and you may optionally OR the value withMenuItem.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:
setShowAsActionin interfaceMenuItem- Parameters:
actionEnum- How the item should display. One ofMenuItem.SHOW_AS_ACTION_ALWAYS,MenuItem.SHOW_AS_ACTION_IF_ROOM, orMenuItem.SHOW_AS_ACTION_NEVER. SHOW_AS_ACTION_NEVER is the default.- See Also:
-
setActionView
Description copied from interface:MenuItemSet 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:
setActionViewin interfaceMenuItem- Parameters:
view- View to use for presenting this item to the user.- Returns:
- This Item so additional setters can be called.
- See Also:
-
getActionView
Description copied from interface:MenuItemReturns the currently set action view for this menu item.- Specified by:
getActionViewin interfaceMenuItem- Returns:
- This item's action view
- See Also:
-
getActionProvider
Description copied from interface:MenuItemGets theActionProvider.- Specified by:
getActionProviderin interfaceMenuItem- Returns:
- The action provider.
- See Also:
-
setActionProvider
Description copied from interface:MenuItemSets theActionProviderresponsible 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(View).- Specified by:
setActionProviderin interfaceMenuItem- Parameters:
actionProvider- The action provider.- Returns:
- This Item so additional setters can be called.
- See Also:
-
setShowAsActionFlags
Description copied from interface:MenuItemSets how this item should display in the presence of an Action Bar. The parameter actionEnum is a flag set. One ofMenuItem.SHOW_AS_ACTION_ALWAYS,MenuItem.SHOW_AS_ACTION_IF_ROOM, orMenuItem.SHOW_AS_ACTION_NEVERshould be used, and you may optionally OR the value withMenuItem.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:
setShowAsActionFlagsin interfaceMenuItem- Parameters:
actionEnum- How the item should display. One ofMenuItem.SHOW_AS_ACTION_ALWAYS,MenuItem.SHOW_AS_ACTION_IF_ROOM, orMenuItem.SHOW_AS_ACTION_NEVER. SHOW_AS_ACTION_NEVER is the default.- Returns:
- This MenuItem instance for call chaining.
- See Also:
-
expandActionView
public boolean expandActionView()Description copied from interface:MenuItemExpand the action view associated with this menu item. The menu item must have an action view set, as well as the showAsAction flagMenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW. If a listener has been set usingMenuItem.setOnActionExpandListener(OnActionExpandListener)it will have itsMenuItem.OnActionExpandListener.onMenuItemActionExpand(MenuItem)method invoked. The listener may return false from this method to prevent expanding the action view.- Specified by:
expandActionViewin interfaceMenuItem- Returns:
- true if the action view was expanded, false otherwise.
-
collapseActionView
public boolean collapseActionView()Description copied from interface:MenuItemCollapse the action view associated with this menu item. The menu item must have an action view set, as well as the showAsAction flagMenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW. If a listener has been set usingMenuItem.setOnActionExpandListener(OnActionExpandListener)it will have itsMenuItem.OnActionExpandListener.onMenuItemActionCollapse(MenuItem)method invoked. The listener may return false from this method to prevent collapsing the action view.- Specified by:
collapseActionViewin interfaceMenuItem- Returns:
- true if the action view was collapsed, false otherwise.
-
setOnActionExpandListener
Description copied from interface:MenuItemSet anMenuItem.OnActionExpandListeneron 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 flagMenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW.- Specified by:
setOnActionExpandListenerin interfaceMenuItem- 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:MenuItemReturns true if this menu item's action view has been expanded.- Specified by:
isActionViewExpandedin interfaceMenuItem- Returns:
- true if the item's action view is expanded, false otherwise.
- See Also:
-
setContentDescription
Description copied from interface:MenuItemChange the content description associated with this menu item.- Specified by:
setContentDescriptionin interfaceMenuItem- Parameters:
contentDescription- The new content description.
-
getContentDescription
Description copied from interface:MenuItemRetrieve the content description associated with this menu item.- Specified by:
getContentDescriptionin interfaceMenuItem- Returns:
- The content description.
-
setTooltipText
Description copied from interface:MenuItemChange the tooltip text associated with this menu item.- Specified by:
setTooltipTextin interfaceMenuItem- Parameters:
tooltipText- The new tooltip text.
-
getTooltipText
Description copied from interface:MenuItemRetrieve the tooltip text associated with this menu item.- Specified by:
getTooltipTextin interfaceMenuItem- Returns:
- The tooltip text.
-