In Series 40 and S60 devices, Command
s
are mapped directly to a softkey or placed in an expandable menu (the common
'Options' menu) according to Nokia user interface guidelines. It is essential
to use logically proper and correct types for Command
s.
If right types for the Command
s are used, the Command
mapping
works as expected.
The placement of Command
s in the UI is decided
by assigning them a Command
type and a priority value.
The order of Command
s of the same type is handled with
the priority value. A Command
that has been assigned
the smaller priority value is placed before the other Command
s
of the same type in a menu. When Command
s are presented
in Options
menu, the Command
s mapped
to the menu are shown in the following order based on their type:
Command
s can be divided into four categories:
Displayable
Command
s (normal Command
s)
are associated with a Displayable
object. These Command
s
have a property called ‘type’ that affects how they are treated in S60 implementation.
Item
Command
s are
associated with individual Form
Item
s. Item
Command
s
are used to display context sensitive menus and are available only when the
corresponding Item
has focus.
Default Command
in a Form
Item
aims
to make one Command
easy to access. Default Command
s
are associated with a Form
Item
object
with setDefaultCommand()
method. Default Command
is
invoked directly with the Selection key.
Device-provided operations are Command
s
provided by the implementation for certain type of components without application
programmer’s intervention. The Command
s are used to provide
access to device functionality otherwise not accessible.
Commonly, every Command
is associated with a Displayable
or a Form
Item
. Command
s can generally be
applied to any screen, including Alert
s.
As the Command
s handle the main functionality and
navigation in the MIDlet, the developer MUST always add an EXIT
Command
in
order for the application to allow mobile device users exit the application
gracefully. If the application has more than one display, or has other components,
the required navigation Command
s to these items must
be added as well.
Command
s mapped to softkeys conform to the following
rules:
Softkey 1 (left softkey)
Multiple Command
s can be mapped to the left softkey.
If there are multiple Command
s, an Options
label
is presented on the left softkey and selecting it opens a menu of commands.
If there is only a single 'positive' Command
(OK,
ITEM, SCREEN,
or HELP
), it is presented directly
on the left softkey. If there is more than one 'negative' Command
,
they are presented in the Options
menu that is accessed
with the left softkey.
Softkey 2 (right softkey)
There can only be one 'negative' Command
(STOP,
CANCEL, BACK,
or EXIT)
mapped to the right
softkey, and the Command
mapped there is directly invoked
by the softkey press. If there are multiple 'negative' Command
s,
the one that has the highest priority value is mapped to the right softkey
and the rest are placed in the menu of commands under the left softkey.
Selection key (formerly middle softkey)
In Series 40, only a single context
sensitive Command
(OK, ITEM
) is
mapped to the selection key. In S60, multiple Command
s
can be mapped to the Selection key. If there's only a single Command
,
it is shown directly in softkey, otherwise the Command
s
are visible in a context sensitive menu that can be opened with the Selection
key.
Note: Some UI components override this rule and place a component specific
operation directly to the Selection key. For example, POPUP ChoiceGroup
has Open
operation
in the Selection key.
Enter key (on QWERTY keyboard)
Has the same effect as the Selection key, unless it is bound to a displayable specific operation.
The behavior that the command activates is not encapsulated in the specific
object. This means that when the mobile device user invokes a Command
,
the actual functionality is not executed automatically by the implementation.
Instead, the action is defined in a CommandListener
interface.
This example illustrates how Command
s are mapped
to softkeys. Command
s in this example are used to insert
a short string to a TextBox
or to exit the MIDlet. Note
how the priority setting affects the order of Command
s
in the left softkey and how the EXIT Command
is by default
placed under the right softkey.
Source code for the example:
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class ExampleCommand extends MIDlet implements CommandListener { private Display display; private TextBox textbox; private Command apple; private Command orange; private Command pear; private Command lemon; private Command exit; private Command clear; public ExampleCommand() { display = Display.getDisplay(this); apple = new Command("Apple", Command.SCREEN, 1); orange = new Command("Orange", Command.SCREEN, 4); pear = new Command("Pear", Command.SCREEN, 2); lemon = new Command("Lemon", Command.SCREEN, 3); exit = new Command("Exit", Command.EXIT, 1); clear = new Command("Clear", Command.SCREEN, 5); textbox = new TextBox("Today's menu:", "The command you select will be presented here", 100, TextField.ANY); textbox.addCommand(exit); textbox.addCommand(apple); textbox.addCommand(orange); textbox.addCommand(pear); textbox.addCommand(lemon); textbox.addCommand(clear); textbox.setCommandListener(this); } public void startApp() { display.setCurrent(textbox); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command command, Displayable displayable) { if (command == apple) { textbox.setString(apple.getLabel() + " selected"); } else if (command == orange) { textbox.setString(orange.getLabel() + " selected"); } else if (command == lemon) { textbox.setString(lemon.getLabel() + " selected"); } else if (command == pear) { textbox.setString(pear.getLabel() + " selected"); } else if (command == clear) { textbox.setString(""); } else if (command == exit) { destroyApp(false); notifyDestroyed(); } } }
For more information about S60-specific Command
features,
see Command implementation
notes.