mirror of https://github.com/espruino/BangleApps
CalClock: Version 0.5
- Use event colors - Improved all day event supportpull/2328/head
parent
e8163a6f14
commit
52d71ab0ca
|
@ -2,3 +2,4 @@
|
||||||
0.02: More compact rendering & app icon
|
0.02: More compact rendering & app icon
|
||||||
0.03: Tell clock widgets to hide.
|
0.03: Tell clock widgets to hide.
|
||||||
0.04: Improve current time readability in light theme.
|
0.04: Improve current time readability in light theme.
|
||||||
|
0.05: Show calendar colors & improved all day events.
|
||||||
|
|
|
@ -20,41 +20,55 @@ function zp(str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawEventHeader(event, y) {
|
function drawEventHeader(event, y) {
|
||||||
g.setFont("Vector", 24);
|
var x = 0;
|
||||||
|
|
||||||
var time = isActive(event) ? new Date() : new Date(event.timestamp * 1000);
|
var time = isActive(event) ? new Date() : new Date(event.timestamp * 1000);
|
||||||
var timeStr = zp(time.getHours()) + ":" + zp(time.getMinutes());
|
|
||||||
g.drawString(timeStr, 5, y);
|
//Don't need to know what time the event is at if its all day
|
||||||
y += 24;
|
if (isActive(event) || !event.allDay) {
|
||||||
|
g.setFont("Vector", 24);
|
||||||
|
var timeStr = zp(time.getHours()) + ":" + zp(time.getMinutes());
|
||||||
|
g.drawString(timeStr, 0, y);
|
||||||
|
y += 3;
|
||||||
|
x = 13*timeStr.length+5;
|
||||||
|
}
|
||||||
|
|
||||||
g.setFont("12x20", 1);
|
g.setFont("12x20", 1);
|
||||||
|
|
||||||
if (isActive(event)) {
|
if (isActive(event)) {
|
||||||
g.drawString(zp(time.getDate())+". " + require("locale").month(time,1),15*timeStr.length,y-21);
|
g.drawString(zp(time.getDate())+". " + require("locale").month(time,1),x,y);
|
||||||
} else {
|
} else {
|
||||||
var offset = 0-time.getTimezoneOffset()/1440;
|
var offset = 0-time.getTimezoneOffset()/1440;
|
||||||
var days = Math.floor((time.getTime()/1000)/86400+offset)-Math.floor(getTime()/86400+offset);
|
var days = Math.floor((time.getTime()/1000)/86400+offset)-Math.floor(getTime()/86400+offset);
|
||||||
if(days > 0) {
|
if(days > 0 || event.allDay) {
|
||||||
var daysStr = days===1?/*LANG*/"tomorrow":/*LANG*/"in "+days+/*LANG*/" days";
|
var daysStr = days===1?/*LANG*/"tomorrow":/*LANG*/"in "+days+/*LANG*/" days";
|
||||||
g.drawString(daysStr,15*timeStr.length,y-21);
|
g.drawString(daysStr,x,y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
y += 21;
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawEventBody(event, y) {
|
function drawEventBody(event, y) {
|
||||||
g.setFont("12x20", 1);
|
g.setFont("12x20", 1);
|
||||||
var lines = g.wrapString(event.title, g.getWidth()-10);
|
var lines = g.wrapString(event.title, g.getWidth()-15);
|
||||||
|
var yStart = y;
|
||||||
if (lines.length > 2) {
|
if (lines.length > 2) {
|
||||||
lines = lines.slice(0,2);
|
lines = lines.slice(0,2);
|
||||||
lines[1] = lines[1].slice(0,-3)+"...";
|
lines[1] = lines[1].slice(0,-3)+"...";
|
||||||
}
|
}
|
||||||
g.drawString(lines.join('\n'), 5, y);
|
g.drawString(lines.join('\n'),10,y);
|
||||||
y+=20 * lines.length;
|
y+=20 * lines.length;
|
||||||
if(event.location) {
|
if(event.location) {
|
||||||
g.drawImage(atob("DBSBAA8D/H/nDuB+B+B+B3Dn/j/B+A8A8AYAYAYAAAAAAA=="),5,y);
|
g.drawImage(atob("DBSBAA8D/H/nDuB+B+B+B3Dn/j/B+A8A8AYAYAYAAAAAAA=="),10,y);
|
||||||
g.drawString(event.location, 20, y);
|
g.drawString(event.location,25,y);
|
||||||
y+=20;
|
y+=20;
|
||||||
}
|
}
|
||||||
|
if (event.color) {
|
||||||
|
var oldColor = g.getColor();
|
||||||
|
g.setColor("#"+(0x1000000+Number(event.color)).toString(16).padStart(6,"0"));
|
||||||
|
g.fillRect(0,yStart,5,y-3);
|
||||||
|
g.setColor(oldColor);
|
||||||
|
}
|
||||||
y+=5;
|
y+=5;
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
@ -68,19 +82,19 @@ function drawEvent(event, y) {
|
||||||
var curEventHeight = 0;
|
var curEventHeight = 0;
|
||||||
|
|
||||||
function drawCurrentEvents(y) {
|
function drawCurrentEvents(y) {
|
||||||
g.setColor(g.theme.dark ? "#0ff" : "#0000ff");
|
g.setColor(g.theme.dark ? "#0ff" : "#00f");
|
||||||
g.clearRect(5, y, g.getWidth() - 5, y + curEventHeight);
|
g.clearRect(0,y,g.getWidth()-5,y+curEventHeight);
|
||||||
curEventHeight = y;
|
curEventHeight = y;
|
||||||
|
|
||||||
if(current.length === 0) {
|
if(current.length === 0) {
|
||||||
y = drawEvent({timestamp: getTime(), durationInSeconds: 100}, y);
|
y = drawEvent({timestamp: getTime(), durationInSeconds: 100}, y);
|
||||||
} else {
|
} else {
|
||||||
y = drawEventHeader(current[0], y);
|
y = drawEventHeader(current[0],y);
|
||||||
for (var e of current) {
|
for (var e of current) {
|
||||||
y = drawEventBody(e, y);
|
y = drawEventBody(e,y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
curEventHeight = y - curEventHeight;
|
curEventHeight = y-curEventHeight;
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +108,7 @@ function drawFutureEvents(y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function fullRedraw() {
|
function fullRedraw() {
|
||||||
g.clearRect(5,24,g.getWidth()-5,g.getHeight());
|
g.clearRect(0,24,g.getWidth()-5,g.getHeight());
|
||||||
updateCalendar();
|
updateCalendar();
|
||||||
var y = 30;
|
var y = 30;
|
||||||
y = drawCurrentEvents(y);
|
y = drawCurrentEvents(y);
|
||||||
|
@ -117,3 +131,4 @@ var minuteInterval = setInterval(redraw, 60 * 1000);
|
||||||
Bangle.setUI("clock");
|
Bangle.setUI("clock");
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "calclock",
|
"id": "calclock",
|
||||||
"name": "Calendar Clock",
|
"name": "Calendar Clock",
|
||||||
"shortName": "CalClock",
|
"shortName": "CalClock",
|
||||||
"version": "0.04",
|
"version": "0.05",
|
||||||
"description": "Show the current and upcoming events synchronized from Gadgetbridge",
|
"description": "Show the current and upcoming events synchronized from Gadgetbridge",
|
||||||
"icon": "calclock.png",
|
"icon": "calclock.png",
|
||||||
"type": "clock",
|
"type": "clock",
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
diff --git a/apps/calclock/calclock.js b/apps/calclock/calclock.js
|
||||||
|
index cb8c6100e..2092c1a4e 100644
|
||||||
|
--- a/apps/calclock/calclock.js
|
||||||
|
+++ b/apps/calclock/calclock.js
|
||||||
|
@@ -3,9 +3,24 @@ var current = [];
|
||||||
|
var next = [];
|
||||||
|
|
||||||
|
function updateCalendar() {
|
||||||
|
- calendar = require("Storage").readJSON("android.calendar.json",true)||[];
|
||||||
|
- calendar = calendar.filter(e => isActive(e) || getTime() <= e.timestamp);
|
||||||
|
- calendar.sort((a,b) => a.timestamp - b.timestamp);
|
||||||
|
+ calendar = [
|
||||||
|
+ {
|
||||||
|
+ t: "calendar",
|
||||||
|
+ id: 2, type: 0, timestamp: getTime(), durationInSeconds: 200,
|
||||||
|
+ title: "Capture Screenshot",
|
||||||
|
+ description: "Capture Screenshot",
|
||||||
|
+ location: "",
|
||||||
|
+ calName: "",
|
||||||
|
+ color: -7151168, allDay: true },
|
||||||
|
+ {
|
||||||
|
+ t: "calendar",
|
||||||
|
+ id: 7186, type: 0, timestamp: getTime() + 2000, durationInSeconds: 100,
|
||||||
|
+ title: "Upload to BangleApps",
|
||||||
|
+ description: "",
|
||||||
|
+ location: "",
|
||||||
|
+ calName: "",
|
||||||
|
+ color: -509406, allDay: false }
|
||||||
|
+ ];
|
||||||
|
|
||||||
|
current = calendar.filter(isActive);
|
||||||
|
next = calendar.filter(e=>!isActive(e));
|
Binary file not shown.
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 3.1 KiB |
Loading…
Reference in New Issue