Added Spanish language to sliding text clock

Also improved handling of lcdon
pull/727/head
adrian w kirk 2021-04-18 09:31:25 +01:00
parent 615c84800e
commit 6446d5e00b
3 changed files with 68 additions and 25 deletions

View File

@ -216,8 +216,8 @@
{ "id": "slidingtext",
"name": "Sliding Clock",
"icon": "slidingtext.png",
"version":"0.02",
"description": "Inspired by the Pebble sliding clock, old times are scrolled off the screen and new times on. You are also able to change language on the fly so you can see the time written in other languages using button 1. Currently only English, French and Japanese are supported",
"version":"0.03",
"description": "Inspired by the Pebble sliding clock, old times are scrolled off the screen and new times on. You are also able to change language on the fly so you can see the time written in other languages using button 1. Currently English, French, Japanese and Spanish are supported",
"tags": "clock",
"type":"clock",
"allow_emulator":true,
@ -229,6 +229,7 @@
{"name":"slidingtext.locale.en.js","url":"slidingtext.locale.en.js"},
{"name":"slidingtext.locale.en2.js","url":"slidingtext.locale.en2.js"},
{"name":"slidingtext.utils.en.js","url":"slidingtext.utils.en.js"},
{"name":"slidingtext.utils.es.js","url":"slidingtext.utils.es.js"},
{"name":"slidingtext.locale.fr.js","url":"slidingtext.locale.fr.js"},
{"name":"slidingtext.locale.jp.js","url":"slidingtext.locale.jp.js"},
{"name":"slidingtext.dtfmt.js","url":"slidingtext.dtfmt.js"}

View File

@ -24,8 +24,9 @@
{name:"English(Traditional)",shortname:"en2"},
{name:"French",shortname:"fr"},
{name:"Japanese",shortname:"jp"}
{name:"Spanish",shortname:"es"}
];
var selected_languages = ["en","fr","jp"];
var selected_languages = ["en","es","jp"];
try{
var stored = localStorage.getItem('slidingtext_stored')
if(stored) selected_languages = JSON.parse(stored);

View File

@ -121,12 +121,14 @@ class ShiftText {
setBgColor(bg_color){
this.bg_color = bg_color;
}
reset(){
reset(hard_reset) {
//console.log("reset");
this.hide();
this.x = this.init_x;
this.y = this.init_y;
if (hard_reset) {
this.txt = this.init_txt;
}
this.show();
if(this.timeoutId != null){
clearTimeout(this.timeoutId);
@ -253,7 +255,7 @@ function nextColorTheme(){
setColor(color_scheme.main_bar,
color_scheme.other_bars,
color_scheme.background);
reset_clock();
reset_clock(true);
draw_clock();
}
@ -274,8 +276,7 @@ function setColor(main_color,other_color,bg_color){
]);
}
// load the date formats required
// load the date formats and laguages required
LANGUAGES_FILE = "slidingtext.languages.json";
var LANGUAGES_DEFAULT = ["en","en2"];
var locales = null;
@ -313,7 +314,7 @@ function changeFormatter(){
}
console.log("changing to formatter " + date_formatter_idx);
date_formatter = date_formatters[date_formatter_idx];
reset_clock();
reset_clock(true);
draw_clock();
command_stack_high_priority.unshift(
function() {
@ -340,13 +341,41 @@ function changeFormatter(){
}
var DISPLAY_TEXT_X = 20;
function reset_clock(hard_reset){
console.log("reset_clock hard_reset:" + hard_reset);
function reset_clock(){
//console.log("reset_clock");
if(!hard_reset && last_draw_time != null){
// If its not a hard reset then we want to reset the
// rows set to the last time. If the last time is too long
// ago then we fast forward to 1 min ago.
// In this way the watch wakes by scrolling
// off the last time and scroll on the new time
var reset_time = last_draw_time;
var last_minute_millis = Date.now() - 60000;
if(reset_time.getTime() < last_minute_millis){
reset_time = new Date(last_minute_millis);
}
var rows = date_formatter.formatDate(reset_time);
for (var i = 0; i < rows.length; i++) {
row_displays[i].hide();
row_displays[i].speed_x = CLOCK_TEXT_SPEED_X;
row_displays[i].x = DISPLAY_TEXT_X;
row_displays[i].y = row_displays[i].init_y;
if(row_displays[i].timeoutId != null){
clearTimeout(row_displays[i].timeoutId);
}
row_displays[i].setText(rows[i]);
row_displays[i].show();
}
} else {
// do a hard reset and clear everything out
for (var i = 0; i < row_displays.length; i++) {
row_displays[i].speed_x = CLOCK_TEXT_SPEED_X;
row_displays[i].reset();
row_displays[i].reset(hard_reset);
}
}
reset_commands();
}
@ -371,6 +400,7 @@ function draw_clock(){
console.log("forwarding to next minute");
date = new Date(date.getTime() + next_minute_boundary_secs * 1000);
}
// for debugging only
//date.setMinutes(37);
var rows = date_formatter.formatDate(date);
var display;
@ -404,7 +434,7 @@ function display_row(display,txt){
//console.log("move in new:" + txt);
display.onFinished(next_command);
display.setTextXPosition(txt, 240);
display.moveToX(20);
display.moveToX(DISPLAY_TEXT_X);
}
);
}
@ -421,14 +451,14 @@ function display_row(display,txt){
//console.log("move in:" + txt);
display.onFinished(next_command);
display.setTextXPosition(txt,240);
display.moveToX(20);
display.moveToX(DISPLAY_TEXT_X);
}
);
} else {
command_stack_high_priority.push(
function(){
//console.log("move in2:" + txt);
display.setTextXPosition(txt,20);
display.setTextXPosition(txt,DISPLAY_TEXT_X);
next_command();
}
);
@ -508,7 +538,7 @@ function button1pressed() {
function button3pressed() {
console.log("button3pressed");
nextColorTheme();
reset_clock();
reset_clock(true);
draw_clock();
save_settings();
}
@ -517,7 +547,7 @@ function button3pressed() {
let intervalRef = null;
function clearTimers(){
if(intervalRef) {
if(intervalRef != null) {
clearInterval(intervalRef);
intervalRef = null;
}
@ -533,21 +563,32 @@ function startTimers(){
}
function scheduleDrawClock(){
//console.log("scheduleDrawClock");
if(intervalRef) clearTimers();
intervalRef = setInterval(draw_clock, 60*1000);
clearTimers();
if (Bangle.isLCDOn()) {
console.log("scheduleDrawClock");
intervalRef = setInterval(() => {
if (Bangle.isLCDOn()) {
console.log("draw clock callback");
draw_clock()
} else {
console.log("draw clock callback - skipped not visible");
}
}, 60 * 1000);
draw_clock();
} else {
console.log("scheduleDrawClock - skipped not visible");
}
}
Bangle.on('lcdPower', (on) => {
if (on) {
console.log("lcdPower: on");
Bangle.drawWidgets();
reset_clock();
reset_clock(false);
startTimers();
} else {
console.log("lcdPower: off");
reset_clock();
reset_clock(false);
clearTimers();
}
});