In Series 40 and Symbian 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:
Native software
UI Component operations (for example internal selection element in ChoiceGroup
.)
Default Item
Command
Item Command
s
STOP
OK
CANCEL
ITEM
SCREEN
HELP
BACK
EXIT
Automatically
added ‘View’ in ChoiceGroup
s and List
s which are truncated due to text wrap being off.
Automatically
added ‘am’ and ‘pm’ in time entry DateField
s when the clock is set to 12 hour mode.
In cases where the priority of similar Command
types is the same, the ordering is based on the order the Command
s were programmatically added to the Displayable
.
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 Symbian 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.
Since Commands
control the basic UI navigation
functions of a MIDlet, you must always add an EXIT Command
to the MIDlet, so that the user can exit the MIDlet gracefully.
If the MIDlet UI uses one or more views in addition to the main view,
consider adding an EXIT Command
to all the views.
You must also add the necessary backstepping Command
(either CANCEL or BACK) to each additional view, so that the user
can always return to the previous view in the UI.
If a CommandListener
method does not return
or is not delayed, the system may be blocked. Therefore, the CommandListener
method should return immediately.
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 Symbian, 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.
Application specified Command
labels are used:
as a label in the softkey to which the Command
was mapped (in case where only one Command
is
mapped to a specific softkey) or
as a label in the Options or context sensitive menu item (in
case where more than one Command
is mapped to
a softkey) or
In S60 3rd Edition FP 2 onwards, the Selection key has a label describing the function attached to it:
If the Selection key executes a Command
, the short label of the Command
is shown as
the Selection key label.
If the Selection key opens a context sensitive menu, a menu icon is shown as the Selection key label.
If the Selection key does the same operation as left softkey, a platform provided dot icon is shown as the Selection key label.
The Selection key labeling functionality is available only in the portrait mode. The Selection key functions normally both in portrait and in landscape modes, but in landscape mode the label cannot be shown due to space restrictions.
If a Command
is added or removed after the Command
s for
a displayable have been presented to the user, all the Command
s are mapped again based on the rules presented in the previous sections.
This may update the softkeys and Command
list
items even when they are visible.
Form, addition / removal
of Command
s may be performed by both the implementation
and the MIDlet, as the user traverses different Items, since each Item
may have its own specific Command
s. This may result in scenarios where sometimes a particular Command
is displayed on the left softkey, while at other
times "Options" is displayed.
If another Displayable
appears over the Options
list while it is open
(by a system application or by the MIDlet itself), then upon that Displayable
’s removal the user will not be returned to
the options list.
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. The EXIT Command
is also placed under the right softkey, but
is covered by the default Cancel
text when the
left softkey menu is open.
Figure: An example showing Commands mapped to softkeys
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(); } } }