Hello.
I'm developing a widget.
It should show this behavior:
- Show main view.
- On UP/DOWN press: increment/decrement a variable, recalculate stuff and redraw main view.
- On MENU press: show confirmation dialog to reset data.
- On BACK press: show Glance (if available) or exit.
I've used the Input sample application included in the SDK. Added the InputDelegate.mc class to my project and added an instance of the InputDelegate to the function calling the main view, in he main App class.
In the InputDelegate.onKey function (for the moment) I check for the key pressed, print it using System.println and continue. The MENU press is already calling the confirmation in this code:
public function onKey(evt as KeyEvent) as Boolean {
System.println("InputDelegate.onKey");
var key = evt.getKey();
var button = getButton(key);
_parentView.setButton(button);
var keyAction = getKeyAction(key);
if (keyAction != null) {
_parentView.setAction(keyAction);
}
if (key == KEY_ENTER) {
System.println("MOB");
var message = Application.loadResource( Rez.Strings.ResetData );
var dialog = new WatchUi.Confirmation(message);
WatchUi.pushView (
dialog,
new MyConfirmationDelegate(),
WatchUi.SLIDE_IMMEDIATE
);
} else if (key == KEY_DOWN) {
System.println("DOWN");
} else if (key == KEY_UP) {
System.println("UP");
} else if (key == KEY_ESC) {
System.println("ESC");
}
if (key == KEY_ESC) {
if (_lastKey == KEY_ESC) {
System.exit();
}
}
_lastKey = key;
return true;
}
Issue is: MENU works as expected. UP/DOWN/BACK are never intercepted. If I press any of those the widget calls view.onHide and app.onStop and exits cleanly.
How can I intercept the UP/DOWN/BACK buttons? Aren't they available to widgets?
Thanks in advance!