Merge pull request #3404 from aGoodUsername/master

fuzzyw: add toggle for animation + minor bug fixes
master
thyttan 2024-05-08 23:20:06 +02:00 committed by GitHub
commit 6f0440d5e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 134 additions and 109 deletions

View File

@ -1,4 +1,5 @@
0.01: First release 0.01: First release
0.02: Move translations to locale module (removed watch settings, now pick language in Bangle App Loader, More..., Settings) 0.02: Move translations to locale module (removed watch settings, now pick language in Bangle App Loader, More..., Settings)
0.03: Change for fast loading, use widget_utils to hide widgets 0.03: Change for fast loading, use widget_utils to hide widgets
0.04: Add animation when display changes 0.04: Add animation when display changes
0.05: Add toggle for animation + minor bug fixes

View File

@ -11,6 +11,7 @@ Translations are supported to get the time in the language of your choice! To ch
* nn_NO - Norwegian Nynorsk (thank you zerodogg) * nn_NO - Norwegian Nynorsk (thank you zerodogg)
* sv_SE - Swedish * sv_SE - Swedish
* de_DE - German * de_DE - German
* da_DK - Danish
Most translations are taken from the original Fuzzy Text International code. Most translations are taken from the original Fuzzy Text International code.

View File

@ -31,113 +31,129 @@
/*LANG*/"ten to *$2", /*LANG*/"ten to *$2",
/*LANG*/"five to *$2" /*LANG*/"five to *$2"
] ]
}; };
let text_scale = 4; let text_scale = 4;
let timeout = 2.5*60; let timeout = 2.5*60;
let drawTimeout; let drawTimeout;
let animInterval; let animInterval;
let time_string = ""; let time_string = "";
let time_string_old = ""; let time_string_old = "";
let time_string_old_wrapped = ""; let time_string_old_wrapped = "";
let settings = {};
let loadSettings = function() { let loadSettings = function() {
settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'showWidgets': false}; settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'showWidgets': false, 'animate': true};
}; };
let queueDraw = function(seconds) { let queueDraw = function(seconds) {
let millisecs = seconds * 1000; let millisecs = seconds * 1000;
if (drawTimeout) clearTimeout(drawTimeout); if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = setTimeout(function() { drawTimeout = setTimeout(function() {
drawTimeout = undefined; drawTimeout = undefined;
draw(); draw();
}, millisecs - (Date.now() % millisecs)); }, millisecs - (Date.now() % millisecs));
}; };
let getTimeString = function(date) { let getTimeString = function(date) {
let segment = Math.round((date.getMinutes()*60 + date.getSeconds() + 1)/300); let segment = Math.round((date.getMinutes()*60 + date.getSeconds() + 1)/300);
let hour = date.getHours() + Math.floor(segment/12); let hour = date.getHours() + Math.floor(segment/12);
f_string = fuzzy_string.minutes[segment % 12]; // add "" to load into RAM due to 2v21 firmware .replace on flashstring issue
if (f_string.includes('$1')) { let f_string = ""+fuzzy_string.minutes[segment % 12];
f_string = f_string.replace('$1', fuzzy_string.hours[(hour) % 12]); if (f_string.includes('$1')) {
} else { f_string = f_string.replace('$1', fuzzy_string.hours[(hour) % 12]);
f_string = f_string.replace('$2', fuzzy_string.hours[(hour + 1) % 12]); } else {
} f_string = f_string.replace('$2', fuzzy_string.hours[(hour + 1) % 12]);
}
return f_string; return f_string;
}; };
let draw = function() { let draw = function() {
time_string = getTimeString(new Date()).replace('*', ''); time_string = getTimeString(new Date()).replace('*', '');
//print(time_string); //print(time_string);
if (time_string != time_string_old) { if (time_string != time_string_old) {
g.setFont('Vector', R.h/text_scale).setFontAlign(0, 0); g.setFont('Vector', R.h/text_scale).setFontAlign(0, 0);
animate(3); if (settings.animate) {
} animate(3);
queueDraw(timeout); } else {
}; quickDraw();
}
let animate = function(step) {
if (animInterval) clearInterval(animInterval);
let time_string_new_wrapped = g.wrapString(time_string, R.w).join("\n");
slideX = 0;
animInterval = setInterval(function() {
let time_start = getTime()
//blank old time
g.setColor(g.theme.bg);
g.drawString(time_string_old_wrapped, R.x + R.w/2 + slideX, R.y + R.h/2);
g.drawString(time_string_new_wrapped, R.x - R.w/2 + slideX, R.y + R.h/2);
g.setColor(g.theme.fg);
slideX += step;
let stop = false;
if (slideX>=R.w) {
slideX=R.w;
stop = true;
} }
//draw shifted new time queueDraw(timeout);
g.drawString(time_string_old_wrapped, R.x + R.w/2 + slideX, R.y + R.h/2); };
g.drawString(time_string_new_wrapped, R.x - R.w/2 + slideX, R.y + R.h/2);
if (stop) {
time_string_old = time_string;
clearInterval(animInterval);
animInterval=undefined;
time_string_old_wrapped = time_string_new_wrapped;
}
print(Math.round((getTime() - time_start)*1000))
}, 30);
};
g.clear(); let animate = function(step) {
loadSettings();
// Stop updates when LCD is off, restart when on
Bangle.on('lcdPower',on=>{
if (on) {
draw(); // draw immediately, queue redraw
} else { // stop draw timer
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
}
});
Bangle.setUI({
mode : 'clock',
remove : function() {
// Called to unload all of the clock app
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
if (animInterval) clearInterval(animInterval); if (animInterval) clearInterval(animInterval);
animInterval = undefined; let time_string_new_wrapped = g.wrapString(time_string, R.w).join("\n");
require('widget_utils').show(); // re-show widgets let slideX = 0;
//don't let pulling the drawer change y
let text_y = R.y + R.h/2;
animInterval = setInterval(function() {
//blank old time
g.setColor(g.theme.bg);
g.drawString(time_string_old_wrapped, R.x + R.w/2 + slideX, text_y);
g.drawString(time_string_new_wrapped, R.x - R.w/2 + slideX, text_y);
g.setColor(g.theme.fg);
slideX += step;
let stop = false;
if (slideX>=R.w) {
slideX=R.w;
stop = true;
}
//draw shifted new time
g.drawString(time_string_old_wrapped, R.x + R.w/2 + slideX, text_y);
g.drawString(time_string_new_wrapped, R.x - R.w/2 + slideX, text_y);
if (stop) {
time_string_old = time_string;
clearInterval(animInterval);
animInterval=undefined;
time_string_old_wrapped = time_string_new_wrapped;
}
//print(Math.round((getTime() - time_start)*1000));
}, 30);
};
let quickDraw = function() {
let time_string_new_wrapped = g.wrapString(time_string, R.w).join("\n");
g.setColor(g.theme.bg);
g.drawString(time_string_old_wrapped, R.x + R.w/2, R.y + R.h/2);
g.setColor(g.theme.fg);
g.drawString(time_string_new_wrapped, R.x + R.w/2, R.y + R.h/2);
time_string_old_wrapped = time_string_new_wrapped;
};
g.clear();
loadSettings();
// Stop updates when LCD is off, restart when on
Bangle.on('lcdPower',on=>{
if (on) {
draw(); // draw immediately, queue redraw
} else { // stop draw timer
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
}
});
Bangle.setUI({
mode : 'clock',
remove : function() {
// Called to unload all of the clock app
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
if (animInterval) clearInterval(animInterval);
animInterval = undefined;
require('widget_utils').show(); // re-show widgets
}
});
Bangle.loadWidgets();
if (settings.showWidgets) {
Bangle.drawWidgets();
} else {
require("widget_utils").swipeOn(); // hide widgets, make them visible with a swipe
} }
});
Bangle.loadWidgets(); let R = Bangle.appRect;
if (settings.showWidgets) { draw();
Bangle.drawWidgets();
} else {
require("widget_utils").swipeOn(); // hide widgets, make them visible with a swipe
} }
R = Bangle.appRect;
draw();
}

View File

@ -1,32 +1,39 @@
(function(back) { (function(back) {
const SETTINGS_FILE = "fuzzy.settings.json"; const SETTINGS_FILE = "fuzzyw.settings.json";
// initialize with default settings... // initialize with default settings...
let s = {'showWidgets': false} let s = {'showWidgets': false, 'animate': true};
// ...and overwrite them with any saved values // ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings // This way saved values are preserved if a new version adds more settings
const storage = require('Storage') const storage = require('Storage');
let settings = storage.readJSON(SETTINGS_FILE, 1) || s; let settings = storage.readJSON(SETTINGS_FILE, 1) || s;
const saved = settings || {} const saved = settings || {};
for (const key in saved) { for (const key in saved) {
s[key] = saved[key] s[key] = saved[key];
} }
function save() { function save() {
settings = s settings = s;
storage.write(SETTINGS_FILE, settings) storage.write(SETTINGS_FILE, settings);
} }
E.showMenu({ E.showMenu({
'': { 'title': 'Fuzzy Word Clock' }, '': { 'title': 'Fuzzy Word Clock' },
'< Back': back, '< Back': back,
'Show Widgets': { 'Show Widgets': {
value: settings.showWidgets, value: s.showWidgets,
onchange: () => { onchange: () => {
settings.showWidgets = !settings.showWidgets; s.showWidgets = !s.showWidgets;
save(); save();
} }
}, },
'Animate': {
value: s.animate,
onchange: () => {
s.animate = !s.animate;
save();
}
}
}); });
}) })

View File

@ -2,7 +2,7 @@
"id":"fuzzyw", "id":"fuzzyw",
"name":"Fuzzy Text Clock", "name":"Fuzzy Text Clock",
"shortName": "Fuzzy Text", "shortName": "Fuzzy Text",
"version": "0.04", "version": "0.05",
"description": "An imprecise clock for when you're not in a rush", "description": "An imprecise clock for when you're not in a rush",
"readme": "README.md", "readme": "README.md",
"icon":"fuzzyw.png", "icon":"fuzzyw.png",