mirror of https://github.com/espruino/BangleApps
Merge pull request #1970 from pebl-hank/HanksWorldClock
Hanks world clock - Add settingspull/1987/head
commit
9d8f70b0f0
|
@ -3,4 +3,5 @@
|
||||||
0.17: Fix hours
|
0.17: Fix hours
|
||||||
0.18: Code cleanup and major changes with seconds timing. New feature: if watch is locked, seconds get refreshed every 10 seconds.
|
0.18: Code cleanup and major changes with seconds timing. New feature: if watch is locked, seconds get refreshed every 10 seconds.
|
||||||
0.19: Fix PM Hours
|
0.19: Fix PM Hours
|
||||||
0.20: Add theme support
|
0.20: Add theme support
|
||||||
|
0.21: Add Settings
|
|
@ -1,3 +1,10 @@
|
||||||
|
// ------- Settings file
|
||||||
|
const SETTINGSFILE = "hworldclock.json";
|
||||||
|
var secondsMode;
|
||||||
|
var showSunInfo;
|
||||||
|
var colorWhenDark;
|
||||||
|
// ------- Settings file
|
||||||
|
|
||||||
const big = g.getWidth()>200;
|
const big = g.getWidth()>200;
|
||||||
// Font for primary time and date
|
// Font for primary time and date
|
||||||
const primaryTimeFontSize = big?6:5;
|
const primaryTimeFontSize = big?6:5;
|
||||||
|
@ -66,6 +73,11 @@ const mockOffsets = {
|
||||||
],
|
],
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
|
|
||||||
|
// Example hworldclock.settings.json
|
||||||
|
// [["London","0"],["NY","-5"],["Denver","-6"]]
|
||||||
|
|
||||||
|
|
||||||
// Uncomment one at a time to test various offsets array scenarios
|
// Uncomment one at a time to test various offsets array scenarios
|
||||||
//offsets = mockOffsets.zeroOffsets; // should render nothing below primary time
|
//offsets = mockOffsets.zeroOffsets; // should render nothing below primary time
|
||||||
//offsets = mockOffsets.oneOffset; // should render larger in two rows
|
//offsets = mockOffsets.oneOffset; // should render larger in two rows
|
||||||
|
@ -73,6 +85,19 @@ const mockOffsets = {
|
||||||
//offsets = mockOffsets.fourOffsets; // should render in columns
|
//offsets = mockOffsets.fourOffsets; // should render in columns
|
||||||
|
|
||||||
// END TESTING CODE
|
// END TESTING CODE
|
||||||
|
|
||||||
|
|
||||||
|
// Load settings
|
||||||
|
function loadMySettings() {
|
||||||
|
// Helper function default setting
|
||||||
|
function def (value, def) {return value !== undefined ? value : def;}
|
||||||
|
|
||||||
|
var settings = require('Storage').readJSON(SETTINGSFILE, true) || {};
|
||||||
|
secondsMode = def(settings.secondsMode, "when unlocked");
|
||||||
|
showSunInfo = def(settings.showSunInfo, true);
|
||||||
|
colorWhenDark = def(settings.colorWhenDark, "green");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Check settings for what type our clock should be
|
// Check settings for what type our clock should be
|
||||||
var _12hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]||false;
|
var _12hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]||false;
|
||||||
|
@ -139,13 +164,17 @@ function drawSeconds() {
|
||||||
|
|
||||||
g.setFont("5x9Numeric7Seg",primaryTimeFontSize - 3);
|
g.setFont("5x9Numeric7Seg",primaryTimeFontSize - 3);
|
||||||
if (g.theme.dark) {
|
if (g.theme.dark) {
|
||||||
g.setColor("#22ff05");
|
if (colorWhenDark == "green") {
|
||||||
|
g.setColor("#22ff05");
|
||||||
|
} else {
|
||||||
|
g.setColor(g.theme.fg);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
g.setColor(g.theme.fg);
|
g.setColor(g.theme.fg);
|
||||||
}
|
}
|
||||||
//console.log("---");
|
//console.log("---");
|
||||||
//console.log(seconds);
|
//console.log(seconds);
|
||||||
if (Bangle.isLocked()) seconds = seconds.slice(0, -1) + ':::'; // we use :: as the font does not have an x
|
if (Bangle.isLocked() && secondsMode != "always") seconds = seconds.slice(0, -1) + ':::'; // we use :: as the font does not have an x
|
||||||
//console.log(seconds);
|
//console.log(seconds);
|
||||||
g.drawString(`${seconds}`, xyCenterSeconds, yposTime+14, true);
|
g.drawString(`${seconds}`, xyCenterSeconds, yposTime+14, true);
|
||||||
queueDrawSeconds();
|
queueDrawSeconds();
|
||||||
|
@ -184,7 +213,11 @@ function draw() {
|
||||||
//g.setFont(font, primaryTimeFontSize);
|
//g.setFont(font, primaryTimeFontSize);
|
||||||
g.setFont("5x9Numeric7Seg",primaryTimeFontSize);
|
g.setFont("5x9Numeric7Seg",primaryTimeFontSize);
|
||||||
if (g.theme.dark) {
|
if (g.theme.dark) {
|
||||||
g.setColor("#22ff05");
|
if (colorWhenDark == "green") {
|
||||||
|
g.setColor("#22ff05");
|
||||||
|
} else {
|
||||||
|
g.setColor(g.theme.fg);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
g.setColor(g.theme.fg);
|
g.setColor(g.theme.fg);
|
||||||
}
|
}
|
||||||
|
@ -198,7 +231,7 @@ function draw() {
|
||||||
g.drawString(ampm, xyCenterSeconds, yAmPm, true);
|
g.drawString(ampm, xyCenterSeconds, yAmPm, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawSeconds(); // To make sure...
|
if (secondsMode != "none") drawSeconds(); // To make sure...
|
||||||
|
|
||||||
// draw Day, name of month, Date
|
// draw Day, name of month, Date
|
||||||
//DATE
|
//DATE
|
||||||
|
@ -245,19 +278,31 @@ function draw() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
g.setFontAlign(-1, 0);
|
if (showSunInfo) {
|
||||||
g.setFont("Vector",12);
|
g.setFontAlign(-1, 0);
|
||||||
g.drawString(`^${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset
|
g.setFont("Vector",12);
|
||||||
g.setFontAlign(1, 0);
|
g.drawString(`^${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset
|
||||||
g.drawString(`v${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw riseset
|
g.setFontAlign(1, 0);
|
||||||
|
g.drawString(`v${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw riseset
|
||||||
|
}
|
||||||
|
//debug settings
|
||||||
|
//g.setFontAlign(1, 0);
|
||||||
|
//g.drawString(secondsMode, xcol2, 3 + yposWorld + 3 * 15, true);
|
||||||
|
//g.drawString(showSunInfo, xcol2, 3 + yposWorld + 3 * 15, true);
|
||||||
|
//g.drawString(colorWhenDark, xcol2, 3 + yposWorld + 3 * 15, true);
|
||||||
|
|
||||||
|
|
||||||
queueDraw();
|
queueDraw();
|
||||||
queueDrawSeconds();
|
|
||||||
|
if (secondsMode != "none") queueDrawSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
// clean app screen
|
// clean app screen
|
||||||
g.clear();
|
g.clear();
|
||||||
|
|
||||||
|
// Init the settings of the app
|
||||||
|
loadMySettings();
|
||||||
|
|
||||||
// Show launcher when button pressed
|
// Show launcher when button pressed
|
||||||
Bangle.setUI("clock");
|
Bangle.setUI("clock");
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
|
@ -269,28 +314,38 @@ draw();
|
||||||
|
|
||||||
|
|
||||||
if (!Bangle.isLocked()) { // Initial state
|
if (!Bangle.isLocked()) { // Initial state
|
||||||
if (PosInterval != 0) clearInterval(PosInterval);
|
if (showSunInfo) {
|
||||||
PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins
|
if (PosInterval != 0) clearInterval(PosInterval);
|
||||||
|
PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins
|
||||||
|
}
|
||||||
|
|
||||||
secondsTimeout = 1000;
|
secondsTimeout = 1000;
|
||||||
|
if (secondsMode != "none") {
|
||||||
|
if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
|
||||||
|
drawTimeoutSeconds = undefined;
|
||||||
|
}
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
|
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
drawTimeoutSeconds = undefined;
|
|
||||||
|
|
||||||
draw(); // draw immediately, queue redraw
|
draw(); // draw immediately, queue redraw
|
||||||
updatePos();
|
if (showSunInfo) updatePos();
|
||||||
}else{
|
}else{
|
||||||
secondsTimeout = 10 * 1000;
|
if (secondsMode == "always") secondsTimeout = 1000;
|
||||||
|
if (secondsMode == "when unlocked") secondsTimeout = 10 * 1000;
|
||||||
|
|
||||||
|
if (secondsMode != "none") {
|
||||||
|
if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
|
||||||
|
drawTimeoutSeconds = undefined;
|
||||||
|
}
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
|
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
drawTimeoutSeconds = undefined;
|
|
||||||
|
|
||||||
if (PosInterval != 0) clearInterval(PosInterval);
|
if (showSunInfo) {
|
||||||
PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins
|
if (PosInterval != 0) clearInterval(PosInterval);
|
||||||
|
PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins
|
||||||
|
}
|
||||||
draw(); // draw immediately, queue redraw
|
draw(); // draw immediately, queue redraw
|
||||||
updatePos();
|
if (showSunInfo) updatePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -299,29 +354,36 @@ if (!Bangle.isLocked()) { // Initial state
|
||||||
|
|
||||||
Bangle.on('lock',on=>{
|
Bangle.on('lock',on=>{
|
||||||
if (!on) { // UNlocked
|
if (!on) { // UNlocked
|
||||||
|
if (showSunInfo) {
|
||||||
if (PosInterval != 0) clearInterval(PosInterval);
|
if (PosInterval != 0) clearInterval(PosInterval);
|
||||||
PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins
|
PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins
|
||||||
|
}
|
||||||
|
|
||||||
secondsTimeout = 1000;
|
secondsTimeout = 1000;
|
||||||
|
if (secondsMode != "none") {
|
||||||
|
if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
|
||||||
|
drawTimeoutSeconds = undefined;
|
||||||
|
}
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
|
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
drawTimeoutSeconds = undefined;
|
|
||||||
|
|
||||||
draw(); // draw immediately, queue redraw
|
draw(); // draw immediately, queue redraw
|
||||||
updatePos();
|
if (showSunInfo) updatePos();
|
||||||
}else{ // locked
|
}else{ // locked
|
||||||
|
|
||||||
secondsTimeout = 10 * 1000;
|
if (secondsMode == "always") secondsTimeout = 1000;
|
||||||
|
if (secondsMode == "when unlocked") secondsTimeout = 10 * 1000;
|
||||||
|
|
||||||
|
if (secondsMode != "none") {
|
||||||
|
if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
|
||||||
|
drawTimeoutSeconds = undefined;
|
||||||
|
}
|
||||||
if (drawTimeout) clearTimeout(drawTimeout);
|
if (drawTimeout) clearTimeout(drawTimeout);
|
||||||
if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds);
|
|
||||||
drawTimeout = undefined;
|
drawTimeout = undefined;
|
||||||
drawTimeoutSeconds = undefined;
|
|
||||||
|
|
||||||
if (PosInterval != 0) clearInterval(PosInterval);
|
if (PosInterval != 0) clearInterval(PosInterval);
|
||||||
PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins
|
PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins
|
||||||
draw(); // draw immediately, queue redraw
|
draw(); // draw immediately, queue redraw
|
||||||
updatePos();
|
if (showSunInfo) updatePos();
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "hworldclock",
|
"id": "hworldclock",
|
||||||
"name": "Hanks World Clock",
|
"name": "Hanks World Clock",
|
||||||
"shortName": "Hanks World Clock",
|
"shortName": "Hanks World Clock",
|
||||||
"version": "0.20",
|
"version": "0.21",
|
||||||
"description": "Current time zone plus up to three others",
|
"description": "Current time zone plus up to three others",
|
||||||
"allow_emulator":true,
|
"allow_emulator":true,
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
|
@ -15,7 +15,11 @@
|
||||||
"storage": [
|
"storage": [
|
||||||
{"name":"hworldclock.app.js","url":"app.js"},
|
{"name":"hworldclock.app.js","url":"app.js"},
|
||||||
{"name":"hworldclock.img","url":"hworldclock-icon.js","evaluate":true},
|
{"name":"hworldclock.img","url":"hworldclock-icon.js","evaluate":true},
|
||||||
|
{"name":"hworldclock.settings.js","url":"settings.js"},
|
||||||
{"name":"hsuncalc.js","url":"hsuncalc.js"}
|
{"name":"hsuncalc.js","url":"hsuncalc.js"}
|
||||||
],
|
],
|
||||||
"data": [{"name":"hworldclock.settings.json"}]
|
"data": [
|
||||||
}
|
{"name":"hworldclock.settings.json"},
|
||||||
|
{"name":"hworldclock.json"}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
// Settings menu for the enhanced Anton clock
|
||||||
|
|
||||||
|
(function(back) {
|
||||||
|
var FILE = "hworldclock.json";
|
||||||
|
// Load settings
|
||||||
|
var settings = Object.assign({
|
||||||
|
secondsOnUnlock: false,
|
||||||
|
}, require('Storage').readJSON(FILE, true) || {});
|
||||||
|
|
||||||
|
function writeSettings() {
|
||||||
|
require('Storage').writeJSON(FILE, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper method which uses int-based menu item for set of string values
|
||||||
|
function stringItems(startvalue, writer, values) {
|
||||||
|
return {
|
||||||
|
value: (startvalue === undefined ? 0 : values.indexOf(startvalue)),
|
||||||
|
format: v => values[v],
|
||||||
|
min: 0,
|
||||||
|
max: values.length - 1,
|
||||||
|
wrap: true,
|
||||||
|
step: 1,
|
||||||
|
onchange: v => {
|
||||||
|
writer(values[v]);
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper method which breaks string set settings down to local settings object
|
||||||
|
function stringInSettings(name, values) {
|
||||||
|
return stringItems(settings[name], v => settings[name] = v, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
var mainmenu = {
|
||||||
|
"": {
|
||||||
|
"title": "Hanks World Clock"
|
||||||
|
},
|
||||||
|
"< Back": () => back(),
|
||||||
|
"Seconds": stringInSettings("secondsMode", ["always", "when unlocked", "none"]),
|
||||||
|
"Color w. dark": stringInSettings("colorWhenDark", ["green", "default"]),
|
||||||
|
"Show SunInfo": {
|
||||||
|
value: (settings.showSunInfo !== undefined ? settings.showSunInfo : true),
|
||||||
|
format: v => v ? "On" : "Off",
|
||||||
|
onchange: v => {
|
||||||
|
settings.showSunInfo = v;
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Actually display the menu
|
||||||
|
E.showMenu(mainmenu);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// end of file
|
Loading…
Reference in New Issue