Added Settings for Color scheme

pull/857/head
Thomas ICHÉ 2021-08-20 15:49:13 +02:00
parent 1592bcb1a5
commit 4d933ed959
5 changed files with 76 additions and 10 deletions

View File

@ -3390,13 +3390,14 @@
{ "id": "hcclock",
"name": "Hi-Contrast Clock",
"icon": "hcclock-icon.png",
"version":"0.01",
"version":"0.02",
"description": "Hi-Contrast Clock : A simple yet very bold clock that aims to be readable in high luninosity environments. Uses big 10x5 pixel digits. Use BTN 1 to switch background and foreground colors.",
"tags": "clock",
"type":"clock",
"allow_emulator":true,
"storage": [
{"name":"hcclock.app.js","url":"hcclock.app.js"},
{"name":"hcclock.settings.js","url":"hcclock.settings.js"},
{"name":"hcclock.img","url":"hcclock-icon.js","evaluate":true}
]
},

View File

@ -1,2 +1,2 @@
0.01: base code
0.02: added settings for color schemes

View File

@ -174,19 +174,52 @@ function fmtDate(day,month,year,hour)
let ap = "(AM)";
if(hour == 0 || hour > 12)
ap = "(PM)";
return months[month] + " " + day + " " + year + " "+ ap;
return months[month] + " " + day + " " + year + " "+ ap;
}
else
return months[month] + ". " + day + " " + year;
}
// Handles Flipping colors, then refreshes the UI
//////////////////////////////////////////
//
// HANDLE COLORS + SETTINGS
//
function getColorScheme()
{
let settings = require('Storage').readJSON("hcclock.json", true) || {};
if (!("scheme" in settings)) {
settings.scheme = 0;
}
return settings.scheme;
}
function setColorScheme(value)
{
let settings = require('Storage').readJSON("hcclock.json", true) || {};
settings.scheme = value;
require('Storage').writeJSON('hcclock.json', settings);
if(value == 0) // White
{
bg = 255;
fg = 0;
}
else // Black
{
bg = 0;
fg = 255;
}
redraw();
}
function flipColors()
{
let t = bg;
bg = fg;
fg = t;
redraw();
if(getColorScheme() == 0)
setColorScheme(1);
else
setColorScheme(0);
}
//////////////////////////////////////////
@ -197,7 +230,7 @@ function flipColors()
// Initialize
g.clear();
Bangle.loadWidgets();
redraw();
setColorScheme(getColorScheme());
// Define Refresh Interval
setInterval(updateTime, interval);

View File

@ -0,0 +1,32 @@
(function(back) {
function getColorScheme()
{
let settings = require('Storage').readJSON("hcclock.json", true) || {};
if (!("scheme" in settings)) {
settings.scheme = 0;
}
return settings.scheme;
}
function setColorScheme(value)
{
let settings = require('Storage').readJSON("hcclock.json", true) || {};
settings.scheme = value? 1 : 0;
require('Storage').writeJSON('hcclock.json', settings);
}
function setIcon(visible) {
updateSetting('showIcon', visible);
}
var mainmenu = {
"" : { "title" : "Hi-Contrast Clock" },
"Color Scheme" : {
value: getColorScheme,
format: v => v == 0?"White":"Black",
onchange: setColorScheme
},
"< Back" : back,
};
E.showMenu(mainmenu);
})

2
core

@ -1 +1 @@
Subproject commit 27f9a7125146a38c4357d679ec783f6e98a983c6
Subproject commit 8d9a012d62d40aae1b2304d0149440fb3c022393