From e262880005f6ffc2fd3004d3a549745266698fc1 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sat, 24 Aug 2024 00:19:49 +0200 Subject: [PATCH 1/8] pomoplus: increase size of fonts and buttons for legibility and ease of use. Also center the images correctly with regards to their anchoring. --- apps/pomoplus/ChangeLog | 1 + apps/pomoplus/app.js | 48 +++++++++++++++++++++---------------- apps/pomoplus/metadata.json | 2 +- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/apps/pomoplus/ChangeLog b/apps/pomoplus/ChangeLog index 96104469b5..6ce1bd59a9 100644 --- a/apps/pomoplus/ChangeLog +++ b/apps/pomoplus/ChangeLog @@ -2,3 +2,4 @@ 0.02-0.04: Bug fixes 0.05: Submitted to the app loader 0.06: Added setting to show clock after start/resume +0.07: Make fonts and buttons larger for legibility and ease of use. diff --git a/apps/pomoplus/app.js b/apps/pomoplus/app.js index a9e21b98a4..b4ff83cafb 100644 --- a/apps/pomoplus/app.js +++ b/apps/pomoplus/app.js @@ -14,37 +14,45 @@ if ( common.state = common.STATE_DEFAULT; } +const W = g.getWidth(); +const H = g.getHeight(); +const SCALING = W/176; // The UI was tweaked to look good on a Bangle.js 2 (176x176 px). SCALING is used to adapt with the resolution of whatever device the app is running on. +const BUTTON_HEIGHT = 56 * SCALING; + function drawButtons() { - let w = g.getWidth(); - let h = g.getHeight(); //Draw the backdrop - const BAR_TOP = h - 24; - g.setColor(0, 0, 1).setFontAlign(0, -1) - .clearRect(0, BAR_TOP, w, h) - .fillRect(0, BAR_TOP, w, h) + const BUTTON_TOP = H - BUTTON_HEIGHT; + const IMG_SIZE = 24; + const IMG_ANCHOR_Y = BUTTON_TOP + BUTTON_HEIGHT / 2 - IMG_SIZE / 2; + g.setColor(0, 0, 1) + .fillRect({x:0, y:BUTTON_TOP, x2:W-1, y2:H-1,r:15}) .setColor(1, 1, 1); if (!common.state.wasRunning) { //If the timer was never started, only show a play button - g.drawImage(common.BUTTON_ICONS.play, w / 2, BAR_TOP); + g.drawImage(common.BUTTON_ICONS.play, W / 2 - IMG_SIZE / 2, IMG_ANCHOR_Y); } else { - g.drawLine(w / 2, BAR_TOP, w / 2, h); + g.setColor(g.theme.bg) + .fillRect(W / 2 - 2, BUTTON_TOP, W / 2 + 2, H) + .setColor(1,1,1); if (common.state.running) { - g.drawImage(common.BUTTON_ICONS.pause, w / 4, BAR_TOP) - .drawImage(common.BUTTON_ICONS.skip, w * 3 / 4, BAR_TOP); + g.drawImage(common.BUTTON_ICONS.pause, W / 4 - IMG_SIZE / 2, IMG_ANCHOR_Y) + .drawImage(common.BUTTON_ICONS.skip, W * 3 / 4 - IMG_SIZE / 2, IMG_ANCHOR_Y); } else { - g.drawImage(common.BUTTON_ICONS.reset, w / 4, BAR_TOP) - .drawImage(common.BUTTON_ICONS.play, w * 3 / 4, BAR_TOP); + g.drawImage(common.BUTTON_ICONS.reset, W / 4 - IMG_SIZE / 2, IMG_ANCHOR_Y) + .drawImage(common.BUTTON_ICONS.play, W * 3 / 4 - IMG_SIZE / 2, IMG_ANCHOR_Y); } } } function drawTimerAndMessage() { - let w = g.getWidth(); - let h = g.getHeight(); + const ANCHOR_X = W / 2; + const ANCHOR_Y = H * 3 / 8; + const TIME_SIZE = 48 * SCALING; + const LABEL_SIZE = 18 * SCALING; g.reset() .setFontAlign(0, 0) - .setFont("Vector", 36) - .clearRect(w / 2 - 60, h / 2 - 34, w / 2 + 60, h / 2 + 34) + .setFont("Vector", TIME_SIZE) + .clearRect(0, ANCHOR_Y - TIME_SIZE / 2, W-1, ANCHOR_Y + TIME_SIZE / 2 + 1.2 * LABEL_SIZE) //Draw the timer .drawString((() => { @@ -59,17 +67,17 @@ function drawTimerAndMessage() { if (hours >= 1) return `${parseInt(hours)}:${pad(minutes)}:${pad(seconds)}`; else return `${parseInt(minutes)}:${pad(seconds)}`; - })(), w / 2, h / 2) + })(), ANCHOR_X, ANCHOR_Y) //Draw the phase label - .setFont("Vector", 12) + .setFont("Vector", LABEL_SIZE) .drawString(((currentPhase, numShortBreaks) => { if (!common.state.wasRunning) return "Not started"; else if (currentPhase == common.PHASE_WORKING) return `Work ${numShortBreaks + 1}/${common.settings.numShortBreaks + 1}` else if (currentPhase == common.PHASE_SHORT_BREAK) return `Short break ${numShortBreaks + 1}/${common.settings.numShortBreaks}`; else return "Long break!"; })(common.state.phase, common.state.numShortBreaks), - w / 2, h / 2 + 18); + ANCHOR_X, ANCHOR_Y + 2*LABEL_SIZE); //Update phase with vibation if needed if (common.getTimeLeft() <= 0) { @@ -81,7 +89,7 @@ drawButtons(); Bangle.on("touch", (button, xy) => { //If we support full touch and we're not touching the keys, ignore. //If we don't support full touch, we can't tell so just assume we are. - if (xy !== undefined && xy.y <= g.getHeight() - 24) return; + if (xy !== undefined && xy.y <= g.getHeight() - BUTTON_HEIGHT) return; if (!common.state.wasRunning) { //If we were never running, there is only one button: the start button diff --git a/apps/pomoplus/metadata.json b/apps/pomoplus/metadata.json index 4f2fd6cbb9..1fd65de166 100644 --- a/apps/pomoplus/metadata.json +++ b/apps/pomoplus/metadata.json @@ -1,7 +1,7 @@ { "id": "pomoplus", "name": "Pomodoro Plus", - "version": "0.06", + "version": "0.07", "description": "A configurable pomodoro timer that runs in the background.", "icon": "icon.png", "type": "app", From ffdfe98b92cbda40b0822c58649973689cfb0cf4 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sun, 25 Aug 2024 12:12:51 +0200 Subject: [PATCH 2/8] pomoplus: add README.md --- apps/pomoplus/README.md | 39 +++++++++++++++++++++++++++++++++++++ apps/pomoplus/metadata.json | 1 + 2 files changed, 40 insertions(+) create mode 100644 apps/pomoplus/README.md diff --git a/apps/pomoplus/README.md b/apps/pomoplus/README.md new file mode 100644 index 0000000000..0e8170f504 --- /dev/null +++ b/apps/pomoplus/README.md @@ -0,0 +1,39 @@ +# Pomodoro Plus + +> The Pomodoro Technique is a time management method developed by Francesco Cirillo in the late 1980s. It uses a kitchen timer to break work into intervals, typically 25 minutes in length, separated by short breaks. Each interval is known as a pomodoro, from the Italian word for tomato, after the tomato-shaped kitchen timer Cirillo used as a university student. +> +> The original technique has six steps: +> +> Decide on the task to be done. +> Set the Pomodoro timer (typically for 25 minutes). +> Work on the task. +> End work when the timer rings and take a short break (typically 5–10 minutes). +> Go back to Step 2 and repeat until you complete four pomodori. +> After four pomodori are done, take a long break (typically 20 to 30 minutes) instead of a short break. Once the long break is finished, return to step 2. + +*Description gathered from https://en.wikipedia.org/wiki/Pomodoro_Technique* + +## Usage + +- Click the play button to start a pomodoro and get to work! +- Click the pause button if you're interrupted with something urgent. +- Click the cross button if you need to end your work session. +- Click the skip button if you forgot to start the pomodori after the urgent interruption and ended up working for a long time! (Good on ya'!) + +Configure the pomodori and break times in the settings. + +## Features + +Continues to run in the background if you exit the app while the pomodoro timer is running. + +## Requests + +Open an issue on the espruino/BangleApps issue tracker. + +## Creator + +bruceblore + +## Contributors + +notEvil, thyttan diff --git a/apps/pomoplus/metadata.json b/apps/pomoplus/metadata.json index 1fd65de166..7b1efee2a7 100644 --- a/apps/pomoplus/metadata.json +++ b/apps/pomoplus/metadata.json @@ -10,6 +10,7 @@ "BANGLEJS", "BANGLEJS2" ], + "readme": "README.md", "storage": [ { "name": "pomoplus.app.js", From 65ab758beaddbd6b215696d8e5674eeb6144074d Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Tue, 27 Aug 2024 22:09:44 +0200 Subject: [PATCH 3/8] pomoplus: tweak var names, apply scaling to radius Also reword the comment regarding SCALING. --- apps/pomoplus/app.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/pomoplus/app.js b/apps/pomoplus/app.js index b4ff83cafb..6da7405798 100644 --- a/apps/pomoplus/app.js +++ b/apps/pomoplus/app.js @@ -16,30 +16,30 @@ if ( const W = g.getWidth(); const H = g.getHeight(); -const SCALING = W/176; // The UI was tweaked to look good on a Bangle.js 2 (176x176 px). SCALING is used to adapt with the resolution of whatever device the app is running on. +const SCALING = W/176; // The UI was tweaked to look good on a Bangle.js 2 (176x176 px). SCALING automatically adapts so elements have the same proportions relative to the screen size on devices with other resolutions. const BUTTON_HEIGHT = 56 * SCALING; function drawButtons() { //Draw the backdrop const BUTTON_TOP = H - BUTTON_HEIGHT; - const IMG_SIZE = 24; - const IMG_ANCHOR_Y = BUTTON_TOP + BUTTON_HEIGHT / 2 - IMG_SIZE / 2; + const ICONS_SIZE = 24; + const ICONS_ANCHOR_Y = BUTTON_TOP + BUTTON_HEIGHT / 2 - ICONS_SIZE / 2; g.setColor(0, 0, 1) - .fillRect({x:0, y:BUTTON_TOP, x2:W-1, y2:H-1,r:15}) + .fillRect({x:0, y:BUTTON_TOP, x2:W-1, y2:H-1,r:15*SCALING}) .setColor(1, 1, 1); if (!common.state.wasRunning) { //If the timer was never started, only show a play button - g.drawImage(common.BUTTON_ICONS.play, W / 2 - IMG_SIZE / 2, IMG_ANCHOR_Y); + g.drawImage(common.BUTTON_ICONS.play, W / 2 - ICONS_SIZE / 2, ICONS_ANCHOR_Y); } else { g.setColor(g.theme.bg) .fillRect(W / 2 - 2, BUTTON_TOP, W / 2 + 2, H) .setColor(1,1,1); if (common.state.running) { - g.drawImage(common.BUTTON_ICONS.pause, W / 4 - IMG_SIZE / 2, IMG_ANCHOR_Y) - .drawImage(common.BUTTON_ICONS.skip, W * 3 / 4 - IMG_SIZE / 2, IMG_ANCHOR_Y); + g.drawImage(common.BUTTON_ICONS.pause, W / 4 - ICONS_SIZE / 2, ICONS_ANCHOR_Y) + .drawImage(common.BUTTON_ICONS.skip, W * 3 / 4 - ICONS_SIZE / 2, ICONS_ANCHOR_Y); } else { - g.drawImage(common.BUTTON_ICONS.reset, W / 4 - IMG_SIZE / 2, IMG_ANCHOR_Y) - .drawImage(common.BUTTON_ICONS.play, W * 3 / 4 - IMG_SIZE / 2, IMG_ANCHOR_Y); + g.drawImage(common.BUTTON_ICONS.reset, W / 4 - ICONS_SIZE / 2, ICONS_ANCHOR_Y) + .drawImage(common.BUTTON_ICONS.play, W * 3 / 4 - ICONS_SIZE / 2, ICONS_ANCHOR_Y); } } } From 15f8906723781de6872411ab61bf4013ed5fca45 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Tue, 27 Aug 2024 23:48:15 +0200 Subject: [PATCH 4/8] pomoplus: hide buttons and widgets when locked --- apps/pomoplus/app.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/pomoplus/app.js b/apps/pomoplus/app.js index 6da7405798..0576547dc0 100644 --- a/apps/pomoplus/app.js +++ b/apps/pomoplus/app.js @@ -4,6 +4,7 @@ Bangle.POMOPLUS_ACTIVE = true; //Prevent the boot code from running. To avoid h const storage = require("Storage"); const common = require("pomoplus-com.js"); +const wu = require("widget_utils"); //Expire the state if necessary if ( @@ -18,10 +19,10 @@ const W = g.getWidth(); const H = g.getHeight(); const SCALING = W/176; // The UI was tweaked to look good on a Bangle.js 2 (176x176 px). SCALING automatically adapts so elements have the same proportions relative to the screen size on devices with other resolutions. const BUTTON_HEIGHT = 56 * SCALING; +const BUTTON_TOP = H - BUTTON_HEIGHT; function drawButtons() { //Draw the backdrop - const BUTTON_TOP = H - BUTTON_HEIGHT; const ICONS_SIZE = 24; const ICONS_ANCHOR_Y = BUTTON_TOP + BUTTON_HEIGHT / 2 - ICONS_SIZE / 2; g.setColor(0, 0, 1) @@ -85,7 +86,8 @@ function drawTimerAndMessage() { } } -drawButtons(); +if (!Bangle.isLocked()) drawButtons(); + Bangle.on("touch", (button, xy) => { //If we support full touch and we're not touching the keys, ignore. //If we don't support full touch, we can't tell so just assume we are. @@ -164,6 +166,17 @@ if (common.state.running) { setupTimerInterval(); } +Bangle.on('lock', (on, reason) => { + if (on) { + g.clearRect(0,BUTTON_TOP,W-1,H-1); + wu.hide(); + } + if (!on) { + drawButtons(); + wu.show(); + } +}); + //Save our state when the app is closed E.on('kill', () => { storage.writeJSON(common.STATE_PATH, common.state); @@ -171,3 +184,4 @@ E.on('kill', () => { Bangle.loadWidgets(); Bangle.drawWidgets(); +if (Bangle.isLocked()) wu.hide(); From 70be2ed03f82c1bea5070f00caa723e5f72ba573 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sat, 31 Aug 2024 21:55:24 +0200 Subject: [PATCH 5/8] pomoplus: HW button hide/show widgets + SW buttons --- apps/pomoplus/ChangeLog | 4 +++- apps/pomoplus/README.md | 3 +++ apps/pomoplus/app.js | 39 +++++++++++++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/apps/pomoplus/ChangeLog b/apps/pomoplus/ChangeLog index 6ce1bd59a9..327ce07c2b 100644 --- a/apps/pomoplus/ChangeLog +++ b/apps/pomoplus/ChangeLog @@ -2,4 +2,6 @@ 0.02-0.04: Bug fixes 0.05: Submitted to the app loader 0.06: Added setting to show clock after start/resume -0.07: Make fonts and buttons larger for legibility and ease of use. +0.07: Make fonts and buttons larger for legibility and ease of use. Hide + buttons when screen is locked. Toggle the graphical presentation when + pressing the (middle) hardware button. diff --git a/apps/pomoplus/README.md b/apps/pomoplus/README.md index 0e8170f504..20bc39a67e 100644 --- a/apps/pomoplus/README.md +++ b/apps/pomoplus/README.md @@ -19,6 +19,7 @@ - Click the pause button if you're interrupted with something urgent. - Click the cross button if you need to end your work session. - Click the skip button if you forgot to start the pomodori after the urgent interruption and ended up working for a long time! (Good on ya'!) +- Press the (middle) hardware button to toggle visibility of widgets and software buttons. Configure the pomodori and break times in the settings. @@ -26,6 +27,8 @@ Configure the pomodori and break times in the settings. Continues to run in the background if you exit the app while the pomodoro timer is running. +The buttons and widgets hide automatically when the screen is locked. + ## Requests Open an issue on the espruino/BangleApps issue tracker. diff --git a/apps/pomoplus/app.js b/apps/pomoplus/app.js index 0576547dc0..0c4e5a79a0 100644 --- a/apps/pomoplus/app.js +++ b/apps/pomoplus/app.js @@ -88,10 +88,34 @@ function drawTimerAndMessage() { if (!Bangle.isLocked()) drawButtons(); -Bangle.on("touch", (button, xy) => { +let hideButtons = ()=>{ + g.clearRect(0,BUTTON_TOP,W-1,H-1); +} + +let graphicState = 0; // 0 - all is visible, 1 - widgets are hidden, 2 - widgets and buttons are hidden. +let switchGraphicsOnButton = (n)=>{ + if (process.env.HWVERSION == 2) n=2; // Translate Bangle.js 2 button to Bangle.js 1 middle button. + if (n == 2) { + if (graphicState == 0) { + wu.hide(); + } + if (graphicState == 1) { + hideButtons(); + } + if (graphicState == 2) { + wu.show(); + drawButtons(); + } + + graphicState = (graphicState+1) % 3; + } +} + +let touchHandler = (button, xy) => { //If we support full touch and we're not touching the keys, ignore. //If we don't support full touch, we can't tell so just assume we are. - if (xy !== undefined && xy.y <= g.getHeight() - BUTTON_HEIGHT) return; + let isOutsideButtonArea = xy !== undefined && xy.y <= g.getHeight() - BUTTON_HEIGHT; + if (isOutsideButtonArea || graphicState == 2) return; if (!common.state.wasRunning) { //If we were never running, there is only one button: the start button @@ -147,7 +171,14 @@ Bangle.on("touch", (button, xy) => { if (common.settings.showClock) Bangle.showClock(); } } -}); +}; + +Bangle.setUI({ + mode: "custom", + touch: touchHandler, + btn: switchGraphicsOnButton + +}) let timerInterval; @@ -168,7 +199,7 @@ if (common.state.running) { Bangle.on('lock', (on, reason) => { if (on) { - g.clearRect(0,BUTTON_TOP,W-1,H-1); + hideButtons(); wu.hide(); } if (!on) { From f20683cc4e9e12de201c47f3d30ac8cb9add71d6 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sat, 31 Aug 2024 21:57:44 +0200 Subject: [PATCH 6/8] pomoplus: fix typo in readme --- apps/pomoplus/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/pomoplus/README.md b/apps/pomoplus/README.md index 20bc39a67e..98642debfd 100644 --- a/apps/pomoplus/README.md +++ b/apps/pomoplus/README.md @@ -18,7 +18,7 @@ - Click the play button to start a pomodoro and get to work! - Click the pause button if you're interrupted with something urgent. - Click the cross button if you need to end your work session. -- Click the skip button if you forgot to start the pomodori after the urgent interruption and ended up working for a long time! (Good on ya'!) +- Click the skip button if you forgot to start the pomodoro after the urgent interruption and ended up working for a long time! (Good on ya'!) - Press the (middle) hardware button to toggle visibility of widgets and software buttons. Configure the pomodori and break times in the settings. From ff3228c8f2fcbe64cc6c80df289c7fe13f5b1004 Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sat, 31 Aug 2024 22:23:05 +0200 Subject: [PATCH 7/8] pomoplus: refactor function names touchHandler -> onTouchSoftwareButtons switchGraphicsOnButton -> onButtonSwitchGraphics --- apps/pomoplus/app.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/pomoplus/app.js b/apps/pomoplus/app.js index 0c4e5a79a0..c587a3b730 100644 --- a/apps/pomoplus/app.js +++ b/apps/pomoplus/app.js @@ -93,7 +93,7 @@ let hideButtons = ()=>{ } let graphicState = 0; // 0 - all is visible, 1 - widgets are hidden, 2 - widgets and buttons are hidden. -let switchGraphicsOnButton = (n)=>{ +let onButtonSwitchGraphics = (n)=>{ if (process.env.HWVERSION == 2) n=2; // Translate Bangle.js 2 button to Bangle.js 1 middle button. if (n == 2) { if (graphicState == 0) { @@ -106,12 +106,11 @@ let switchGraphicsOnButton = (n)=>{ wu.show(); drawButtons(); } - graphicState = (graphicState+1) % 3; } } -let touchHandler = (button, xy) => { +let onTouchSoftwareButtons = (button, xy) => { //If we support full touch and we're not touching the keys, ignore. //If we don't support full touch, we can't tell so just assume we are. let isOutsideButtonArea = xy !== undefined && xy.y <= g.getHeight() - BUTTON_HEIGHT; @@ -175,9 +174,8 @@ let touchHandler = (button, xy) => { Bangle.setUI({ mode: "custom", - touch: touchHandler, - btn: switchGraphicsOnButton - + touch: onTouchSoftwareButtons, + btn: onButtonSwitchGraphics }) let timerInterval; From d7f7d2b95d8e66ff89cae32d44a0e460907666bb Mon Sep 17 00:00:00 2001 From: thyttan <6uuxstm66@mozmail.com⁩> Date: Sat, 31 Aug 2024 22:43:39 +0200 Subject: [PATCH 8/8] pomoplus: fix unintentional redraws when unlocking --- apps/pomoplus/app.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/pomoplus/app.js b/apps/pomoplus/app.js index c587a3b730..56275efb46 100644 --- a/apps/pomoplus/app.js +++ b/apps/pomoplus/app.js @@ -196,13 +196,14 @@ if (common.state.running) { } Bangle.on('lock', (on, reason) => { + if (graphicState==2) return; if (on) { hideButtons(); wu.hide(); } if (!on) { drawButtons(); - wu.show(); + if (graphicState==0) wu.show(); } });