This is an issue when using a progress bar. When using a progress bar you should pass null for the input delegate, but doing so allows user input to continue being fed to the previous delegate. This is a problem if the delegate does anything in response to that user input, like push another progress bar as in the example below.
Travis
using Toybox.Application as App;
using Toybox.Attention as Attn;
using Toybox.System as Sys;
using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
class TimedView extends Ui.View {
hidden var timer;
hidden var ticks;
function initialize() {
timer = new Timer.Timer();
}
function onShow() {
timer.start(self.method(:onTimer), 5000, false);
}
function onHide() {
timer.stop();
}
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
dc.clear();
var cx = dc.getWidth() / 2;
var cy = dc.getHeight() / 2;
dc.drawText(cx, cy, Gfx.FONT_SMALL,
"For the next 5 seconds\nNo tone should play\nif you press a key.",
Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
}
function onTimer() {
Ui.popView(SLIDE_IMMEDIATE);
}
}
class TestView extends Ui.View
{
function initialize() {
}
function onUpdate(dc) {
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_BLACK);
dc.clear();
var cx = dc.getWidth() / 2;
var cy = dc.getHeight() / 2;
dc.drawText(cx, cy, Gfx.FONT_SMALL,
"Press a Key.\nA tone should play.",
Gfx.TEXT_JUSTIFY_CENTER | Gfx.TEXT_JUSTIFY_VCENTER);
}
}
class TestDelegate extends Ui.InputDelegate
{
hidden var view;
function initialize(view) {
self.view = view;
}
function onKey(evt) {
Attn.playTone(Attn.TONE_KEY);
var key = evt.getKey();
if (key == Ui.KEY_ESC) {
Ui.popView(Ui.SLIDE_IMMEDIATE);
}
else if (key == Ui.KEY_ENTER) {
var view = new TimedView();
Ui.pushView(view, null, Ui.SLIDE_IMMEDIATE);
}
return true;
}
}
class TestApp extends App.AppBase
{
function initialize() {
}
function getInitialView() {
var view = new TestView();
var delegate = new TestDelegate(view);
return [ view, delegate ];
}
}