diff --git a/apps/lcars/lcars.app.js b/apps/lcars/lcars.app.js index 13c163e26..958ab7388 100644 --- a/apps/lcars/lcars.app.js +++ b/apps/lcars/lcars.app.js @@ -567,6 +567,11 @@ function getAlarmMinutes(){ } function increaseAlarm(){ + // Set to zero if alarm was disabled before + if(!isAlarmEnabled()){ + WIDGETS["widtmr"].resetTimer(); + } + WIDGETS["widtmr"].increaseTimer(5); WIDGETS["widtmr"].setStarted(true); } diff --git a/apps/notanalog/notanalog.app.js b/apps/notanalog/notanalog.app.js index be9a01fa7..6bd725f58 100644 --- a/apps/notanalog/notanalog.app.js +++ b/apps/notanalog/notanalog.app.js @@ -396,6 +396,10 @@ function getAlarmMinutes(){ } function increaseAlarm(){ + if(!isAlarmEnabled()){ + WIDGETS["widtmr"].resetTimer(); + } + WIDGETS["widtmr"].increaseTimer(5); WIDGETS["widtmr"].setStarted(true); } diff --git a/apps/widtmr/README.md b/apps/widtmr/README.md index bd795d20f..4bdf20b93 100644 --- a/apps/widtmr/README.md +++ b/apps/widtmr/README.md @@ -22,25 +22,36 @@ into your own app. The following functions are available: - isStarted() -> boolean - setStarted(boolean) -> void +- resetTimer() -> void - increaseTimer(int) -> void - decreaseTimer(int) -> void - getRemainingMinutes() -> int - getRemainingTime() -> DateTime - getRemainingTimeStr() -> str -Example to increase the timer by 5 and ensure that its started: +For example if we want to increase the timer by +5 minutes each time +the touch event is fired: ```Javascript Bangle.loadWidgets(); ... -WIDGETS["widtmr"].increaseTimer(5); -WIDGETS["widtmr"].setStarted(true); +Bangle.on('touch', function(btn, e){ + // Set to zero if alarm was disabled before + if(!isAlarmEnabled()){ + WIDGETS["widtmr"].resetTimer(); + } + + WIDGETS["widtmr"].increaseTimer(5); + WIDGETS["widtmr"].setStarted(true); +}); ``` -Example to decrease the timer. This also disables the timer if time <= 0.: +Example to decrease the timer by 5 and stop if 0 is reached: ```Javascript Bangle.loadWidgets(); ... -WIDGETS["widtmr"].decreaseTimer(5); +Bangle.on('touch', function(btn, e){ + WIDGETS["widtmr"].decreaseTimer(5); +} ``` # Creator diff --git a/apps/widtmr/widget.js b/apps/widtmr/widget.js index 8dcc5ec41..751da4ee8 100644 --- a/apps/widtmr/widget.js +++ b/apps/widtmr/widget.js @@ -121,6 +121,11 @@ } updateSettings(); + }, resetTimer: function(){ + settings.started=false; + settings.minutes = 0; + updateSettings(); + }, getRemainingMinutes: function(){ settings = storage.readJSON("widtmr.json",1)||{started: false}; if(!settings.started){ @@ -129,7 +134,7 @@ var now = new Date(); var diff = settings.goal - now; - return Math.ceil(diff / (1000*60)); + return Math.round(diff / (1000*60)); }, getRemainingTimeStr: function(){ settings = storage.readJSON("widtmr.json",1)||{started: false};