From 7ce25c8774d6846d2430f2bb6a22625d444578a9 Mon Sep 17 00:00:00 2001 From: Sven Klomp Date: Wed, 23 Feb 2022 20:50:45 +0100 Subject: [PATCH] Initial commit of widcw widcw is a widget to display the current calendar week. --- apps/widcw/ChangeLog | 1 + apps/widcw/logo.svg | 62 +++++++++++++++++++++++++++++++++++++++ apps/widcw/metadata.json | 13 ++++++++ apps/widcw/widget.js | 48 ++++++++++++++++++++++++++++++ apps/widcw/widget.png | Bin 0 -> 884 bytes apps/widcw/widget.svg | 55 ++++++++++++++++++++++++++++++++++ 6 files changed, 179 insertions(+) create mode 100644 apps/widcw/ChangeLog create mode 100644 apps/widcw/logo.svg create mode 100644 apps/widcw/metadata.json create mode 100644 apps/widcw/widget.js create mode 100644 apps/widcw/widget.png create mode 100644 apps/widcw/widget.svg diff --git a/apps/widcw/ChangeLog b/apps/widcw/ChangeLog new file mode 100644 index 000000000..a4bc24d1a --- /dev/null +++ b/apps/widcw/ChangeLog @@ -0,0 +1 @@ +0.01: First version \ No newline at end of file diff --git a/apps/widcw/logo.svg b/apps/widcw/logo.svg new file mode 100644 index 000000000..e093414d5 --- /dev/null +++ b/apps/widcw/logo.svg @@ -0,0 +1,62 @@ + + + + + + + + CW + + diff --git a/apps/widcw/metadata.json b/apps/widcw/metadata.json new file mode 100644 index 000000000..653b093ec --- /dev/null +++ b/apps/widcw/metadata.json @@ -0,0 +1,13 @@ +{ + "id": "widcw", + "name": "Calendar Week Widget", + "version": "0.01", + "description": "Widget which shows the current calendar week", + "icon": "widget.png", + "type": "widget", + "tags": "widget,calendar", + "supports": ["BANGLEJS","BANGLEJS2"], + "storage": [ + {"name":"widcw.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widcw/widget.js b/apps/widcw/widget.js new file mode 100644 index 000000000..ef43a4551 --- /dev/null +++ b/apps/widcw/widget.js @@ -0,0 +1,48 @@ +(function() { + var width = 22; // width of the widget + + function draw() { + const x = this.x, y = this.y, x2 = x+21, y2 = y+23; + + var date = new Date(); + + // Calculate calendar week (https://stackoverflow.com/a/6117889) + getCW= function(date){ + var d=new Date(date.getFullYear(), date.getMonth(), date.getDate()); + var dayNum = d.getDay() || 7; + d.setDate(d.getDate() + 4 - dayNum); + var yearStart = new Date(d.getFullYear(),0,1); + return Math.ceil((((d - yearStart) / 86400000) + 1)/7); + }; + + g.reset().setFontAlign(0, 0) // center all text + // header + .setBgColor("#f00").setColor("#fff") + .clearRect(x, y, x2, y+8).setFont("4x6").drawString("CW", (x+x2)/2+1, y+5) + // date + .setBgColor("#fff").setColor("#000") + .clearRect(x, y+9, x2, y2).setFont("Vector:16").drawString(getCW(date), (x+x2)/2+2, y+17); + + if (!g.theme.dark) { + // black border around date for light themes + g.setColor("#000").drawPoly([ + x, y+9, + x, y2, + x2, y2, + x2, y+9 + ]); + } + + // redraw when date changes + setTimeout(()=>WIDGETS["widcw"].draw(), (86401 - Math.floor(date/1000) % 86400)*1000); + + } + + // add your widget + WIDGETS["widcw"]={ + area:"tl", // tl (top left), tr (top right), bl (bottom left), br (bottom right) + width: width, // how wide is the widget? You can change this and call Bangle.drawWidgets() to re-layout + draw:draw // called to draw the widget + }; + +})(); diff --git a/apps/widcw/widget.png b/apps/widcw/widget.png new file mode 100644 index 0000000000000000000000000000000000000000..c73d40c5a60b0f618d12a23276b14d53325b23df GIT binary patch literal 884 zcmV-)1B?8LP)pF8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H10|7}y zK~!jg?bknuT}2ef@lTRXRxvSa5rwF+Q;VpmiBV9|R&BIV5MpDRlvXMTf+>R9st}UY zR)T`WuvQU-z#@o$hzg1r5DA<86L;V4Gx1r>T=u+q_r?37<$PgaXXZC|&Y3yyoLMTB zN~Kb%R4SFqHL|IrZVC_L0Cr(J7Vtej$70almo<^IxD@&~j%9;p@VIp1(?Pd@-;2$5XZ<4fO5sbzPjf ztuSC9B?M9!M#Cd!8)aJmTWvpw#i<~L?Jt;IU=YAij@tJfJq-1cY#jZIiDn@8?;5VaA?CoUo zFsFlIq?3QiMyl*dPR1LU#=&C$_57{QJnO&zh)Ln{XYrlb*0aHzY-FOgwunb3abTy> zLUXk=dLuqCoJNf?Y%To#bYZk5vKq>s5s zTSaZcVkYROIyyQr+wiLNzF8`q8TXuyOy&9c&=&Ahi}uU>y{Ii69ieM}-+~A55N?q& z&b$<#DwRs*|KT5a_e&ZbqWHf60000< KMNUMnLSTZK%c`yb literal 0 HcmV?d00001 diff --git a/apps/widcw/widget.svg b/apps/widcw/widget.svg new file mode 100644 index 000000000..d3e567286 --- /dev/null +++ b/apps/widcw/widget.svg @@ -0,0 +1,55 @@ + + + + + + + + CW + +