diff --git a/apps/widapplebatt/ChangeLog b/apps/widapplebatt/ChangeLog new file mode 100644 index 00000000000..4c21f3ace36 --- /dev/null +++ b/apps/widapplebatt/ChangeLog @@ -0,0 +1 @@ +0.01: New Widget! diff --git a/apps/widapplebatt/app.png b/apps/widapplebatt/app.png new file mode 100644 index 00000000000..5fb343ecdd9 Binary files /dev/null and b/apps/widapplebatt/app.png differ diff --git a/apps/widapplebatt/metadata.json b/apps/widapplebatt/metadata.json new file mode 100644 index 00000000000..92f5afa74f7 --- /dev/null +++ b/apps/widapplebatt/metadata.json @@ -0,0 +1,22 @@ +{ + "id": "widapplebatt", + "name": "Apple Battery Widget", + "shortName":"Apple Battery", + "icon": "app.png", + "version":"0.01", + "type": "widget", + "supports": ["BANGLEJS", "BANGLEJS2"], + "author": "RKBoss6", + "description": "A simple battery widget in the style of iOS devices' battery icons, with a setting to show or hide the percent text.", + "tags": "widget,battery", + "provides_widgets" : ["battery"], + "storage": [ + {"name":"widapplebatt.wid.js","url":"widget.js"}, + {"name":"widapplebatt.settings.js","url":"settings.js"} + ], + "data":[ + {"name":"widapplebatt.settings.json"} + ], + "screenshots": [{"url":"screenshot1.png"},{"url":"screenshot2.png"},{"url":"screenshot3.png"}] + +} diff --git a/apps/widapplebatt/screenshot1.png b/apps/widapplebatt/screenshot1.png new file mode 100644 index 00000000000..400187bd742 Binary files /dev/null and b/apps/widapplebatt/screenshot1.png differ diff --git a/apps/widapplebatt/screenshot2.png b/apps/widapplebatt/screenshot2.png new file mode 100644 index 00000000000..08e4581369a Binary files /dev/null and b/apps/widapplebatt/screenshot2.png differ diff --git a/apps/widapplebatt/screenshot3.png b/apps/widapplebatt/screenshot3.png new file mode 100644 index 00000000000..2d7b03df3a7 Binary files /dev/null and b/apps/widapplebatt/screenshot3.png differ diff --git a/apps/widapplebatt/settings.js b/apps/widapplebatt/settings.js new file mode 100644 index 00000000000..06bf2b91c46 --- /dev/null +++ b/apps/widapplebatt/settings.js @@ -0,0 +1,28 @@ +(function(back) { + const FILE = "widapplebatt.settings.json"; + // Load settings + var settings = Object.assign({ + showPercent: true, + }, require('Storage').readJSON(FILE, true) || {}); + + function writeSettings() { + require('Storage').writeJSON(FILE, settings); + } + + + // Show the menu + E.showMenu({ + "" : { "title" : "Apple Battery" }, + "< Back" : () => back(), + 'Show Percent': { + value: !!settings.showPercent, // !! converts undefined to false + onchange: v => { + settings.showPercent = v; + writeSettings(); + if(WIDGETS["applebatt"]) WIDGETS["applebatt"].reload() + if(WIDGETS["applebatt"]) WIDGETS["applebatt"].draw() + + } + } + }); +}) \ No newline at end of file diff --git a/apps/widapplebatt/widget.js b/apps/widapplebatt/widget.js new file mode 100644 index 00000000000..10407d21af2 --- /dev/null +++ b/apps/widapplebatt/widget.js @@ -0,0 +1,37 @@ +(function(){ + const intervalLow = 120000; + const intervalHigh = 30000; + var id; + let settings; + function reload() { + settings=require("Storage").readJSON("widapplebatt.settings.json")||{showPercent:true} + } + function draw() { + g.reset("widget"); + var x = this.x, y = this.y, w = this.width-5; + const l = E.getBattery(); + const lw=(w)*(l/100) + g.setColor("#808080"); + g.fillRect({x:x+2,y:y+2,w:w,h:16,r:6}) + let col=g.theme.fg + if(l<25) col=g.theme.dark ? "#ff0" : "#FC6A03" + if(l<15) col="#f00" + if(Bangle.isCharging()) col="#0f0" + g.setColor(col) + .fillRect({x:x+2,y:y+2,w:lw,h:16,r:6}) + .setFontAlign(0,0).setColor(g.theme.bg) + .setColor(g.theme.bg) + .drawRect({x:x+1,y:y+1,w:w+2,h:16+2,r:6}) + .drawRect({x:x+0.5,y:y+1,w:w+3,h:16+2,r:6}) + .drawRect({x:x,y:y,w:w+4,h:16+4,r:6}) + if(settings.showPercent) g.setFont("14").drawString(l,x+2+(w/2),y+12) + if (Bangle.isCharging()) changeInterval(id, intervalHigh); + else changeInterval(id, intervalLow); + + } + reload() + Bangle.on('charging',function(charging) { draw(); }); + id = setInterval(()=>WIDGETS["applebatt"].draw(), intervalLow); + + WIDGETS["applebatt"]={area:"tr",width:32,draw:draw, reload:reload}; +})();