widclk/close/etc - allow turning on/off when quick-switching apps

f6b38b3443 (r88164680)
pull/2209/head
Gordon Williams 2022-10-28 12:21:27 +01:00
parent a42b79a7c7
commit ac6f7b1521
12 changed files with 54 additions and 57 deletions

View File

@ -3,3 +3,4 @@
0.04: Fix regression stopping correct widget updates 0.04: Fix regression stopping correct widget updates
0.05: Don't show clock widget if already showing clock app 0.05: Don't show clock widget if already showing clock app
0.06: Use 7 segment font, update *on* the minute, use less memory 0.06: Use 7 segment font, update *on* the minute, use less memory
0.07: allow turning on/off when quick-switching apps

View File

@ -1,7 +1,7 @@
{ {
"id": "widclk", "id": "widclk",
"name": "Digital clock widget", "name": "Digital clock widget",
"version": "0.06", "version": "0.07",
"description": "A simple digital clock widget", "description": "A simple digital clock widget",
"icon": "widget.png", "icon": "widget.png",
"type": "widget", "type": "widget",

View File

@ -1,9 +1,12 @@
/* Simple clock that appears in the widget bar if no other clock /* Simple clock that appears in the widget bar if no other clock
is running. We update once per minute, but don't bother stopping is running. We update once per minute, but don't bother stopping
if the */ if the */
WIDGETS["wdclk"]={area:"tl",width:Bangle.CLOCK?0:52/* g.stringWidth("00:00") */,draw:function() {
// don't show widget if we know we have a clock app running if (!Bangle.CLOCK == !this.width) { // if we're the wrong size for if we have a clock or not...
if (!Bangle.CLOCK) WIDGETS["wdclk"]={area:"tl",width:52/* g.stringWidth("00:00") */,draw:function() { this.width = Bangle.CLOCK?0:52;
return setTimeout(Bangle.drawWidgets,1); // widget changed size - redraw
}
if (!this.width) return; // if size not right, return
g.reset().setFontCustom(atob("AAAAAAAAAAIAAAQCAQAAAd0BgMBdwAAAAAAAdwAB0RiMRcAAAERiMRdwAcAQCAQdwAcERiMRBwAd0RiMRBwAAEAgEAdwAd0RiMRdwAcERiMRdwAFAAd0QiEQdwAdwRCIRBwAd0BgMBAAABwRCIRdwAd0RiMRAAAd0QiEQAAAAAAAAAA="), 32, atob("BgAAAAAAAAAAAAAAAAYCAAYGBgYGBgYGBgYCAAAAAAAABgYGBgYG"), 512+9); g.reset().setFontCustom(atob("AAAAAAAAAAIAAAQCAQAAAd0BgMBdwAAAAAAAdwAB0RiMRcAAAERiMRdwAcAQCAQdwAcERiMRBwAd0RiMRBwAAEAgEAdwAd0RiMRdwAcERiMRdwAFAAd0QiEQdwAdwRCIRBwAd0BgMBAAABwRCIRdwAd0RiMRAAAd0QiEQAAAAAAAAAA="), 32, atob("BgAAAAAAAAAAAAAAAAYCAAYGBgYGBgYGBgYCAAAAAAAABgYGBgYG"), 512+9);
var time = require("locale").time(new Date(),1); var time = require("locale").time(new Date(),1);
g.drawString(time, this.x, this.y+3, true); // 5 * 6*2 = 60 g.drawString(time, this.x, this.y+3, true); // 5 * 6*2 = 60

View File

@ -1,4 +1,4 @@
0.01: Fork of widclk v0.04 github.com/espruino/BangleApps/tree/master/apps/widclk 0.01: Fork of widclk v0.04 github.com/espruino/BangleApps/tree/master/apps/widclk
0.02: Modification for bottom widget area and text color 0.02: Modification for bottom widget area and text color
0.03: based in widclk v0.05 compatible at same time, bottom area and color 0.03: based in widclk v0.05 compatible at same time, bottom area and color
0.04: refactored to use less memory, and allow turning on/off when quick-switching apps

View File

@ -2,8 +2,8 @@
"id": "widclkbttm", "id": "widclkbttm",
"name": "Digital clock (Bottom) widget", "name": "Digital clock (Bottom) widget",
"shortName": "Digital clock Bottom Widget", "shortName": "Digital clock Bottom Widget",
"version": "0.03", "version": "0.04",
"description": "Displays time in the bottom area.", "description": "Displays time in the bottom of the screen (may not be compatible with some apps)",
"icon": "widclkbttm.png", "icon": "widclkbttm.png",
"type": "widget", "type": "widget",
"tags": "widget", "tags": "widget",

View File

@ -1,31 +1,16 @@
(function() { WIDGETS["wdclkbttm"]={area:"br",width:Bangle.CLOCK?0:60,draw:function() {
// don't show widget if we know we have a clock app running if (!Bangle.CLOCK == !this.width) { // if we're the wrong size for if we have a clock or not...
if (Bangle.CLOCK) return; this.width = Bangle.CLOCK?0:60;
return setTimeout(Bangle.drawWidgets,1); // widget changed size - redraw
let intervalRef = null; }
var width = 5 * 6*2; if (!this.width) return; // if size not right, return
var text_color=0x07FF;//cyan g.reset().setFont("6x8", 2).setFontAlign(-1, 0).setColor("#0ff"); // cyan
function draw() {
g.reset().setFont("6x8", 2).setFontAlign(-1, 0).setColor(text_color);
var time = require("locale").time(new Date(),1); var time = require("locale").time(new Date(),1);
g.drawString(time, this.x, this.y+11, true); // 5 * 6*2 = 60 g.drawString(time, this.x, this.y+11, true); // 5 * 6*2 = 60
} // queue draw in one minute
function clearTimers(){ if (this.drawTimeout) clearTimeout(this.drawTimeout);
if(intervalRef) { this.drawTimeout = setTimeout(()=>{
clearInterval(intervalRef); this.drawTimeout = undefined;
intervalRef = null; this.draw();
} }, 60000 - (Date.now() % 60000));
} }};
function startTimers(){
intervalRef = setInterval(()=>WIDGETS["wdclkbttm"].draw(), 60*1000);
WIDGETS["wdclkbttm"].draw();
}
Bangle.on('lcdPower', (on) => {
clearTimers();
if (on) startTimers();
});
WIDGETS["wdclkbttm"]={area:"br",width:width,draw:draw};
if (Bangle.isLCDOn) intervalRef = setInterval(()=>WIDGETS["wdclkbttm"].draw(), 60*1000);
})()

View File

@ -1 +1,2 @@
0.01: New widget! 0.01: New widget!
0.02: allow turning on/off when quick-switching apps

View File

@ -1,7 +1,7 @@
{ {
"id": "widclose", "id": "widclose",
"name": "Close Button", "name": "Close Button",
"version": "0.01", "version": "0.02",
"description": "A button to close the current app", "description": "A button to close the current app",
"readme": "README.md", "readme": "README.md",
"icon": "icon.png", "icon": "icon.png",

View File

@ -1,14 +1,17 @@
if (!Bangle.CLOCK) WIDGETS.close = { WIDGETS.close = {
area: "tr", width: 24, sortorder: 10, // we want the right-most spot please area: "tr", width: Bangle.CLOCK?0:24, sortorder: 10, // we want the right-most spot please
draw: function() { draw: function() {
Bangle.removeListener("touch", this.touch); if (!Bangle.CLOCK == !this.width) { // if we're the wrong size for if we have a clock or not...
Bangle.on("touch", this.touch); this.width = Bangle.CLOCK?0:24;
g.reset().setColor("#f00").drawImage(atob( // hardcoded red to match setUI back button return setTimeout(Bangle.drawWidgets,1); // widget changed size - redraw
}
if (this.width) g.reset().setColor("#f00").drawImage(atob( // red to match setUI back button
// b/w version of preview.png, 24x24 // b/w version of preview.png, 24x24
"GBgBABgAAf+AB//gD//wH//4P//8P//8fn5+fjx+fxj+f4H+/8P//8P/f4H+fxj+fjx+fn5+P//8P//8H//4D//wB//gAf+AABgA" "GBgBABgAAf+AB//gD//wH//4P//8P//8fn5+fjx+fxj+f4H+/8P//8P/f4H+fxj+fjx+fn5+P//8P//8H//4D//wB//gAf+AABgA"
), this.x, this.y); ), this.x, this.y);
}, touch: function(_, c) { }, touch: function(_, c) { // if touched
const w = WIDGETS.close; const w = WIDGETS.close; // if in range, go back to the clock
if (w && c.x>=w.x && c.x<=w.x+24 && c.y>=w.y && c.y<=w.y+24) load(); if (w && c.x>=w.x && c.x<w.x+w.width && c.y>=w.y && c.y<=w.y+24) load();
} }
}; };
Bangle.on("touch", WIDGETS.close.touch);

View File

@ -1 +1,2 @@
0.01: New widget! 0.01: New widget!
0.02: allow turning on/off when quick-switching apps

View File

@ -1,7 +1,7 @@
{ {
"id": "widcloselaunch", "id": "widcloselaunch",
"name": "Close Button to launcher", "name": "Close Button to launcher",
"version": "0.01", "version": "0.02",
"description": "A button to close the current app and go to launcher", "description": "A button to close the current app and go to launcher",
"readme": "README.md", "readme": "README.md",
"icon": "icon.png", "icon": "icon.png",

View File

@ -1,14 +1,17 @@
if (!Bangle.CLOCK) WIDGETS.close = { WIDGETS.close = {
area: "tr", width: 24, sortorder: 10, // we want the right-most spot please area: "tr", width: Bangle.CLOCK?0:24, sortorder: 10, // we want the right-most spot please
draw: function() { draw: function() {
Bangle.removeListener("touch", this.touch); if (!Bangle.CLOCK == !this.width) { // if we're the wrong size for if we have a clock or not...
Bangle.on("touch", this.touch); this.width = Bangle.CLOCK?0:24;
g.reset().setColor("#f00").drawImage(atob( // hardcoded red to match setUI back button return setTimeout(Bangle.drawWidgets,1); // widget changed size - redraw
}
if (this.width) g.reset().setColor("#f00").drawImage(atob( // red to match setUI back button
// b/w version of preview.png, 24x24 // b/w version of preview.png, 24x24
"GBgBABgAAf+AB//gD//wH//4P//8P//8fn5+fjx+fxj+f4H+/8P//8P/f4H+fxj+fjx+fn5+P//8P//8H//4D//wB//gAf+AABgA" "GBgBABgAAf+AB//gD//wH//4P//8P//8fn5+fjx+fxj+f4H+/8P//8P/f4H+fxj+fjx+fn5+P//8P//8H//4D//wB//gAf+AABgA"
), this.x, this.y); ), this.x, this.y);
}, touch: function(_, c) { }, touch: function(_, c) {
const w = WIDGETS.close; const w = WIDGETS.close;
if (w && c.x>=w.x && c.x<=w.x+24 && c.y>=w.y && c.y<=w.y+24) Bangle.showLauncher(); if (w && c.x>=w.x && c.x<w.x+w.width && c.y>=w.y && c.y<=w.y+24) Bangle.showLauncher();
} }
}; };
Bangle.on("touch", WIDGETS.close.touch);