Download Developing Penlets
Transcript
Developing Penlets
if ((event==MenuEvent.MENU_UP)||
(event==MenuEvent.MENU_DOWN)||
(event==MenuEvent.MENU_SELECT)||
(event==MenuEvent.MENU_LEFT)) {
this.menuView.setFocusItem(this.currentEngine);
this.display.setCurrent(this.menuView);
setCurrentMenuMarker(TRANS_MENU_LANGUAGE);
return true;
}
Note that we set the focus of the menuView object to a number
representing the current target language (currentEngine is a byte that
stands for the current translation engine). Then we pass this.menuView
to display.setCurrent so that menuView will be displayed.
Right Menu Event
The RIGHT_MENU event is key to any penlet. This is the event that the
system sends when the user taps on the right arrow of a Nav Plus. It
means “select the current item” or “display a submenu.” In Sample
Translator, it displays the “Write a word” message.
The relevant code is:
if (event == MenuEvent.MENU_RIGHT) {
// Obtain the single prompt string and play associated APM
this.playCommandAPM();
// Draw the single prompt string
this.labelUI.draw(INPUT_PROMPT,true);
this.display.setCurrent(this.labelUI);
setCurrentMenuMarker(TRANS_MENU_WRITE_TAP);
return true;
}
Note that this case handles the event by playing a sound and displaying
text. The term APM means “Audio Punctuation Mark”. In this case, it is
the audio command to the user: “Write a word.” When users tap the right
arrow, they are leaving the application menu. In order to display to the
OLED, we need a ScrollLabel object such as labelUI. We call draw on
that object and then pass it to display.setCurrent. Don’t’ forget this
last step; if you do, your ScrollLabel object will not be displayed.
79