Merge pull request #2471 from peerdavid/master

[BW Clock] Added option to only show the time as well as the week number.
pull/2476/head
Gordon Williams 2023-01-09 10:01:36 +00:00 committed by GitHub
commit 75dd5c0d84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 13 deletions

View File

@ -27,3 +27,4 @@
0.26: Use clkinfo.addInteractive instead of a custom implementation
0.27: Clean out some leftovers in the remove function after switching to
clkinfo.addInteractive that would cause ReferenceError.
0.28: Option to show (1) time only and (2) week of year.

View File

@ -3,16 +3,14 @@ A very minimalistic clock.
![](screenshot.png)
## ToDos and known issues
- [ ] The clkinfo is always shown and its, therefore, not possible to only show the time as shown in the screenshot.
- [ ] The weeknumber is currently not an option in clkinfo.
- [ ] Its not possible to run clkinfo items (e.g. trigger home assistant).
## Features
The BW clock implements features that are exposed by other apps through the `clkinfo` module.
For example, if you install the HomeAssistant app, this menu item will be shown if you first
touch the bottom of the screen and then swipe left/right to the home assistant menu. To select
sub-items simply swipe up/down.
sub-items simply swipe up/down. To run an action (e.g. trigger home assistant), simply select the clkinfo (border) and touch on the item again. See also the screenshot below:
![](screenshot_3.png)
## Settings
- Screen: Normal (widgets shown), Dynamic (widgets shown if unlocked) or Full (widgets are hidden).

View File

@ -100,12 +100,45 @@ let imgLock = function() {
* Clock Info
*/
let clockInfoItems = clock_info.load();
// Add some custom clock-infos
let weekOfYear = function() {
var date = new Date();
date.setHours(0, 0, 0, 0);
// Thursday in current week decides the year.
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
// January 4 is always in week 1.
var week1 = new Date(date.getFullYear(), 0, 4);
// Adjust to Thursday in week 1 and count number of weeks from date to week1.
return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000
- 3 + (week1.getDay() + 6) % 7) / 7);
}
clockInfoItems[0].items.unshift({ name : "weekofyear",
get : function() { return { text : "Week " + weekOfYear(),
img : null}},
show : function() {},
hide : function() {},
})
// Empty for large time
clockInfoItems[0].items.unshift({ name : "nop",
get : function() { return { text : null,
img : null}},
show : function() {},
hide : function() {},
})
let clockInfoMenu = clock_info.addInteractive(clockInfoItems, {
x : 0,
y: 135,
w: W,
h: H-135,
draw : (itm, info, options) => {
var hideClkInfo = info.text == null;
g.setColor(g.theme.fg);
g.fillRect(options.x, options.y, options.x+options.w, options.y+options.h);
@ -113,8 +146,17 @@ let clockInfoMenu = clock_info.addInteractive(clockInfoItems, {
g.setColor(g.theme.bg);
if (options.focus){
g.drawRect(options.x, options.y, options.x+options.w-2, options.y+options.h-1); // show if focused
g.drawRect(options.x+1, options.y+1, options.x+options.w-3, options.y+options.h-2); // show if focused
var y = hideClkInfo ? options.y+20 : options.y+2;
var h = hideClkInfo ? options.h-20 : options.h-2;
g.drawRect(options.x, y, options.x+options.w-2, y+h-1); // show if focused
g.drawRect(options.x+1, y+1, options.x+options.w-3, y+h-2); // show if focused
}
// In case we hide the clkinfo, we show the time again as the time should
// be drawn larger.
if(hideClkInfo){
drawTime();
return;
}
// Set text and font
@ -137,6 +179,11 @@ let clockInfoMenu = clock_info.addInteractive(clockInfoItems, {
g.drawImage(image, midx-parseInt(imgWidth*1.3/2)-parseInt(strWidth/2), options.y+6, {scale: scale});
}
g.drawString(text, midx+parseInt(imgWidth*1.3/2), options.y+20);
// In case we are in focus and the focus box changes (fullscreen yes/no)
// we draw the time again. Otherwise it could happen that a while line is
// not cleared correctly.
if(options.focus) drawTime();
}
});
@ -187,6 +234,8 @@ let drawDate = function() {
let drawTime = function() {
var hideClkInfo = clockInfoMenu.menuA == 0 && clockInfoMenu.menuB == 0;
// Draw background
var y1 = getLineY();
var y = y1;
@ -199,13 +248,19 @@ let drawTime = function() {
var timeStr = hours + colon + minutes;
// Set y coordinates correctly
y += parseInt((H - y)/2)-10;
y += parseInt((H - y)/2) + 5;
// Clear region
if (hideClkInfo){
g.setLargeFont();
} else {
y -= 15;
g.setMediumFont();
}
// Clear region and draw time
g.setColor(g.theme.fg);
g.fillRect(0,y1,W,y+20);
g.fillRect(0,y1,W,y+20 + (hideClkInfo ? 1 : 0) + (isFullscreen() ? 3 : 0));
g.setMediumFont();
g.setColor(g.theme.bg);
g.setFontAlign(0,0);
g.drawString(timeStr, W/2, y);
@ -270,6 +325,14 @@ let lockListenerBw = function(isLocked) {
};
Bangle.on('lock', lockListenerBw);
let charging = function(charging){
// Jump to battery
clockInfoMenu.menuA = 0;
clockInfoMenu.menuB = 2;
clockInfoMenu.redraw();
drawTime();
}
Bangle.on('charging', charging);
let kill = function(){
clockInfoMenu.remove();
@ -294,6 +357,7 @@ Bangle.setUI({
// Called to unload all of the clock app
Bangle.removeListener('lcdPower', lcdListenerBw);
Bangle.removeListener('lock', lockListenerBw);
Bangle.removeListener('charging', charging);
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
// save settings

View File

@ -1,7 +1,7 @@
{
"id": "bwclk",
"name": "BW Clock",
"version": "0.27",
"version": "0.28",
"description": "A very minimalistic clock.",
"readme": "README.md",
"icon": "app.png",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB