Skip to content

Commit 91a9888

Browse files
authored
Merge pull request #3897 from RKBoss6/ChargeAnimSettings
Add settings to Charge Animation [Show Time, Show Battery Percent]
2 parents 4d38399 + 53c2977 commit 91a9888

File tree

9 files changed

+122
-7
lines changed

9 files changed

+122
-7
lines changed

apps/chargeanim/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
0.01: New App!
22
0.02: Bangle.js 2 compatibility
3+
0.03: Add settings menu for showing time and battery percent with animation.

apps/chargeanim/Screenshot1.png

13.8 KB
Loading

apps/chargeanim/Screenshot2.png

12.4 KB
Loading

apps/chargeanim/Screenshot3.png

15.8 KB
Loading

apps/chargeanim/app.js

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
2+
var settings = Object.assign({
3+
// default values
4+
showBatPercent: true,
5+
showTime: true,
6+
7+
8+
}, require("Storage").readJSON("chargeAnimSettings.json", true) || {});
9+
10+
111
g.setBgColor(0, 0, 0);
212
g.clear().flip();
313
var imgbat = require("heatshrink").decompress(atob("nFYhBC/AH4A/AGUeACA22HEo3/G8YrTAC422HBQ2tHBI3/G/43/G/43/G/43/G/43/G/43/G+fTG+vSN+w326Q31GwI3/G9g2WG742CG/43rGwY3yGwg33RKo3bNzQ3bGwo3/G9A2GG942dG/43QGw43uGxA34IKw3VGyY3iG0I3pb8pBRG+wYPG8wYQG/42uG8oZSG/43bDKY3iDKg3cNzI3iRKo3gGyo3/G7A2WG7g2aG/43WGzA3dGzI3/G6fTGzRvcG/43/G/43/G/43/G/43/G/43/G/437HFw2IHFo2KAH4A/AH4Aa"));
414
var imgbubble = require("heatshrink").decompress(atob("i0UhAebgoAFCaYXNBocjAAIWNCYoVHCw4UFIZwqELJQWFKZQVOChYVzABwVaCx7wKCqIWNCg4WMChIXJCZgAnA=="));
5-
15+
require("Font8x12").add(Graphics);
16+
var batteryPercentStr="";
617
var W=g.getWidth(),H=g.getHeight();
718
var b2v = (W != 240)?-1:1;
819
var b2rot = (W != 240)?Math.PI:0;
@@ -12,11 +23,50 @@ for (var i=0;i<10;i++) {
1223
bubbles.push({y:Math.random()*H,ly:0,x:(0.5+(i<5?i:i+8))*W/18,v:0.6+Math.random(),s:0.5+Math.random()});
1324
}
1425

26+
g.setFont("Vector",22);
27+
g.setFontAlign(0,0);
28+
29+
var clockStr="";
30+
var x=g.getWidth()/2;
31+
var cy=g.getHeight()-(g.getHeight()/7)
32+
var by=g.getHeight()-(g.getHeight()/3.500)
33+
34+
35+
function calculateTime(){
36+
37+
var d=new Date();
38+
clockStr = require("locale").time(d, 1); // Hour and minute
39+
var meridian=require("locale").meridian(d);
40+
if(meridian!=""){
41+
//Meridian active
42+
clockStr=clockStr+" "+meridian;
43+
}
44+
45+
}
46+
function calculate(){
47+
if(settings.showTime==true){
48+
calculateTime();
49+
}
50+
if(settings.showBatPercent==true){
51+
batteryPercentStr=E.getBattery()+"%";
52+
}
53+
54+
55+
}
56+
1557
function anim() {
1658
/* we don't use any kind of buffering here. Just draw one image
1759
at a time (image contains a background) too, and there is minimal
1860
flicker. */
19-
var mx = W/2.0, my = H/2.0;
61+
var mx = W/2.0;
62+
var my;
63+
if(settings.showBatPercent){
64+
var my = H/2.5;
65+
}else{
66+
var my = H/2.0;
67+
}
68+
69+
2070
bubbles.forEach(f=>{
2171
f.y-=f.v * b2v;
2272
if (f.y<-24)
@@ -26,10 +76,25 @@ function anim() {
2676
g.drawImage(imgbubble,f.y,f.x,{scale:f.s * b2scale, rotate:b2rot});
2777
});
2878
g.drawImage(imgbat, mx,my,{scale:b2scale, rotate:Math.sin(getTime()*2)*0.5-Math.PI/2 + b2rot});
79+
if(settings.showTime==true){
80+
g.drawString(clockStr,x,cy);
81+
}
82+
if(settings.showBatPercent==true){
83+
g.drawString(batteryPercentStr,x,by,true);
84+
}
2985
g.flip();
86+
87+
88+
}
89+
90+
if(settings.showBatPercent||settings.showTime){
91+
//Eliminate unnesccesary need for calculation
92+
calculate();
93+
setInterval(calculate,20000);
3094
}
3195

32-
setInterval(anim,20);
96+
setInterval(anim,22);
97+
3398

3499
Bangle.on("charging", isCharging => {
35100
if (!isCharging) load();
-3.32 KB
Binary file not shown.
-1.98 KB
Binary file not shown.

apps/chargeanim/metadata.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
{
22
"id": "chargeanim",
33
"name": "Charge Animation",
4-
"version": "0.02",
5-
"description": "When charging, show a sideways charging animation and keep the screen on. When removed from the charger load the clock again.",
4+
"version": "0.03",
5+
"description": "When charging, show a sideways charging animation and optionally, show time, or show battery percentage. When removed from the charger, clock loads again.",
66
"icon": "icon.png",
77
"tags": "battery",
88
"supports": ["BANGLEJS", "BANGLEJS2"],
99
"allow_emulator": true,
10-
"screenshots": [{"url":"bangle2-charge-animation-screenshot.png"},{"url":"bangle-charge-animation-screenshot.png"}],
10+
"screenshots": [
11+
{"url":"Screenshot1.png"},
12+
{"url":"Screenshot2.png"},
13+
{"url":"Screenshot3.png"}],
1114
"storage": [
1215
{"name":"chargeanim.app.js","url":"app.js"},
1316
{"name":"chargeanim.boot.js","url":"boot.js"},
17+
{"name":"chargeanim.settings.js","url":"settings.js"},
1418
{"name":"chargeanim.img","url":"app-icon.js","evaluate":true}
15-
]
19+
],
20+
"data": [{"name":"chargeAnimSettings.json"}]
1621
}

apps/chargeanim/settings.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
(function(back) {
2+
var FILE = "chargeAnimSettings.json";
3+
// Load settings
4+
5+
var settings = Object.assign({
6+
// default values
7+
showBatPercent: true,
8+
showTime: true,
9+
10+
11+
}, require('Storage').readJSON(FILE, true) || {});
12+
13+
function writeSettings() {
14+
require('Storage').writeJSON(FILE, settings);
15+
}
16+
17+
// Show the menu
18+
E.showMenu({
19+
"" : { "title" : "Charge Animation" },
20+
"< Back" : () => back(),
21+
'Show Percent Charged': {
22+
value: !!settings.showBatPercent, // !! converts undefined to false
23+
onchange: v => {
24+
settings.showBatPercent = v;
25+
writeSettings();
26+
}
27+
// format: ... may be specified as a function which converts the value to a string
28+
// if the value is a boolean, showMenu() will convert this automatically, which
29+
// keeps settings menus consistent
30+
},
31+
'Show Time': {
32+
value: !!settings.showTime, // !! converts undefined to false
33+
onchange: v => {
34+
settings.showTime = v;
35+
writeSettings();
36+
}
37+
// format: ... may be specified as a function which converts the value to a string
38+
// if the value is a boolean, showMenu() will convert this automatically, which
39+
// keeps settings menus consistent
40+
}
41+
42+
43+
});
44+
})

0 commit comments

Comments
 (0)