mirror of https://github.com/espruino/BangleApps
Merge pull request #1126 from Athemis/calendar
calendar: improve legibility on Bangle2 and localize stringspull/1184/head
commit
d9d5926416
|
@ -2429,7 +2429,7 @@
|
|||
{
|
||||
"id": "calendar",
|
||||
"name": "Calendar",
|
||||
"version": "0.03",
|
||||
"version": "0.04",
|
||||
"description": "Simple calendar",
|
||||
"icon": "calendar.png",
|
||||
"screenshots": [{"url":"screenshot_calendar.png"}],
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
0.01: Basic calendar
|
||||
0.02: Make Bangle 2 compatible
|
||||
0.03: Add setting to start week on Sunday
|
||||
0.04: Add setting to switch color schemes. On Bangle 2 non-dithering colors will be used by default. Use localized names for months and days of the week (Language app needed).
|
||||
|
|
|
@ -9,5 +9,6 @@ Basic calendar
|
|||
|
||||
## Settings
|
||||
|
||||
- Starts on Sunday: whether the calendar should start on Sunday (default is Monday).
|
||||
- Starts Sunday: whether the calendar should start on Sunday (default is Monday).
|
||||
- B2 Colors: use non-dithering colors (default, recommended for Bangle 2) or the original color scheme.
|
||||
|
||||
|
|
|
@ -1,5 +1 @@
|
|||
require("heatshrink").decompress(
|
||||
atob(
|
||||
"mEwxH+AH4A/ADuIUCARRDhgePCKIv13YAEDoYJFAA4RJFyQvcGBYRGy4dDy4uLCJgv/DoOBDgOBF5oRLF6IeBDgIvNCJYvQDwQuNCJovRADov/F9OsAEgv/F/4vhwIACAqYv/F/4vnd94vvX/4v/F/7vvF96//F/4v/d94v/F/4wsFxQwjFxgA/AH4A/AH4AZA=="
|
||||
)
|
||||
)
|
||||
require("heatshrink").decompress(atob("mEwwcCpMkyQC3wAIFgIRJn8JAoeQ/gRYwB0Bn57F/gCBHAgfCn8EDgdI/kSAoIR8oBkFgAFCCIysKCPM//4AKZAgR3/0Aj+Ag/ggP4gF/CPpr/Nf5r/NfYRhw4RL8IRDyEAABUJCIYC/AVI="))
|
|
@ -10,26 +10,109 @@ const color1 = "#035AA6";
|
|||
const color2 = "#4192D9";
|
||||
const color3 = "#026873";
|
||||
const color4 = "#038C8C";
|
||||
const color5 = "#03A696";
|
||||
const gray1 = "#bbbbbb";
|
||||
const black = "#000000";
|
||||
const white = "#ffffff";
|
||||
const gray1 = "#444444";
|
||||
const gray2 = "#888888";
|
||||
const gray3 = "#bbbbbb";
|
||||
const red = "#d41706";
|
||||
const blue = "#0000ff";
|
||||
const yellow = "#ffff00";
|
||||
|
||||
let settings = require('Storage').readJSON("calendar.json", true) || {};
|
||||
if (settings.startOnSun === undefined)
|
||||
settings.startOnSun = false;
|
||||
if (settings.ndColors === undefined)
|
||||
if (process.env.HWVERSION == 2) {
|
||||
settings.ndColors = true;
|
||||
} else {
|
||||
settings.ndColors = false;
|
||||
}
|
||||
|
||||
if (settings.ndColors === true) {
|
||||
let bgColor = white;
|
||||
let bgColorMonth = blue;
|
||||
let bgColorDow = black;
|
||||
let bgColorWeekend = yellow;
|
||||
let fgOtherMonth = blue;
|
||||
let fgSameMonth = black;
|
||||
} else {
|
||||
let bgColor = color4;
|
||||
let bgColorMonth = color1;
|
||||
let bgColorDow = color2;
|
||||
let bgColorWeekend = color3;
|
||||
let fgOtherMonth = gray1;
|
||||
let fgSameMonth = white;
|
||||
}
|
||||
|
||||
function getDowLbls(locale) {
|
||||
let dowLbls;
|
||||
//TODO: Find some clever way to generate this programmatically from locale lib
|
||||
switch (locale) {
|
||||
case "de_AT":
|
||||
case "de_CH":
|
||||
case "de_DE":
|
||||
if (settings.startOnSun) {
|
||||
dowLbls = ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"];
|
||||
} else {
|
||||
dowLbls = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"];
|
||||
}
|
||||
break;
|
||||
case "nl_NL":
|
||||
if (settings.startOnSun) {
|
||||
dowLbls = ["zo", "ma", "di", "wo", "do", "vr", "za"];
|
||||
} else {
|
||||
dowLbls = ["ma", "di", "wo", "do", "vr", "za", "zo"];
|
||||
}
|
||||
break;
|
||||
case "fr_BE":
|
||||
case "fr_CH":
|
||||
case "fr_FR":
|
||||
if (settings.startOnSun) {
|
||||
dowLbls = ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"];
|
||||
} else {
|
||||
dowLbls = ["Lu", "Ma", "Me", "Je", "Ve", "Sa", "Di"];
|
||||
}
|
||||
break;
|
||||
case "sv_SE":
|
||||
if (settings.startOnSun) {
|
||||
dowLbls = ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"];
|
||||
} else {
|
||||
dowLbls = ["Lu", "Ma", "Me", "Je", "Ve", "Sa", "Di"];
|
||||
}
|
||||
break;
|
||||
case "it_CH":
|
||||
case "it_IT":
|
||||
if (settings.startOnSun) {
|
||||
dowLbls = ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"];
|
||||
} else {
|
||||
dowLbls = ["Lu", "Ma", "Me", "Gi", "Ve", "Sa", "Do"];
|
||||
}
|
||||
break;
|
||||
case "oc_FR":
|
||||
if (settings.startOnSun) {
|
||||
dowLbls = ["dg", "dl", "dm", "dc", "dj", "dv", "ds"];
|
||||
} else {
|
||||
dowLbls = ["dl", "dm", "dc", "dj", "dv", "ds", "dg"];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (settings.startOnSun) {
|
||||
dowLbls = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
||||
} else {
|
||||
dowLbls = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
|
||||
}
|
||||
break;
|
||||
}
|
||||
return dowLbls;
|
||||
}
|
||||
|
||||
function drawCalendar(date) {
|
||||
g.setBgColor(color4);
|
||||
g.setBgColor(bgColor);
|
||||
g.clearRect(0, 0, maxX, maxY);
|
||||
g.setBgColor(color1);
|
||||
g.setBgColor(bgColorMonth);
|
||||
g.clearRect(0, 0, maxX, headerH);
|
||||
g.setBgColor(color2);
|
||||
g.setBgColor(bgColorDow);
|
||||
g.clearRect(0, headerH, maxX, headerH + rowH);
|
||||
g.setBgColor(color3);
|
||||
g.setBgColor(bgColorWeekend);
|
||||
g.clearRect(colW * 5, headerH + rowH, maxX, maxY);
|
||||
for (let y = headerH; y < maxY; y += rowH) {
|
||||
g.drawLine(0, y, maxX, y);
|
||||
|
@ -40,24 +123,11 @@ function drawCalendar(date) {
|
|||
|
||||
const month = date.getMonth();
|
||||
const year = date.getFullYear();
|
||||
const monthMap = {
|
||||
0: "January",
|
||||
1: "February",
|
||||
2: "March",
|
||||
3: "April",
|
||||
4: "May",
|
||||
5: "June",
|
||||
6: "July",
|
||||
7: "August",
|
||||
8: "September",
|
||||
9: "October",
|
||||
10: "November",
|
||||
11: "December"
|
||||
};
|
||||
const localeMonth = require('locale').month(date);
|
||||
g.setFontAlign(0, 0);
|
||||
g.setFont("6x8", fontSize);
|
||||
g.setColor(white);
|
||||
g.drawString(`${monthMap[month]} ${year}`, maxX / 2, headerH / 2);
|
||||
g.drawString(`${localeMonth} ${year}`, maxX / 2, headerH / 2);
|
||||
g.drawPoly([10, headerH / 2, 20, 10, 20, headerH - 10], true);
|
||||
g.drawPoly(
|
||||
[maxX - 10, headerH / 2, maxX - 20, 10, maxX - 20, headerH - 10],
|
||||
|
@ -65,12 +135,7 @@ function drawCalendar(date) {
|
|||
);
|
||||
|
||||
g.setFont("6x8", fontSize);
|
||||
let dowLbls;
|
||||
if (settings.startOnSun) {
|
||||
dowLbls = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
||||
} else {
|
||||
dowLbls = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
|
||||
}
|
||||
let dowLbls = getDowLbls(require('locale').name);
|
||||
dowLbls.forEach((lbl, i) => {
|
||||
g.drawString(lbl, i * colW + colW / 2, headerH + rowH / 2);
|
||||
});
|
||||
|
@ -120,14 +185,19 @@ function drawCalendar(date) {
|
|||
today.year === year && today.month === month && today.day === day - 50;
|
||||
if (isToday) {
|
||||
g.setColor(red);
|
||||
let x1 = x * colW;
|
||||
let y1 = y * rowH + headerH + rowH;
|
||||
let x2 = x * colW + colW;
|
||||
let y2 = y * rowH + headerH + rowH + rowH;
|
||||
g.drawRect(x1, y1, x2, y2);
|
||||
g.drawRect(
|
||||
x * colW,
|
||||
y * rowH + headerH + rowH,
|
||||
x * colW + colW - 1,
|
||||
y * rowH + headerH + rowH + rowH
|
||||
x1 + 1,
|
||||
y1 + 1,
|
||||
x2 - 1,
|
||||
y2 - 1
|
||||
);
|
||||
}
|
||||
g.setColor(day < 50 ? gray3 : white);
|
||||
g.setColor(day < 50 ? fgOtherMonth : fgSameMonth);
|
||||
g.drawString(
|
||||
(day > 50 ? day - 50 : day).toString(),
|
||||
x * colW + colW / 2,
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 540 B After Width: | Height: | Size: 7.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 1.1 KiB |
|
@ -2,7 +2,13 @@
|
|||
var FILE = "calendar.json";
|
||||
var settings = require('Storage').readJSON(FILE, true) || {};
|
||||
if (settings.startOnSun === undefined)
|
||||
settings.startOnSun = true;
|
||||
settings.startOnSun = false;
|
||||
if (settings.ndColors === undefined)
|
||||
if (process.env.HWVERSION == 2) {
|
||||
settings.ndColors = true;
|
||||
} else {
|
||||
settings.ndColors = false;
|
||||
}
|
||||
|
||||
function writeSettings() {
|
||||
require('Storage').writeJSON(FILE, settings);
|
||||
|
@ -11,7 +17,7 @@
|
|||
E.showMenu({
|
||||
"": { "title": "Calendar" },
|
||||
"< Back": () => back(),
|
||||
'Start on Sunday': {
|
||||
'Start Sunday': {
|
||||
value: settings.startOnSun,
|
||||
format: v => v ? "Yes" : "No",
|
||||
onchange: v => {
|
||||
|
@ -19,6 +25,14 @@
|
|||
writeSettings();
|
||||
}
|
||||
},
|
||||
'B2 Colors': {
|
||||
value: settings.ndColors,
|
||||
format: v => v ? "Yes" : "No",
|
||||
onchange: v => {
|
||||
settings.ndColors = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue