smpltmr 0.12: Fix ClockInfo so it updates after leaving +5min/etc by blurring
+ ClockInfo now shows time left in icon, updates more often the closer to the time + Tapping clockinfo adds 1 min, added +30min option toomaster
parent
de20eb7c3a
commit
17068c8b6c
|
|
@ -9,3 +9,6 @@
|
||||||
0.09: Timer ClockInfo resets to timer menu when blurred
|
0.09: Timer ClockInfo resets to timer menu when blurred
|
||||||
0.10: Timer ClockInfo now uses +- icons, and changes timer from 'T-5 min' to just '5 min' to aid readability
|
0.10: Timer ClockInfo now uses +- icons, and changes timer from 'T-5 min' to just '5 min' to aid readability
|
||||||
0.11: Fix to handle updated firmware on fw 2v25 (or cutting edge >2v24.164), btn -> btnRelease. The timer would fire on long press before the watch reset.
|
0.11: Fix to handle updated firmware on fw 2v25 (or cutting edge >2v24.164), btn -> btnRelease. The timer would fire on long press before the watch reset.
|
||||||
|
0.12: Fix ClockInfo so it updates after leaving +5min/etc by blurring
|
||||||
|
ClockInfo now shows time left in icon, updates more often the closer to the time
|
||||||
|
Tapping clockinfo adds 1 min, added +30min option too
|
||||||
|
|
@ -1,60 +1,23 @@
|
||||||
(function() {
|
(function() {
|
||||||
const TIMER_IDX = "smpltmr";
|
const TIMER_IDX = "smpltmr", alarm = require('sched');
|
||||||
var alarm = require('sched');
|
|
||||||
|
|
||||||
function isAlarmEnabled(){
|
function getAlarm() {
|
||||||
try{
|
var alarmObj = alarm.getAlarm(TIMER_IDX),
|
||||||
|
min = (alarmObj && alarmObj.on) ? alarm.getTimeToAlarm(alarmObj)/(60*1000) : 0;
|
||||||
var alarmObj = alarm.getAlarm(TIMER_IDX);
|
return {
|
||||||
if(alarmObj===undefined || !alarmObj.on){
|
minutes : min,
|
||||||
return false;
|
text : min ? ((min<1) ? "<1" : Math.round(min)) + /*LANG*/" min" : /*LANG*/"OFF",
|
||||||
|
max : alarmObj?alarmObj.timer/60000:1
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
function changeAlarm(t) {
|
||||||
|
var minutes = Math.round(getAlarm().minutes) + t;
|
||||||
} catch(ex){ }
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAlarmMinutes(){
|
|
||||||
if(!isAlarmEnabled()){
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
var alarmObj = alarm.getAlarm(TIMER_IDX);
|
|
||||||
return Math.round(alarm.getTimeToAlarm(alarmObj)/(60*1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAlarmMinutesText(){
|
|
||||||
var min = getAlarmMinutes();
|
|
||||||
if(min < 0)
|
|
||||||
return "OFF";
|
|
||||||
return min + " min";
|
|
||||||
}
|
|
||||||
|
|
||||||
function increaseAlarm(t){
|
|
||||||
try{
|
|
||||||
var minutes = isAlarmEnabled() ? getAlarmMinutes() : 0;
|
|
||||||
alarm.setAlarm(TIMER_IDX, {
|
|
||||||
timer : (minutes+t)*60*1000,
|
|
||||||
});
|
|
||||||
alarm.reload();
|
|
||||||
} catch(ex){ }
|
|
||||||
}
|
|
||||||
|
|
||||||
function decreaseAlarm(t){
|
|
||||||
try{
|
|
||||||
var minutes = getAlarmMinutes();
|
|
||||||
minutes -= t;
|
|
||||||
|
|
||||||
alarm.setAlarm(TIMER_IDX, undefined);
|
alarm.setAlarm(TIMER_IDX, undefined);
|
||||||
if(minutes > 0){
|
if(minutes > 0)
|
||||||
alarm.setAlarm(TIMER_IDX, {
|
alarm.setAlarm(TIMER_IDX, { timer : minutes*60000 });
|
||||||
timer : minutes*60*1000,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
alarm.reload();
|
alarm.reload();
|
||||||
} catch(ex){ }
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var smpltmrItems = {
|
var smpltmrItems = {
|
||||||
|
|
@ -63,33 +26,48 @@
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
name: null,
|
name: null,
|
||||||
get: () => ({ text: getAlarmMinutesText(), img: smpltmrItems.img } ),
|
get: function() {
|
||||||
show: function() { this.interval = setInterval(()=>this.emit('redraw'), 60000); },
|
var alm = getAlarm();
|
||||||
hide: function () { clearInterval(this.interval); delete this.interval; },
|
if (alm.minutes > 0) { // draw an icon showing actual progress (don't ever go 100% as looks odd)
|
||||||
//run: function() { } // should tapping do something?
|
if (this.uses) {
|
||||||
|
if (this.timeout) clearTimeout(this.timeout);
|
||||||
|
this.timeout = setTimeout(()=>{
|
||||||
|
this.emit('redraw');
|
||||||
|
delete this.timeout;
|
||||||
|
}, alm.minutes<3 ? 2000 : (alm.minutes < 30 ? 30000 : 60000));
|
||||||
|
}
|
||||||
|
var gr = Graphics.createArrayBuffer(24,24,1), poly = [11.5,13.5], s=Math.sin,c=Math.cos, a = Math.min(alm.minutes * Math.PI*2 / alm.max,5.5);
|
||||||
|
for (var i=0;i<a;i+=0.5) poly.push(11.5+6*s(i), 13.5-6*c(i));
|
||||||
|
poly.push(11.5+6*s(a), 13.5-6*c(a));
|
||||||
|
gr.drawImage(atob("GBgBAH4AAH4AABgAABgAAH4ADf+wD4HwDgBwDAAwGAAYGAAYMAAMMAAMMAAMMAAMMAAMMAAMGAAYGAAYDAAwDgBwB4HgAf+AAH4A")).fillPoly(poly);
|
||||||
|
return { text: alm.text, img: gr.asImage("string") };
|
||||||
|
} else
|
||||||
|
return { text: alm.text, img: smpltmrItems.img };
|
||||||
|
},
|
||||||
|
show: function() { },
|
||||||
|
hide: function() { if (this.timeout) clearTimeout(this.timeout); delete this.timeout; },
|
||||||
|
run: function() { changeAlarm(1); this.emit('redraw'); return true; } // tapping adds 1 minute
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const restoreMainItem = function(clkinfo) {
|
let onBlur = function(clkinfo) { clkinfo.setItem(clkinfo.menuA,0); }; // change back to menu
|
||||||
clkinfo.menuB = 0;
|
[-5,-30].forEach(o => {
|
||||||
// clock info redraws after this
|
|
||||||
};
|
|
||||||
|
|
||||||
var offsets = [+5,-5];
|
|
||||||
offsets.forEach((o, i) => {
|
|
||||||
smpltmrItems.items = smpltmrItems.items.concat({
|
smpltmrItems.items = smpltmrItems.items.concat({
|
||||||
name: null,
|
name: null,
|
||||||
get: () => ({ text: (o > 0 ? "+" : "") + o + " min", img: (o>0)?atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwAMBgYGBgYGDAYDDAYDDH/jDH/jDAYDDAYDBgYGBgYGAwAMA4AcAeB4AH/gAB+AA=="):atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwAMBgAGBgAGDAADDAADDH/jDH/jDAADDAADBgAGBgAGAwAMA4AcAeB4AH/gAB+AA==") }),
|
get: () => ({ text: o + /*LANG*/" min", img: atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwAMBgAGBgAGDAADDAADDH/jDH/jDAADDAADBgAGBgAGAwAMA4AcAeB4AH/gAB+AA==") }),
|
||||||
show: function() {},
|
show: function() {},
|
||||||
hide: function() {},
|
hide: function() {},
|
||||||
blur: restoreMainItem,
|
blur: onBlur, run: changeAlarm.bind(null,o)
|
||||||
run: function() {
|
});
|
||||||
if(o > 0) increaseAlarm(o);
|
});
|
||||||
else decreaseAlarm(Math.abs(o));
|
[+30,+5].forEach(o => {
|
||||||
this.show();
|
smpltmrItems.items = smpltmrItems.items.concat({
|
||||||
return true;
|
name: null,
|
||||||
}
|
get: () => ({ text: "+" + o + /*LANG*/" min", img: atob("GBiBAAB+AAB+AAAYAAAYAAB+AA3/sA+B8A4AcAwAMBgYGBgYGDAYDDAYDDH/jDH/jDAYDDAYDBgYGBgYGAwAMA4AcAeB4AH/gAB+AA==") }),
|
||||||
|
show: function() {},
|
||||||
|
hide: function() {},
|
||||||
|
blur: onBlur, run: changeAlarm.bind(null,o)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "smpltmr",
|
"id": "smpltmr",
|
||||||
"name": "Simple Timer",
|
"name": "Simple Timer",
|
||||||
"shortName": "Simple Timer",
|
"shortName": "Simple Timer",
|
||||||
"version": "0.11",
|
"version": "0.12",
|
||||||
"description": "A very simple app to start a timer.",
|
"description": "A very simple app to start a timer.",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"tags": "tool,alarm,timer,clkinfo",
|
"tags": "tool,alarm,timer,clkinfo",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue