From ac05df0964579cc869627dfcc25c17f614374ffd Mon Sep 17 00:00:00 2001 From: Danny <31635744+DDDanny@users.noreply.github.com> Date: Wed, 2 Feb 2022 22:16:44 +0100 Subject: [PATCH] codeoptimze and metadata emulator --- apps/timecal/metadata.json | 6 ++-- .../timecal/{ => testing}/timecal.app.test.js | 34 ++++++------------- apps/timecal/timecal.app.js | 27 ++++----------- 3 files changed, 21 insertions(+), 46 deletions(-) rename apps/timecal/{ => testing}/timecal.app.test.js (96%) diff --git a/apps/timecal/metadata.json b/apps/timecal/metadata.json index a1cf31a93..70ea98842 100644 --- a/apps/timecal/metadata.json +++ b/apps/timecal/metadata.json @@ -1,12 +1,14 @@ { "id": "timecal", "name": "TimeCal", "shortName":"TimeCal", - "icon": "icon.png", "version":"0.03", "description": "TimeCal shows the Time along with a 3 week calendar", - "tags": "clock", + "icon": "icon.png", "type": "clock", + "tags": "clock,calendar", "supports":["BANGLEJS2"], + "readme": "README.md", + "allow_emulator":true, "storage": [ {"name":"timecal.app.js","url":"timecal.app.js"}, {"name":"timecal.settings.js","url":"timecal.settings.js"} diff --git a/apps/timecal/timecal.app.test.js b/apps/timecal/testing/timecal.app.test.js similarity index 96% rename from apps/timecal/timecal.app.test.js rename to apps/timecal/testing/timecal.app.test.js index 6a7a8220f..8da4e26b5 100644 --- a/apps/timecal/timecal.app.test.js +++ b/apps/timecal/testing/timecal.app.test.js @@ -85,11 +85,9 @@ class TimeCalClock{ d=d?d :new Date(); - g.setFontAlign(0, -1); - g.setFont("Vector", this.TIME_FONT_SIZE()); - g.setColor(g.theme.fg); - g.clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7); - g.drawString(("0" + require("locale").time(d, 1)).slice(-5), this.centerX, Y); + g.setFontAlign(0, -1).setFont("Vector", this.TIME_FONT_SIZE()).setColor(g.theme.fg) + .clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7) + .drawString(("0" + require("locale").time(d, 1)).slice(-5), this.centerX, Y, true); //.drawRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7); //DEV-Option setTimeout(this.draw.bind(this), 60000-(d.getSeconds()*1000)-d.getMilliseconds()); @@ -166,11 +164,7 @@ class TimeCalClock{ } } if (render){ - g.clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+FONT_SIZE-3); - g.setFont("Vector", FONT_SIZE); - g.setColor(g.theme.fg); - g.setFontAlign(0, -1); - g.drawString(dateStr,this.centerX,Y); + g.setFont("Vector", FONT_SIZE).setColor(g.theme.fg).setFontAlign(0, -1).clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+FONT_SIZE-3).drawString(dateStr,this.centerX,Y); } //g.drawRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+FONT_SIZE-3); //DEV-Option } @@ -183,30 +177,23 @@ class TimeCalClock{ const DAY_NAME_FONT_SIZE=10; const CAL_Y=Bangle.appRect.y+this.DATE_FONT_SIZE()+10+this.TIME_FONT_SIZE()+3; - const CAL_AREA_H=Bangle.appRect.h-CAL_Y;//+24; //+24: top widegtes only + const CAL_AREA_H=Bangle.appRect.h-CAL_Y+24; //+24: top widegtes only const CELL_W=Bangle.appRect.w/7; //cell width const CELL_H=(CAL_AREA_H-DAY_NAME_FONT_SIZE)/3; //cell heigth const DAY_NUM_FONT_SIZE=Math.min(CELL_H-1,15); //size down, max 15 - g.clearRect(Bangle.appRect.x, CAL_Y, Bangle.appRect.x2, CAL_Y+CAL_AREA_H); - - g.setFont("Vector", DAY_NAME_FONT_SIZE); - g.setColor(g.theme.fg); - g.setFontAlign(-1, -1); - + g.setFont("Vector", DAY_NAME_FONT_SIZE).setColor(g.theme.fg).setFontAlign(-1, -1).clearRect(Bangle.appRect.x, CAL_Y, Bangle.appRect.x2, CAL_Y+CAL_AREA_H); //draw grid & Headline const dNames = this.ABR_DAY.map((a) => a.length<=2 ? a : a.substr(0, 2)); //force shrt 2 for(var dNo=0; dNo=0 ? (dNo+this.settings().wdStrt)%7 : (dNo+d.getDay()+4)%7; const dName=dNames[dIdx]; - if (dIdx==0) //sunday colorize txt - g.setColor(this.nrgb[this.settings().suClr]); - else - g.setColor(g.theme.fg); - g.drawString(dName, dNo*CELL_W+(CELL_W-g.stringWidth(dName))/2+2, CAL_Y+1); //center Names if(dNo>0) g.drawLine(dNo*CELL_W, CAL_Y, dNo*CELL_W, CAL_Y+CAL_AREA_H-1); + + if (dIdx==0) g.setColor(this.nrgb[this.settings().suClr]); //sunday maybe colorize txt + g.drawString(dName, dNo*CELL_W+(CELL_W-g.stringWidth(dName))/2+2, CAL_Y+1).setColor(g.theme.fg); } var nextY=CAL_Y+DAY_NAME_FONT_SIZE; @@ -255,8 +242,7 @@ class TimeCalClock{ } } if (this.settings().calBorder) { - g.setColor(g.theme.fg); - g.drawRect(Bangle.appRect.x, CAL_Y, Bangle.appRect.x2, CAL_Y+CAL_AREA_H-1); + g.setColor(g.theme.fg).drawRect(Bangle.appRect.x, CAL_Y, Bangle.appRect.x2, CAL_Y+CAL_AREA_H-1); } } diff --git a/apps/timecal/timecal.app.js b/apps/timecal/timecal.app.js index 9d78f7d08..4c2f719e9 100644 --- a/apps/timecal/timecal.app.js +++ b/apps/timecal/timecal.app.js @@ -85,11 +85,9 @@ class TimeCalClock{ d=d?d :new Date(); - g.setFontAlign(0, -1); - g.setFont("Vector", this.TIME_FONT_SIZE()); - g.setColor(g.theme.fg); - g.clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7); - g.drawString(("0" + require("locale").time(d, 1)).slice(-5), this.centerX, Y); + g.setFontAlign(0, -1).setFont("Vector", this.TIME_FONT_SIZE()).setColor(g.theme.fg) + .clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7) + .drawString(("0" + require("locale").time(d, 1)).slice(-5), this.centerX, Y, true); //.drawRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7); //DEV-Option setTimeout(this.draw.bind(this), 60000-(d.getSeconds()*1000)-d.getMilliseconds()); @@ -166,11 +164,7 @@ class TimeCalClock{ } } if (render){ - g.clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+FONT_SIZE-3); - g.setFont("Vector", FONT_SIZE); - g.setColor(g.theme.fg); - g.setFontAlign(0, -1); - g.drawString(dateStr,this.centerX,Y); + g.setFont("Vector", FONT_SIZE).setColor(g.theme.fg).setFontAlign(0, -1).clearRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+FONT_SIZE-3).drawString(dateStr,this.centerX,Y); } //g.drawRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+FONT_SIZE-3); //DEV-Option } @@ -188,12 +182,7 @@ class TimeCalClock{ const CELL_H=(CAL_AREA_H-DAY_NAME_FONT_SIZE)/3; //cell heigth const DAY_NUM_FONT_SIZE=Math.min(CELL_H-1,15); //size down, max 15 - g.clearRect(Bangle.appRect.x, CAL_Y, Bangle.appRect.x2, CAL_Y+CAL_AREA_H); - - g.setFont("Vector", DAY_NAME_FONT_SIZE); - g.setColor(g.theme.fg); - g.setFontAlign(-1, -1); - + g.setFont("Vector", DAY_NAME_FONT_SIZE).setColor(g.theme.fg).setFontAlign(-1, -1).clearRect(Bangle.appRect.x, CAL_Y, Bangle.appRect.x2, CAL_Y+CAL_AREA_H); //draw grid & Headline const dNames = this.ABR_DAY.map((a) => a.length<=2 ? a : a.substr(0, 2)); //force shrt 2 @@ -204,8 +193,7 @@ class TimeCalClock{ g.drawLine(dNo*CELL_W, CAL_Y, dNo*CELL_W, CAL_Y+CAL_AREA_H-1); if (dIdx==0) g.setColor(this.nrgb[this.settings().suClr]); //sunday maybe colorize txt - g.drawString(dName, dNo*CELL_W+(CELL_W-g.stringWidth(dName))/2+2, CAL_Y+1); //center Names - g.setColor(g.theme.fg); + g.drawString(dName, dNo*CELL_W+(CELL_W-g.stringWidth(dName))/2+2, CAL_Y+1).setColor(g.theme.fg); } var nextY=CAL_Y+DAY_NAME_FONT_SIZE; @@ -254,8 +242,7 @@ class TimeCalClock{ } } if (this.settings().calBorder) { - g.setColor(g.theme.fg); - g.drawRect(Bangle.appRect.x, CAL_Y, Bangle.appRect.x2, CAL_Y+CAL_AREA_H-1); + g.setColor(g.theme.fg).drawRect(Bangle.appRect.x, CAL_Y, Bangle.appRect.x2, CAL_Y+CAL_AREA_H-1); } }