From e98c06998f9092dcdd230d8e52a164b4f3ccf334 Mon Sep 17 00:00:00 2001 From: aGoodUsername <3471404+aGoodUsername@users.noreply.github.com> Date: Tue, 7 May 2024 09:52:40 +0200 Subject: [PATCH 1/3] fuzzyw: added toggle for animation and fixed various bugs * fuzzyw: add animation toggle, fix various minor bugs * fuzzyw: settings: add animation toggle and fix various minor bugs * fuzzyw: added Danish to readme * fuzzyw: Update ChangeLog * fuzzyw: Update metadata.json --- apps/fuzzyw/ChangeLog | 3 +- apps/fuzzyw/README.md | 1 + apps/fuzzyw/fuzzyw.app.js | 224 ++++++++++++++++++--------------- apps/fuzzyw/fuzzyw.settings.js | 25 ++-- apps/fuzzyw/metadata.json | 2 +- 5 files changed, 143 insertions(+), 112 deletions(-) diff --git a/apps/fuzzyw/ChangeLog b/apps/fuzzyw/ChangeLog index dd73475f9..1a7525834 100644 --- a/apps/fuzzyw/ChangeLog +++ b/apps/fuzzyw/ChangeLog @@ -1,4 +1,5 @@ 0.01: First release 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.04: Add animation when display changes \ No newline at end of file +0.04: Add animation when display changes +0.05: Add toggle for animation + minor bug fixes diff --git a/apps/fuzzyw/README.md b/apps/fuzzyw/README.md index 062c9ac25..82c2a9a4b 100644 --- a/apps/fuzzyw/README.md +++ b/apps/fuzzyw/README.md @@ -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) * sv_SE - Swedish * de_DE - German +* da_DK - Danish Most translations are taken from the original Fuzzy Text International code. diff --git a/apps/fuzzyw/fuzzyw.app.js b/apps/fuzzyw/fuzzyw.app.js index 8bc51710f..577f9dff5 100644 --- a/apps/fuzzyw/fuzzyw.app.js +++ b/apps/fuzzyw/fuzzyw.app.js @@ -31,113 +31,135 @@ /*LANG*/"ten to *$2", /*LANG*/"five to *$2" ] -}; + }; -let text_scale = 4; -let timeout = 2.5*60; -let drawTimeout; -let animInterval; -let time_string = ""; -let time_string_old = ""; -let time_string_old_wrapped = ""; + let text_scale = 4; + let timeout = 2.5*60; + let drawTimeout; + let animInterval; + let time_string = ""; + let time_string_old = ""; + let time_string_old_wrapped = ""; + let settings = {}; -let loadSettings = function() { - settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'showWidgets': false}; -}; + let loadSettings = function() { + settings = require("Storage").readJSON(SETTINGS_FILE,1)|| {'showWidgets': false, 'animate': true}; + }; -let queueDraw = function(seconds) { - let millisecs = seconds * 1000; - if (drawTimeout) clearTimeout(drawTimeout); - drawTimeout = setTimeout(function() { - drawTimeout = undefined; - draw(); - }, millisecs - (Date.now() % millisecs)); -}; - -let getTimeString = function(date) { - let segment = Math.round((date.getMinutes()*60 + date.getSeconds() + 1)/300); - let hour = date.getHours() + Math.floor(segment/12); - f_string = fuzzy_string.minutes[segment % 12]; - if (f_string.includes('$1')) { - f_string = f_string.replace('$1', fuzzy_string.hours[(hour) % 12]); - } else { - f_string = f_string.replace('$2', fuzzy_string.hours[(hour + 1) % 12]); - } - return f_string; -}; - -let draw = function() { - time_string = getTimeString(new Date()).replace('*', ''); - //print(time_string); - if (time_string != time_string_old) { - g.setFont('Vector', R.h/text_scale).setFontAlign(0, 0); - animate(3); - } - queueDraw(timeout); -}; - -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 - 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(); -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 + let queueDraw = function(seconds) { + let millisecs = seconds * 1000; if (drawTimeout) clearTimeout(drawTimeout); - drawTimeout = undefined; - } -}); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, millisecs - (Date.now() % millisecs)); + }; -Bangle.setUI({ - mode : 'clock', - remove : function() { - // Called to unload all of the clock app - if (drawTimeout) clearTimeout(drawTimeout); - drawTimeout = undefined; + let getTimeString = function(date) { + let segment = Math.round((date.getMinutes()*60 + date.getSeconds() + 1)/300); + let hour = date.getHours() + Math.floor(segment/12); + let f_string = fuzzy_string.minutes[segment % 12]; + for (let i = 0; i < f_string.length; i++) { + if (f_string.charAt(i) == '$') { + if (f_string.charAt(i+1) == '1') return f_string.slice(0, i) + fuzzy_string.hours[hour % 12] + f_string.slice(i+2); + return f_string.slice(0, i) + fuzzy_string.hours[(hour+1) % 12] + f_string.slice(i+2); + } + } + // the more elegant solution that unfortunately gets optimized to smithereens + /* + if (f_string.includes('$1')) { + //return f_string.replace('$1', fuzzy_string.hours[hour % 12]); + } else { + //return f_string.replace('$2', fuzzy_string.hours[(hour + 1) % 12]); + }*/ + }; + + let draw = function() { + time_string = getTimeString(new Date()).replace('*', ''); + //print(time_string); + if (time_string != time_string_old) { + g.setFont('Vector', R.h/text_scale).setFontAlign(0, 0); + if (settings.animate) { + animate(3); + } else { + quickDraw(); + } + } + queueDraw(timeout); + }; + + let animate = function(step) { if (animInterval) clearInterval(animInterval); - animInterval = undefined; - require('widget_utils').show(); // re-show widgets + let time_string_new_wrapped = g.wrapString(time_string, R.w).join("\n"); + 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(); -if (settings.showWidgets) { - Bangle.drawWidgets(); -} else { - require("widget_utils").swipeOn(); // hide widgets, make them visible with a swipe + let R = Bangle.appRect; + draw(); } - -R = Bangle.appRect; -draw(); -} \ No newline at end of file diff --git a/apps/fuzzyw/fuzzyw.settings.js b/apps/fuzzyw/fuzzyw.settings.js index 535f91d67..2cb693a84 100644 --- a/apps/fuzzyw/fuzzyw.settings.js +++ b/apps/fuzzyw/fuzzyw.settings.js @@ -1,32 +1,39 @@ (function(back) { - const SETTINGS_FILE = "fuzzy.settings.json"; + const SETTINGS_FILE = "fuzzyw.settings.json"; // initialize with default settings... - let s = {'showWidgets': false} + let s = {'showWidgets': false, 'animate': true}; // ...and overwrite them with any saved values // 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; - const saved = settings || {} + const saved = settings || {}; for (const key in saved) { - s[key] = saved[key] + s[key] = saved[key]; } function save() { - settings = s - storage.write(SETTINGS_FILE, settings) + settings = s; + storage.write(SETTINGS_FILE, settings); } E.showMenu({ '': { 'title': 'Fuzzy Word Clock' }, '< Back': back, 'Show Widgets': { - value: settings.showWidgets, + value: s.showWidgets, onchange: () => { - settings.showWidgets = !settings.showWidgets; + s.showWidgets = !s.showWidgets; save(); } }, + 'Animate': { + value: s.animate, + onchange: () => { + s.animate = !s.animate; + save(); + } + } }); }) diff --git a/apps/fuzzyw/metadata.json b/apps/fuzzyw/metadata.json index 97f060866..110526712 100644 --- a/apps/fuzzyw/metadata.json +++ b/apps/fuzzyw/metadata.json @@ -2,7 +2,7 @@ "id":"fuzzyw", "name":"Fuzzy Text Clock", "shortName": "Fuzzy Text", - "version": "0.04", + "version": "0.05", "description": "An imprecise clock for when you're not in a rush", "readme": "README.md", "icon":"fuzzyw.png", From bb57dfcd638e3b81d75a1ee5fbdc67db9571d45d Mon Sep 17 00:00:00 2001 From: aGoodUsername <3471404+aGoodUsername@users.noreply.github.com> Date: Wed, 8 May 2024 10:22:50 +0200 Subject: [PATCH 2/3] fuzzyw: .replace change --- apps/fuzzyw/fuzzyw.app.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/apps/fuzzyw/fuzzyw.app.js b/apps/fuzzyw/fuzzyw.app.js index 577f9dff5..a03b3521c 100644 --- a/apps/fuzzyw/fuzzyw.app.js +++ b/apps/fuzzyw/fuzzyw.app.js @@ -58,20 +58,14 @@ let getTimeString = function(date) { let segment = Math.round((date.getMinutes()*60 + date.getSeconds() + 1)/300); let hour = date.getHours() + Math.floor(segment/12); - let f_string = fuzzy_string.minutes[segment % 12]; - for (let i = 0; i < f_string.length; i++) { - if (f_string.charAt(i) == '$') { - if (f_string.charAt(i+1) == '1') return f_string.slice(0, i) + fuzzy_string.hours[hour % 12] + f_string.slice(i+2); - return f_string.slice(0, i) + fuzzy_string.hours[(hour+1) % 12] + f_string.slice(i+2); - } - } - // the more elegant solution that unfortunately gets optimized to smithereens - /* + // add "" to load into RAM due to 2v21 firmware .replace on flashstring issue + f_string = ""+fuzzy_string.minutes[segment % 12]; if (f_string.includes('$1')) { - //return f_string.replace('$1', fuzzy_string.hours[hour % 12]); + f_string = f_string.replace('$1', fuzzy_string.hours[(hour) % 12]); } else { - //return f_string.replace('$2', fuzzy_string.hours[(hour + 1) % 12]); - }*/ + f_string = f_string.replace('$2', fuzzy_string.hours[(hour + 1) % 12]); + } + return f_string; }; let draw = function() { From 720c897eab414022bcfe1d5d28d6982579e6ce70 Mon Sep 17 00:00:00 2001 From: thyttan <97237430+thyttan@users.noreply.github.com> Date: Wed, 8 May 2024 23:14:06 +0200 Subject: [PATCH 3/3] fuzzyw: define f_string As `let` was accidentally left out after the refactor on latest previous commit. To appease the linter and not pollute global scope. --- apps/fuzzyw/fuzzyw.app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/fuzzyw/fuzzyw.app.js b/apps/fuzzyw/fuzzyw.app.js index a03b3521c..ab09470fa 100644 --- a/apps/fuzzyw/fuzzyw.app.js +++ b/apps/fuzzyw/fuzzyw.app.js @@ -59,7 +59,7 @@ let segment = Math.round((date.getMinutes()*60 + date.getSeconds() + 1)/300); let hour = date.getHours() + Math.floor(segment/12); // add "" to load into RAM due to 2v21 firmware .replace on flashstring issue - f_string = ""+fuzzy_string.minutes[segment % 12]; + let f_string = ""+fuzzy_string.minutes[segment % 12]; if (f_string.includes('$1')) { f_string = f_string.replace('$1', fuzzy_string.hours[(hour) % 12]); } else {