|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdanger.app.Listener
danger.ui.View
danger.ui.Container
danger.ui.Control
danger.ui.BaseMenu
public abstract class BaseMenu
Base functionality for menu controls.
NOTE: This class is not safe to use from more than one thread simultaneously. Use explicit synchronization for multi-threaded access.
| Field Summary | |
|---|---|
static int |
WITH_KEY_HELD
Flag that can be passed to enterMenu(boolean). |
static int |
WITH_WIDGET_HELD
Flag that can be passed to enterMenu(boolean). |
| Fields inherited from class danger.ui.Control |
|---|
mValue |
| Constructor Summary | |
|---|---|
BaseMenu()
Construct an instance with "" (the empty string) for
the title and set not to show the title. |
|
BaseMenu(String title)
Construct an instance with the given title but set not to show the title. |
|
BaseMenu(String title,
boolean showTitle)
Construct an instance with the given title and given setting for whether or not the title should be displayed. |
|
| Method Summary | |
|---|---|
void |
addDivider()
Add a divider to this menu. |
void |
addDivider(int id)
Add a divider with the given ID to this menu. |
void |
addDividerAtPosition(int position)
Insert a divider into this menu at the given position. |
void |
addFromResource(ResourceDatabase database,
int id)
Set up this menu based on the resource with the given ID from the given resource database. |
void |
addFromResource(ResourceDatabase database,
int id,
Listener listener)
Set up this menu based on the resource with the given ID from the given resource database, and set all menu items to use the given listener. |
void |
addFromResource(ResourceDatabase database,
int id,
Listener listener,
Window textEditBaseWindow)
Set up this menu based on the resource with the given ID from the given resource database. |
MenuItem |
addItem(CharSequence inTitle)
Add a menu item to this menu. |
MenuItem |
addItem(CharSequence title,
int eventType)
Add a menu item to this menu. |
MenuItem |
addItem(CharSequence title,
int eventType,
int eventWhat,
int eventData,
Object eventArg,
Listener listener,
int itemID)
Add a menu item to this menu. |
MenuItem |
addItem(CharSequence title,
int eventType,
int eventData,
Object eventArg,
Listener listener)
Add a menu item to this menu. |
MenuItem |
addItem(CharSequence title,
int eventType,
int eventData,
Object eventArg,
Listener listener,
int itemID)
|
MenuItem |
addItem(MenuItem m)
Add the given menu item to this menu. |
MenuItem |
addItem(MenuItem m,
int id)
Add the given menu item to this menu with the given ID. |
MenuItem |
addItem(String inTitle)
Add a menu item to this menu. |
MenuItem |
addItem(String title,
int eventType)
Add a menu item to this menu. |
MenuItem |
addItem(String title,
int eventType,
int eventWhat,
int eventData,
Object eventArg,
Listener listener,
int itemID)
Add a menu item to this menu. |
MenuItem |
addItem(String title,
int eventType,
int eventData,
Object eventArg,
Listener listener)
Add a menu item to this menu. |
MenuItem |
addItem(String title,
int eventType,
int eventData,
Object eventArg,
Listener listener,
int itemID)
|
MenuItem |
addItemAtPosition(MenuItem m,
int position)
Insert the given menu item into this menu at the given position. |
void |
addItemFromResource(ResourceDatabase database,
int id,
int menuItemID,
int eventData,
Object eventArg,
Listener listener)
Add an item to this menu based on the resource with the given ID from the given resource database. |
void |
addItemFromResource(ResourceDatabase database,
int id,
int menuItemID,
Listener listener)
Add an item to this menu based on the resource with the given ID from the given resource database. |
void |
addItems(MenuItem[] items)
Add the elements of the given array of menu items to this menu, in order. |
MenuItem |
addLinkOptionItems(Window inBaseWindow)
Add the menu items needed to support link option functionality. |
MenuItem |
addLinkOptionItems(Window inBaseWindow,
int id)
Add the menu items needed to support link option functionality. |
MenuItem |
addTextEditItems(Window inBaseWindow)
Add the menu items needed to support text edit functionality. |
MenuItem |
addTextEditItems(Window inBaseWindow,
int id)
Add the menu items needed to support text edit functionality. |
void |
collateMenuItems()
Sort the menu items in this menu by title according to locale rules. |
void |
enableItemWithID(int id,
boolean inEnable)
Enables or disables the menu item with the given ID, if such a menu item is in fact in the menu. |
void |
enterMenu()
Indicate the the menu has been entered. |
void |
enterMenu(boolean springLoaded)
Indicate that the menu has been entered, also indicating whether or not it is spring-loaded. |
void |
enterMenu(int flags)
Indicate that the menu has been entered, and specify whether a widget and/or key is held down at this moment. |
void |
enterSubmenuForShortcut(char shortcut)
Indicate the the submenu for the given shortcut has been entered. |
void |
exitMenu(boolean inKeepSelection)
Indicate the the menu has been exited. |
boolean |
getAutoHideIfIdle()
Get the flag indicating whether the menu should auto-hide after a period of inactivity. |
Bitmap |
getCheckedIcon()
Get the icon to be used as a checkmark next to items. |
boolean |
getEllipsizeTruncatedMenuText()
Get the flag indicating whether an ellipsis should be used when truncation of menu item text is required. |
int |
getIDOfItem(MenuItem item)
Get the ID of the given item in this menu. |
MenuItem |
getItem(int n)
Get the nth menu item in the menu. |
MenuItem |
getItemFromShortcut(char shortcut)
Find and return a menu item that has the given shortcut character. |
MenuItem |
getItemWithID(int id)
Get the menu item with the given ID. |
MenuItem |
getItemWithIDOrNull(int id)
Get the menu item with the given ID or return null if
there is no item with the given ID in the menu. |
Bitmap |
getMarkedIcon()
Get the icon to be used as a generic mark next to items. |
Window |
getOwnerWindow()
Get the Window that "owns" this instance, that is, the
Window underneath that caused this menu to appear. |
MenuItem |
getSelectedItem()
Get the currently selected item in this menu. |
int |
getSelectedItemID()
Get the ID of the currently selected item in this menu. |
boolean |
getShowTitle()
Get the flag indicating whether this menu's title should appear. |
boolean |
hasVisibleSubmenu()
Return whether or not this menu has a currently-visible submenu. |
void |
hideItemWithID(int id)
Hides the menu item with the given ID, if such a menu item is in fact in the menu. |
int |
indexOfItem(MenuItem item)
Get the index of the given menu item in this menu, compared with ==. |
int |
indexOfItem(String title)
Get the index of a menu item with the given title, compared with String.equals(java.lang.Object). |
boolean |
isDefaultSelectionFirstMenuItem()
Get the flag indicating whether the menu selection should default to the first item in the menu. |
boolean |
isShortcutForSubmenu(char shortcut)
Determine whether the given shortcut is for a submenu. |
boolean |
isSubmenu()
Get the flag indicating whether this menu is in fact a submenu in a hierarchy. |
int |
itemCount()
Return the number of items in this menu. |
boolean |
matchAndDispatchNonMenuShortcut(char shortcut,
Event event)
|
boolean |
matchAndDispatchShortcut(char shortcut,
Event event)
Match the given character as a menu shortcut. |
protected void |
onStyleChanged(int attribute)
This method is called when the specified attribute of this view's style has been modified. |
boolean |
ownerWindowIsActive()
Return whether or not the owner window of this menu is currently active. |
void |
removeAllItems()
Remove all items from the menu. |
void |
removeItem(int index)
Remove the nth item from the menu. |
void |
removeItemWithID(int id)
Remove the menu item with the given ID, if such a menu item is in fact in the menu. |
void |
sendSelectionChangedEvent()
Send an event indicating that the selection of this instance has changed. |
void |
setAutoHideIfIdle(boolean flag)
Set or clear the flag indicating whether this menu should auto-hide after a period of inactivity. |
void |
setCheckedIcon(Bitmap inIcon)
Set the icon to be used as a checkmark next to items. |
void |
setCheckedIcon(Bitmap inIcon,
boolean invert)
Set the icon to be used as a checkmark next to items. |
void |
setDefaultSelectionToFirstMenuItem(boolean flag)
Set or clear the flag indicating whether the menu selection should default to the first item in the menu. |
void |
setEllipsizeTruncatedMenuText(boolean flag)
Set or clear the flag indicating whether an ellipsis should be used when truncation of menu item text is required. |
void |
setListenerForAllItems(Listener listener)
Set the listener for all menu items to the one given. |
void |
setMarkedIcon(Bitmap inIcon)
Set the icon to be used as a generic mark next to items. |
void |
setMarkedIcon(Bitmap inIcon,
boolean invert)
Set the icon to be used as a generic mark next to items. |
void |
setMaxItemID(int id)
Set the maximum ID that items with IDs that are added to this menu may have. |
void |
setMaxToolTipLines(int maxLines)
Set the maximum number of lines to show in a tool tip. |
void |
setSelectionChangedListener(Listener listener,
int event)
Set the listener for selection-changed events, as well as the event type to use for such events. |
void |
setShowTitle(boolean flag)
Set or clear the flag indicating whether this menu's title should appear. |
void |
setSubmenu(boolean flag)
Set or clear the flag indicating whether this menu is in fact a submenu in a hierarchy. |
void |
showItemWithID(int id)
Shows the menu item with the given ID, if such a menu item is in fact in the menu. |
void |
showItemWithID(int id,
boolean inShow)
Shows or hides the menu item with the given ID, if such a menu item is in fact in the menu. |
void |
sortMenuItems()
Sort the menu items in this menu by title, case-sensitively. |
void |
uncheckAll()
Uncheck all the items in the menu. |
void |
unmarkAll()
Unmark all the items in the menu. |
MenuItem |
updateLinkOptionItems(Window inBaseWindow)
Update the link option items in this menu, according to the state of the given target window. |
MenuItem |
updateTextEditItems(Window inBaseWindow)
Update the text edit items in this menu, according to the state of the given target window. |
| Methods inherited from class danger.ui.Control |
|---|
drawFocusBox, drawIdleBox, drawIdleBox, getBaseline, getEvent, getEventListener, getEventType, getHasBorder, getMaxToolTipLines, getTitle, getTitleSequence, getToolTip, getValue, hasToolTip, loseFocus, onSetHasBorder, onSetTitle, sendEvent, setEvent, setEvent, setEvent, setEvent, setEvent, setEventArg, setEventListener, setHasBorder, setTitle, setTitle, setToolTip, setValue, showToolTip, takeFocus |
| Methods inherited from class danger.app.Listener |
|---|
cancelEvents, childEventPump, childEventPumpDone, eventProblem, isDispatchingThread, sendEvent, sendEvent, sendEvent, sendEvent, sendEvent, sendLowPriorityEvent |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int WITH_WIDGET_HELD
enterMenu(boolean). Specifies that
the menu was entered while a widget was being held down.
public static final int WITH_KEY_HELD
enterMenu(boolean). Specifies that
the menu was entered while a key was being held down.
| Constructor Detail |
|---|
public BaseMenu()
"" (the empty string) for
the title and set not to show the title.
public BaseMenu(String title)
title - null-ok; the title; if passed as null, it
is interpreted as "" (that is, the empty string)
public BaseMenu(String title,
boolean showTitle)
title - null-ok; the title; if passed as null, it
is interpreted as "" (that is, the empty string)showTitle - whether or not to show the title| Method Detail |
|---|
protected void onStyleChanged(int attribute)
View
onStyleChanged in class Viewpublic final void setMaxItemID(int id)
id - > 0; the maximum idpublic final int itemCount()
public final void addFromResource(ResourceDatabase database,
int id)
database - non-null; the resource database to useid - the ID of the menu
public final void addFromResource(ResourceDatabase database,
int id,
Listener listener)
database - non-null; the resource database to useid - the ID of the menulistener - null-ok; the listener that the menu items should have
public final void addFromResource(ResourceDatabase database,
int id,
Listener listener,
Window textEditBaseWindow)
database - non-null; the resource database to useid - the ID of the menulistener - null-ok; the listener that the menu items should have,
or null if they should initially have no listenertextEditBaseWindow - null-ok; the window that text edit items
should target or null if they should initially have no
target
public final void addItemFromResource(ResourceDatabase database,
int id,
int menuItemID,
Listener listener)
database - non-null; the resource database to useid - the ID of the menu item in the resource databasemenuItemID - the ID of the menu item in the menulistener - null-ok; the listener that the menu item should have,
or null if it should initially have no listener
public final void addItemFromResource(ResourceDatabase database,
int id,
int menuItemID,
int eventData,
Object eventArg,
Listener listener)
database - non-null; the resource database to useid - the ID of the menu item in the resource databasemenuItemID - the ID of the menu item in the menueventData - the event data for the event triggered by the itemeventArg - null-ok; the event argument for the event triggered
by the itemlistener - null-ok; the listener that the menu item should have,
or null if it should initially have no listenerpublic final void addDivider(int id)
id - >= 0; the ID, or 0 to indicate that the divider
should have no IDpublic final void addDivider()
public final void addDividerAtPosition(int position)
position - >= 0 && <= itemCount(); the position
to insert at
IndexOutOfBoundsException - thrown if position is invalid
public final MenuItem addItem(String title,
int eventType,
int eventData,
Object eventArg,
Listener listener,
int itemID)
public final MenuItem addItem(CharSequence title,
int eventType,
int eventData,
Object eventArg,
Listener listener,
int itemID)
public final MenuItem addItem(String title,
int eventType,
int eventWhat,
int eventData,
Object eventArg,
Listener listener,
int itemID)
title - null-ok; the title for the item; if passed as
null, interpreted to mean "" (that is, the
empty string)eventType - the event type for the event triggered by the itemeventWhat - the Event.what parameter for the event triggered by the itemeventData - the event data for the event triggered by the itemeventArg - null-ok; the event argument for the event triggered
by the itemlistener - null-ok; the listener that the menu item should have,
or null if it should initially have no listeneritemID - >= 0; the ID for the item or 0 to indicate
that it should have no ID
MenuItem that was added
public final MenuItem addItem(CharSequence title,
int eventType,
int eventWhat,
int eventData,
Object eventArg,
Listener listener,
int itemID)
title - null-ok; the title for the item; if passed as
null, interpreted to mean "" (that is, the
empty string)eventType - the event type for the event triggered by the itemeventWhat - the Event.what parameter for the event triggered by the itemeventData - the event data for the event triggered by the itemeventArg - null-ok; the event argument for the event triggered
by the itemlistener - null-ok; the listener that the menu item should have,
or null if it should initially have no listeneritemID - >= 0; the ID for the item or 0 to indicate
that it should have no ID
MenuItem that was added
public final MenuItem addItem(String title,
int eventType,
int eventData,
Object eventArg,
Listener listener)
title - null-ok; the title for the item; if passed as
null, interpreted to mean "" (that is, the
empty string)eventType - the event type for the event triggered by the itemeventData - the event data for the event triggered by the itemeventArg - null-ok; the event argument for the event triggered
by the itemlistener - null-ok; the listener that the menu item should have,
or null if it should initially have no listener
MenuItem that was added
public final MenuItem addItem(CharSequence title,
int eventType,
int eventData,
Object eventArg,
Listener listener)
title - null-ok; the title for the item; if passed as
null, interpreted to mean "" (that is, the
empty string)eventType - the event type for the event triggered by the itemeventData - the event data for the event triggered by the itemeventArg - null-ok; the event argument for the event triggered
by the itemlistener - null-ok; the listener that the menu item should have,
or null if it should initially have no listener
MenuItem that was added
public final MenuItem addItem(String title,
int eventType)
0
event data, null event argument, no (null)
listener, and no ID.
title - null-ok; the title for the item; if passed as
null, interpreted to mean "" (that is, the
empty string)eventType - the event type for the event triggered by the item
MenuItem that was added
public final MenuItem addItem(CharSequence title,
int eventType)
0
event data, null event argument, no (null)
listener, and no ID.
title - null-ok; the title for the item; if passed as
null, interpreted to mean "" (that is, the
empty string)eventType - the event type for the event triggered by the item
MenuItem that was addedpublic final MenuItem addItem(String inTitle)
0
event type and data, null event argument, no
(null) listener, and no ID.
inTitle - null-ok; the title for the item; if passed as
null, interpreted to mean "" (that is, the
empty string)
MenuItem that was addedpublic final MenuItem addItem(CharSequence inTitle)
0
event type and data, null event argument, no
(null) listener, and no ID.
inTitle - null-ok; the title for the item; if passed as
null, interpreted to mean "" (that is, the
empty string)
MenuItem that was addedpublic final MenuItem addItem(MenuItem m)
m - non-null; the item to add
public final MenuItem addItem(MenuItem m,
int id)
m - non-null; the item to addid - >= 0; the ID, or 0 to indicate that the divider
should have no ID
public final MenuItem addItemAtPosition(MenuItem m,
int position)
m - non-null; the item to insertposition - >= 0 && <= itemCount(); the position
to insert at
IndexOutOfBoundsException - thrown if position is invalidpublic final void addItems(MenuItem[] items)
items - non-null and with all non-null elements; array of items
to add
NullPointerException - thrown if items or any
element of items is null; in the latter case,
the menu items up to the offending null will have been
addedpublic final void hideItemWithID(int id)
id - the ID of the menu item to hidepublic final void showItemWithID(int id)
id - the ID of the menu item to hide
public final void showItemWithID(int id,
boolean inShow)
id - the ID of the menu iteminShow - whether to show or hide the item
public final void enableItemWithID(int id,
boolean inEnable)
id - the ID of the menu iteminEnable - whether to enable or disable the itempublic final void removeItem(int index)
nth item from the menu. It is an error to
attempt to remove an item that doesn't exist.
index - >= 0 && < itemCount(); which item to remove
IndexOutOfBoundsException - thrown if n is
out of rangepublic final void removeItemWithID(int id)
id - the ID of the menu item to removepublic final void removeAllItems()
public final void enterMenu(boolean springLoaded)
enterMenu().
Spring-loaded menus are entered as a result of a "click and hold"
gestures. Because the menu springs to life once the control is no
longer held, we need to know not to dispatch MenuItem
events on the WidgetUp event immediately following the
WidgetHeld event.
springLoaded - whether or not the menu was entered in a
spring-loaded fashionpublic final void enterMenu(int flags)
enterMenu().
flags - zero or more of
WITH_WIDGET_HELD and
WITH_KEY_HELD.public void enterMenu()
public void enterSubmenuForShortcut(char shortcut)
public void exitMenu(boolean inKeepSelection)
public final MenuItem getItemWithID(int id)
id - the ID of the item in question
IllegalArgumentException - thrown if there is no menu item with
the given IDpublic final MenuItem getItemWithIDOrNull(int id)
null if
there is no item with the given ID in the menu.
id - the ID of the item in question
null
if there is no menu item with the given IDpublic final MenuItem getItem(int n)
nth menu item in the menu.
n - >= 0 && < itemCount(); which item to get
nth menu item
IndexOutOfBoundsException - thrown if n is
out of rangepublic final void uncheckAll()
MenuItem.uncheck() on each.
public final void setCheckedIcon(Bitmap inIcon)
inIcon - the icon to use
public final void setCheckedIcon(Bitmap inIcon,
boolean invert)
inIcon - the icon to useinvert - if true, the icon is inverted when displayed
in a selected menu item; if false, the icon is only inverted
if inIcon is grayscale.public final Bitmap getCheckedIcon()
public final void unmarkAll()
MenuItem.unmark() on each.
public final void setMarkedIcon(Bitmap inIcon)
inIcon - the icon to use
public final void setMarkedIcon(Bitmap inIcon,
boolean invert)
inIcon - the icon to useinvert - if true, the icon is inverted when displayed
in a selected menu item; if false, the icon is only inverted
if inIcon is grayscale.public final Bitmap getMarkedIcon()
public final void setShowTitle(boolean flag)
flag - whether (true) or not (false)
the title should appearpublic final boolean getShowTitle()
true) or not (false)
the title should appearpublic final void setDefaultSelectionToFirstMenuItem(boolean flag)
flag - whether (true) or not (false)
the default should be the first menu itempublic final boolean isDefaultSelectionFirstMenuItem()
true) or not (false)
the default should be the first menu itempublic final void setAutoHideIfIdle(boolean flag)
flag - whether (true) or not (false)
the menu should auto-hidepublic final boolean getAutoHideIfIdle()
true) or not (false)
the menu should auto-hidepublic final void setSubmenu(boolean flag)
flag - whether (true) or not (false)
this instance is a submenupublic final boolean isSubmenu()
true) or not (false)
this instance is a submenupublic final void setEllipsizeTruncatedMenuText(boolean flag)
flag - whether (true) or not (false)
to ellipsize truncated menu textpublic final boolean getEllipsizeTruncatedMenuText()
true) or not (false)
to ellipsize truncated menu text
public boolean matchAndDispatchShortcut(char shortcut,
Event event)
true. Otherwise,
do nothing and return false. The default implementation
does nothing but return false. Subclasses should override
it as appropriate.
shortcut - the shortcut characterevent - the event associated with the key press
true) or not (false) the
shortcut was matched and handled
public boolean matchAndDispatchNonMenuShortcut(char shortcut,
Event event)
public boolean isShortcutForSubmenu(char shortcut)
shortcut - the shortcut character
true) or not (false) the
shortcut is for a submenu.public final void setListenerForAllItems(Listener listener)
MenuItem.setListener(danger.app.Listener) on
each.
listener - null-ok; the listener to set
public final void setSelectionChangedListener(Listener listener,
int event)
sendSelectionChangedEvent().
listener - null-ok; the listener; if null, then
calls to sendSelectionChangedEvent() become a no-opevent - the event type for selection-changed eventspublic final void sendSelectionChangedEvent()
setSelectionChangedListener(danger.app.Listener, int), and has the type also
specified in that call. The event subtype is the current value
(that is, what would be returned by Control.getValue()), the
event data is 0, and the event argument is the
currently selected menu item (that is, what would be returned by
getSelectedItem().
This call does nothing if there is no selection-changed
listener (because setSelectionChangedListener(danger.app.Listener, int) was never
called or because it was called and passed null for
the listener argument).
public Window getOwnerWindow()
Window that "owns" this instance, that is, the
Window underneath that caused this menu to appear.
By default this returns the same thing as View.getWindow(), but
subclasses may override this to do something more appropriate.
null if this
instance does not seem to have an ownerpublic final boolean ownerWindowIsActive()
true if one of the following
conditions holds: (a) the owner window is null;
(b) the owner window is an instance of DialogWindow; or
(c) the owner window is the frontmost application window on the
device.
public final void sortMenuItems()
public final void collateMenuItems()
public final boolean hasVisibleSubmenu()
MenuItem.submenuIsVisible() on each, returning true
as soon as that call returns true. If that never happens,
it returns false.
public final MenuItem getSelectedItem()
null
if there is no selectionpublic final int getSelectedItemID()
getIDOfItem(getSelectedItem()).
public final MenuItem addLinkOptionItems(Window inBaseWindow)
inBaseWindow - non-null; the target window
public final MenuItem addLinkOptionItems(Window inBaseWindow,
int id)
inBaseWindow - non-null; the target windowid - the id to assign to the menu item containing the submenu
public final MenuItem updateLinkOptionItems(Window inBaseWindow)
ScreenWindow.adjustActionMenuState().
inBaseWindow - non-null; the target window
null if this
menu doesn't actually have any text edit items in it