com.actionbarsherlock.internal.view.menu
Class ActionMenu

java.lang.Object
  extended by com.actionbarsherlock.internal.view.menu.ActionMenu
All Implemented Interfaces:
Menu

public class ActionMenu
extends Object
implements Menu


Field Summary
 
Fields inherited from interface com.actionbarsherlock.view.Menu
CATEGORY_ALTERNATIVE, CATEGORY_CONTAINER, CATEGORY_MASK, CATEGORY_SECONDARY, CATEGORY_SHIFT, CATEGORY_SYSTEM, FIRST, FLAG_ALWAYS_PERFORM_CLOSE, FLAG_APPEND_TO_GROUP, FLAG_PERFORM_NO_CLOSE, NONE, USER_MASK, USER_SHIFT
 
Constructor Summary
ActionMenu(android.content.Context context)
           
 
Method Summary
 MenuItem add(CharSequence title)
          Add a new item to the menu.
 MenuItem add(int titleRes)
          Add a new item to the menu.
 MenuItem add(int groupId, int itemId, int order, CharSequence title)
          Add a new item to the menu.
 MenuItem add(int groupId, int itemId, int order, int titleRes)
          Variation on Menu.add(int, int, int, CharSequence) that takes a string resource identifier instead of the string itself.
 int addIntentOptions(int groupId, int itemId, int order, android.content.ComponentName caller, android.content.Intent[] specifics, android.content.Intent intent, int flags, MenuItem[] outSpecificItems)
          Add a group of menu items corresponding to actions that can be performed for a particular Intent.
 SubMenu addSubMenu(CharSequence title)
          Add a new sub-menu to the menu.
 SubMenu addSubMenu(int titleRes)
          Add a new sub-menu to the menu.
 SubMenu addSubMenu(int groupId, int itemId, int order, CharSequence title)
          Add a new sub-menu to the menu.
 SubMenu addSubMenu(int groupId, int itemId, int order, int titleRes)
          Variation on Menu.addSubMenu(int, int, int, CharSequence) that takes a string resource identifier for the title instead of the string itself.
 void clear()
          Remove all existing items from the menu, leaving it empty as if it had just been created.
 void close()
          Closes the menu, if open.
 MenuItem findItem(int id)
          Return the menu item with a particular identifier.
 android.content.Context getContext()
           
 MenuItem getItem(int index)
          Gets the menu item at the given index.
 boolean hasVisibleItems()
          Return whether the menu currently has item items that are visible.
 boolean isShortcutKey(int keyCode, android.view.KeyEvent event)
          Is a keypress one of the defined shortcut keys for this window.
 boolean performIdentifierAction(int id, int flags)
          Execute the menu item action associated with the given menu identifier.
 boolean performShortcut(int keyCode, android.view.KeyEvent event, int flags)
          Execute the menu item action associated with the given shortcut character.
 void removeGroup(int groupId)
          Remove all items in the given group.
 void removeItem(int id)
          Remove the item with the given identifier.
 void setGroupCheckable(int group, boolean checkable, boolean exclusive)
          Control whether a particular group of items can show a check mark.
 void setGroupEnabled(int group, boolean enabled)
          Enable or disable all menu items that are in the given group.
 void setGroupVisible(int group, boolean visible)
          Show or hide all menu items that are in the given group.
 void setQwertyMode(boolean isQwerty)
          Control whether the menu should be running in qwerty mode (alphabetic shortcuts) or 12-key mode (numeric shortcuts).
 int size()
          Get the number of items in the menu.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActionMenu

public ActionMenu(android.content.Context context)
Method Detail

getContext

public android.content.Context getContext()

add

public MenuItem add(CharSequence title)
Description copied from interface: Menu
Add a new item to the menu. This item displays the given title for its label.

Specified by:
add in interface Menu
Parameters:
title - The text to display for the item.
Returns:
The newly added menu item.

add

public MenuItem add(int titleRes)
Description copied from interface: Menu
Add a new item to the menu. This item displays the given title for its label.

Specified by:
add in interface Menu
Parameters:
titleRes - Resource identifier of title string.
Returns:
The newly added menu item.

add

public MenuItem add(int groupId,
                    int itemId,
                    int order,
                    int titleRes)
Description copied from interface: Menu
Variation on Menu.add(int, int, int, CharSequence) that takes a string resource identifier instead of the string itself.

Specified by:
add in interface Menu
Parameters:
groupId - The group identifier that this item should be part of. This can also be used to define groups of items for batch state changes. Normally use Menu.NONE if an item should not be in a group.
itemId - Unique item ID. Use Menu.NONE if you do not need a unique ID.
order - The order for the item. Use Menu.NONE if you do not care about the order. See MenuItem.getOrder().
titleRes - Resource identifier of title string.
Returns:
The newly added menu item.

add

public MenuItem add(int groupId,
                    int itemId,
                    int order,
                    CharSequence title)
Description copied from interface: Menu
Add a new item to the menu. This item displays the given title for its label.

Specified by:
add in interface Menu
Parameters:
groupId - The group identifier that this item should be part of. This can be used to define groups of items for batch state changes. Normally use Menu.NONE if an item should not be in a group.
itemId - Unique item ID. Use Menu.NONE if you do not need a unique ID.
order - The order for the item. Use Menu.NONE if you do not care about the order. See MenuItem.getOrder().
title - The text to display for the item.
Returns:
The newly added menu item.

addIntentOptions

public int addIntentOptions(int groupId,
                            int itemId,
                            int order,
                            android.content.ComponentName caller,
                            android.content.Intent[] specifics,
                            android.content.Intent intent,
                            int flags,
                            MenuItem[] outSpecificItems)
Description copied from interface: Menu
Add a group of menu items corresponding to actions that can be performed for a particular Intent. The Intent is most often configured with a null action, the data that the current activity is working with, and includes either the Intent.CATEGORY_ALTERNATIVE or Intent.CATEGORY_SELECTED_ALTERNATIVE to find activities that have said they would like to be included as optional action. You can, however, use any Intent you want.

See PackageManager.queryIntentActivityOptions(android.content.ComponentName, android.content.Intent[], android.content.Intent, int) for more * details on the caller, specifics, and intent arguments. The list returned by that function is used to populate the resulting menu items.

All of the menu items of possible options for the intent will be added with the given group and id. You can use the group to control ordering of the items in relation to other items in the menu. Normally this function will automatically remove any existing items in the menu in the same group and place a divider above and below the added items; this behavior can be modified with the flags parameter. For each of the generated items MenuItem.setIntent(android.content.Intent) is called to associate the appropriate Intent with the item; this means the activity will automatically be started for you without having to do anything else.

Specified by:
addIntentOptions in interface Menu
Parameters:
groupId - The group identifier that the items should be part of. This can also be used to define groups of items for batch state changes. Normally use Menu.NONE if the items should not be in a group.
itemId - Unique item ID. Use Menu.NONE if you do not need a unique ID.
order - The order for the items. Use Menu.NONE if you do not care about the order. See MenuItem.getOrder().
caller - The current activity component name as defined by queryIntentActivityOptions().
specifics - Specific items to place first as defined by queryIntentActivityOptions().
intent - Intent describing the kinds of items to populate in the list as defined by queryIntentActivityOptions().
flags - Additional options controlling how the items are added.
outSpecificItems - Optional array in which to place the menu items that were generated for each of the specifics that were requested. Entries may be null if no activity was found for that specific action.
Returns:
The number of menu items that were added.
See Also:
Menu.FLAG_APPEND_TO_GROUP, MenuItem.setIntent(android.content.Intent), PackageManager.queryIntentActivityOptions(android.content.ComponentName, android.content.Intent[], android.content.Intent, int)

addSubMenu

public SubMenu addSubMenu(CharSequence title)
Description copied from interface: Menu
Add a new sub-menu to the menu. This item displays the given title for its label. To modify other attributes on the submenu's menu item, use SubMenu.getItem().

Specified by:
addSubMenu in interface Menu
Parameters:
title - The text to display for the item.
Returns:
The newly added sub-menu

addSubMenu

public SubMenu addSubMenu(int titleRes)
Description copied from interface: Menu
Add a new sub-menu to the menu. This item displays the given title for its label. To modify other attributes on the submenu's menu item, use SubMenu.getItem().

Specified by:
addSubMenu in interface Menu
Parameters:
titleRes - Resource identifier of title string.
Returns:
The newly added sub-menu

addSubMenu

public SubMenu addSubMenu(int groupId,
                          int itemId,
                          int order,
                          CharSequence title)
Description copied from interface: Menu
Add a new sub-menu to the menu. This item displays the given title for its label. To modify other attributes on the submenu's menu item, use SubMenu.getItem().

Note that you can only have one level of sub-menus, i.e. you cannnot add a subMenu to a subMenu: An UnsupportedOperationException will be thrown if you try.

Specified by:
addSubMenu in interface Menu
Parameters:
groupId - The group identifier that this item should be part of. This can also be used to define groups of items for batch state changes. Normally use Menu.NONE if an item should not be in a group.
itemId - Unique item ID. Use Menu.NONE if you do not need a unique ID.
order - The order for the item. Use Menu.NONE if you do not care about the order. See MenuItem.getOrder().
title - The text to display for the item.
Returns:
The newly added sub-menu

addSubMenu

public SubMenu addSubMenu(int groupId,
                          int itemId,
                          int order,
                          int titleRes)
Description copied from interface: Menu
Variation on Menu.addSubMenu(int, int, int, CharSequence) that takes a string resource identifier for the title instead of the string itself.

Specified by:
addSubMenu in interface Menu
Parameters:
groupId - The group identifier that this item should be part of. This can also be used to define groups of items for batch state changes. Normally use Menu.NONE if an item should not be in a group.
itemId - Unique item ID. Use Menu.NONE if you do not need a unique ID.
order - The order for the item. Use Menu.NONE if you do not care about the order. See MenuItem.getOrder().
titleRes - Resource identifier of title string.
Returns:
The newly added sub-menu

clear

public void clear()
Description copied from interface: Menu
Remove all existing items from the menu, leaving it empty as if it had just been created.

Specified by:
clear in interface Menu

close

public void close()
Description copied from interface: Menu
Closes the menu, if open.

Specified by:
close in interface Menu

findItem

public MenuItem findItem(int id)
Description copied from interface: Menu
Return the menu item with a particular identifier.

Specified by:
findItem in interface Menu
Parameters:
id - The identifier to find.
Returns:
The menu item object, or null if there is no item with this identifier.

getItem

public MenuItem getItem(int index)
Description copied from interface: Menu
Gets the menu item at the given index.

Specified by:
getItem in interface Menu
Parameters:
index - The index of the menu item to return.
Returns:
The menu item.

hasVisibleItems

public boolean hasVisibleItems()
Description copied from interface: Menu
Return whether the menu currently has item items that are visible.

Specified by:
hasVisibleItems in interface Menu
Returns:
True if there is one or more item visible, else false.

isShortcutKey

public boolean isShortcutKey(int keyCode,
                             android.view.KeyEvent event)
Description copied from interface: Menu
Is a keypress one of the defined shortcut keys for this window.

Specified by:
isShortcutKey in interface Menu
Parameters:
keyCode - the key code from KeyEvent to check.
event - the KeyEvent to use to help check.

performIdentifierAction

public boolean performIdentifierAction(int id,
                                       int flags)
Description copied from interface: Menu
Execute the menu item action associated with the given menu identifier.

Specified by:
performIdentifierAction in interface Menu
Parameters:
id - Identifier associated with the menu item.
flags - Additional option flags or 0.
Returns:
If the given identifier exists and is shown, returns true; else returns false.
See Also:
Menu.FLAG_PERFORM_NO_CLOSE

performShortcut

public boolean performShortcut(int keyCode,
                               android.view.KeyEvent event,
                               int flags)
Description copied from interface: Menu
Execute the menu item action associated with the given shortcut character.

Specified by:
performShortcut in interface Menu
Parameters:
keyCode - The keycode of the shortcut key.
event - Key event message.
flags - Additional option flags or 0.
Returns:
If the given shortcut exists and is shown, returns true; else returns false.
See Also:
Menu.FLAG_PERFORM_NO_CLOSE

removeGroup

public void removeGroup(int groupId)
Description copied from interface: Menu
Remove all items in the given group.

Specified by:
removeGroup in interface Menu
Parameters:
groupId - The group to be removed. If there are no items in this group, nothing happens.

removeItem

public void removeItem(int id)
Description copied from interface: Menu
Remove the item with the given identifier.

Specified by:
removeItem in interface Menu
Parameters:
id - The item to be removed. If there is no item with this identifier, nothing happens.

setGroupCheckable

public void setGroupCheckable(int group,
                              boolean checkable,
                              boolean exclusive)
Description copied from interface: Menu
Control whether a particular group of items can show a check mark. This is similar to calling MenuItem.setCheckable(boolean) on all of the menu items with the given group identifier, but in addition you can control whether this group contains a mutually-exclusive set items. This should be called after the items of the group have been added to the menu.

Specified by:
setGroupCheckable in interface Menu
Parameters:
group - The group of items to operate on.
checkable - Set to true to allow a check mark, false to disallow. The default is false.
exclusive - If set to true, only one item in this group can be checked at a time; checking an item will automatically uncheck all others in the group. If set to false, each item can be checked independently of the others.
See Also:
MenuItem.setCheckable(boolean), MenuItem.setChecked(boolean)

setGroupEnabled

public void setGroupEnabled(int group,
                            boolean enabled)
Description copied from interface: Menu
Enable or disable all menu items that are in the given group.

Specified by:
setGroupEnabled in interface Menu
Parameters:
group - The group of items to operate on.
enabled - If true the items will be enabled, else they will be disabled.
See Also:
MenuItem.setEnabled(boolean)

setGroupVisible

public void setGroupVisible(int group,
                            boolean visible)
Description copied from interface: Menu
Show or hide all menu items that are in the given group.

Specified by:
setGroupVisible in interface Menu
Parameters:
group - The group of items to operate on.
visible - If true the items are visible, else they are hidden.
See Also:
MenuItem.setVisible(boolean)

setQwertyMode

public void setQwertyMode(boolean isQwerty)
Description copied from interface: Menu
Control whether the menu should be running in qwerty mode (alphabetic shortcuts) or 12-key mode (numeric shortcuts).

Specified by:
setQwertyMode in interface Menu
Parameters:
isQwerty - If true the menu will use alphabetic shortcuts; else it will use numeric shortcuts.

size

public int size()
Description copied from interface: Menu
Get the number of items in the menu. Note that this will change any times items are added or removed from the menu.

Specified by:
size in interface Menu
Returns:
The item count.


Copyright © 2012-2013. All Rights Reserved.