From 9cd7106f38ebfe36dc6ff5b8446a81f1c784e5b7 Mon Sep 17 00:00:00 2001 From: Hank Date: Wed, 7 Dec 2022 10:27:29 +0100 Subject: [PATCH 1/2] Add Rotation on swipe Down --- apps/hworldclock/ChangeLog | 1 + apps/hworldclock/README.md | 1 + apps/hworldclock/app.js | 52 ++++++++++++++++++++++++++++++++++ apps/hworldclock/metadata.json | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/apps/hworldclock/ChangeLog b/apps/hworldclock/ChangeLog index 8c1517842..158ea1c91 100644 --- a/apps/hworldclock/ChangeLog +++ b/apps/hworldclock/ChangeLog @@ -9,3 +9,4 @@ 0.23: Added note to configure position in "my location" if not done yet. Small fixes. 0.24: Added fast load 0.25: Minor code optimization +0.26: Swipe down to rotate 180° diff --git a/apps/hworldclock/README.md b/apps/hworldclock/README.md index 25cc368ca..073a7c8a9 100644 --- a/apps/hworldclock/README.md +++ b/apps/hworldclock/README.md @@ -14,6 +14,7 @@ Provide names and the UTC offsets for up to three other timezones in the app sto The clock does not handle summer time / daylight saving time changes automatically. If one of your three locations changes its UTC offset, you can simply change the setting in the app store and update. Currently the clock only supports 24 hour time format for the additional time zones. +Swipe down to rotate screen. So you can show the time to a friend real quick. ## Requests diff --git a/apps/hworldclock/app.js b/apps/hworldclock/app.js index c80b712da..c5e1942a5 100644 --- a/apps/hworldclock/app.js +++ b/apps/hworldclock/app.js @@ -7,6 +7,7 @@ var showSunInfo; var colorWhenDark; // ------- Settings file +const BANGLEJS2 = process.env.HWVERSION == 2; const big = g.getWidth()>200; // Font for primary time and date const primaryTimeFontSize = big?6:5; @@ -24,6 +25,7 @@ const xcol1 = 10; const xcol2 = g.getWidth() - xcol1; const font = "6x8"; +let drag; /* TODO: we could totally use 'Layout' here and avoid a whole bunch of hard-coded offsets */ @@ -317,6 +319,56 @@ Bangle.drawWidgets(); draw(); + +function initDragEvents() { + +if (BANGLEJS2) { + Bangle.on("drag", e => { + if (!drag) { // start dragging + drag = {x: e.x, y: e.y}; + } else if (!e.b) { // released + const dx = e.x-drag.x, dy = e.y-drag.y; + drag = null; + if (Math.abs(dx)>Math.abs(dy)+10) { + // horizontal + if (dx < dy) { + + } else { + + } + } else if (Math.abs(dy)>Math.abs(dx)+10) { + // vertical + if (dx < dy) { + g.clear().setRotation(2); + //console.log(" + draw(); + Bangle.loadWidgets(); + Bangle.drawWidgets(); + + } else { + g.clear().setRotation(0); + draw(); + Bangle.loadWidgets(); + Bangle.drawWidgets(); + } + } else { + //console.log("tap " + e.x + " " + e.y); + if (e.x > 145 && e.y > 145) { + + } + } + } + }); + } else { + //setWatch(addDrink, BTN1, { repeat: true, debounce:50 }); + //setWatch(removeDrink, BTN3, { repeat: true, debounce:50 }); + //setWatch(previousDrink, BTN4, { repeat: true, debounce:50 }); + //setWatch(nextDrink, BTN5, { repeat: true, debounce:50 }); + } +} + +initDragEvents(); + if (!Bangle.isLocked()) { // Initial state if (showSunInfo) { if (PosInterval != 0 && typeof PosInterval != 'undefined') clearInterval(PosInterval); diff --git a/apps/hworldclock/metadata.json b/apps/hworldclock/metadata.json index e26599373..7dba8f752 100644 --- a/apps/hworldclock/metadata.json +++ b/apps/hworldclock/metadata.json @@ -2,7 +2,7 @@ "id": "hworldclock", "name": "Hanks World Clock", "shortName": "Hanks World Clock", - "version": "0.25", + "version": "0.26", "description": "Current time zone plus up to three others", "allow_emulator":true, "icon": "app.png", From 383f18f92facbf8a4ea44bad2f8ea9ce0f763f6a Mon Sep 17 00:00:00 2001 From: Hank Date: Wed, 7 Dec 2022 12:18:14 +0100 Subject: [PATCH 2/2] Tidy up --- apps/hworldclock/ChangeLog | 2 +- apps/hworldclock/README.md | 2 +- apps/hworldclock/app.js | 17 +++++++---------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/apps/hworldclock/ChangeLog b/apps/hworldclock/ChangeLog index 158ea1c91..7b97ce527 100644 --- a/apps/hworldclock/ChangeLog +++ b/apps/hworldclock/ChangeLog @@ -9,4 +9,4 @@ 0.23: Added note to configure position in "my location" if not done yet. Small fixes. 0.24: Added fast load 0.25: Minor code optimization -0.26: Swipe down to rotate 180° +0.26: BJS2: Swipe down to rotate 180 degree diff --git a/apps/hworldclock/README.md b/apps/hworldclock/README.md index 073a7c8a9..5a1bcc7f0 100644 --- a/apps/hworldclock/README.md +++ b/apps/hworldclock/README.md @@ -14,7 +14,7 @@ Provide names and the UTC offsets for up to three other timezones in the app sto The clock does not handle summer time / daylight saving time changes automatically. If one of your three locations changes its UTC offset, you can simply change the setting in the app store and update. Currently the clock only supports 24 hour time format for the additional time zones. -Swipe down to rotate screen. So you can show the time to a friend real quick. +BangleJS2: Swipe down to rotate screen. So you can show the time to a friend real quick. ## Requests diff --git a/apps/hworldclock/app.js b/apps/hworldclock/app.js index c5e1942a5..fd9b9270f 100644 --- a/apps/hworldclock/app.js +++ b/apps/hworldclock/app.js @@ -332,19 +332,17 @@ if (BANGLEJS2) { if (Math.abs(dx)>Math.abs(dy)+10) { // horizontal if (dx < dy) { - + // for later purpose } else { - + // for later purpose } } else if (Math.abs(dy)>Math.abs(dx)+10) { // vertical if (dx < dy) { g.clear().setRotation(2); - //console.log(" draw(); Bangle.loadWidgets(); Bangle.drawWidgets(); - } else { g.clear().setRotation(0); draw(); @@ -354,16 +352,16 @@ if (BANGLEJS2) { } else { //console.log("tap " + e.x + " " + e.y); if (e.x > 145 && e.y > 145) { - + // for later purpose } } } }); } else { - //setWatch(addDrink, BTN1, { repeat: true, debounce:50 }); - //setWatch(removeDrink, BTN3, { repeat: true, debounce:50 }); - //setWatch(previousDrink, BTN4, { repeat: true, debounce:50 }); - //setWatch(nextDrink, BTN5, { repeat: true, debounce:50 }); + //setWatch(xxx, BTN1, { repeat: true, debounce:50 }); // maybe adding this later + //setWatch(xxx, BTN3, { repeat: true, debounce:50 }); + //setWatch(xxx, BTN4, { repeat: true, debounce:50 }); + //setWatch(xxx, BTN5, { repeat: true, debounce:50 }); } } @@ -402,7 +400,6 @@ if (!Bangle.isLocked()) { // Initial state updatePos(); } draw(); // draw immediately, queue redraw - }