|
| 1 | +{ // must be inside our own scope here so that when we are unloaded everything disappears |
| 2 | + |
| 3 | +let settings; |
| 4 | +let getSettings=function(){ |
| 5 | + settings = Object.assign( |
| 6 | + require("Storage").readJSON("dailycolorclk.default.json", true) || {}, |
| 7 | + require("Storage").readJSON("dailycolorclk.json", true) || {} |
| 8 | + ); |
| 9 | +} |
| 10 | +let writeSettings=function(){ |
| 11 | + require("Storage").writeJSON("dailycolorclk.json", settings); |
| 12 | +} |
| 13 | +getSettings(); |
| 14 | + |
| 15 | +const fontBitmap = E.toString(require('heatshrink').decompress(atob('AC1+A40H/gIGn/4A4sB//wDI3/8AIFj//wAIFv/+EQ4rGESROHDI4rBCA0BGYwAKDYI+Ogf/MI1/MI0P/4iFFIIABEQk/A4IiEPIIZGFIP/OQgpC//AFIw7EFIR6EFJAHCFJBLDFMKWBFJPwHQ6XEGQS6FFIy5CYQwiBFIgiCZQwiBcgwAkNQRQFa4SUIBAgQDBAZpCAAJbDToYsEA4bJDFQh+DaAagEA4iYCDIo9CGYg0DJoIVBVQZNBF4QeBFYIMBX4QEDn5SDj5gCZAl/K4IiB4CXDEQaPEERZ1CAgYdBCIRbBE4JoRRaDhCDIquIK4IZFaJIIEOoQ9EdYYRECAYsDOgYAaMAIoEFQYRGV4gZEaQbEGDIpcEYgYZIHgzeDDIrRGga3HbQovCv4IEF4IZFEQTIFEQQZFEQLrFEQTrFEQQ8FESYASg4VHZAcDBgUfZAc/Vw0BBgSuEj4MCn4iDBgROBCoT4DAYKhDBgQZBPwZoEBg4VBWQSLDCoIDBRYnADoQMBCoIDBYYQiBIAauEn4dBXQQiCDISxCEQfAZYYiEJgIiE/z/DEQYADv7RG/L0Hw70G/i7DGIfAEQQrD/wnBVwYAB8AnBboRLDEQZ/CNQQiCBAQeCbwYQCEQYICAYQiCCwIDCADEBwAIGg/gBoYvCj5NCAgl/CIZ1EKwRSDAYIsCcYRaECoIiDQQgiD/CuDEQY0BBgIiEaIYiDaInB/+Begn+g/+AgIrBX4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EQJJBAAP9NCiLOW4QrDW4jIBAAbiD//7DIhgB/+PZAg9B/guBfogNBFwJNBAAitDBAoQGAB9/HIQADHQJcCHggIGPQQaFToSrBAASUDKYxmDmAZEXoMDVwpeBn6uFfoLRGwE/aIv+fIUAg4DBv/4XYK/CHQP/8L0DGIIcBz42CDoOAH4YiBh4ZBH4YiCaoLlCEQxZDIAQ/BQoYFBKgL0EQQODCAhoECAYoDWAhLDHYZLEYIiuCCAhUDaQoQHGgYQEBAQQEHob0FBAJUCAAjqCAD8DBA9/SIM/SgQ9CKQQIDj7TCIAhOCv5iDDILTCLQaeBaYXgSoihCFYaCCv4rDERrBEIoQlBFYfwAQKXENAV/VAl4AQN+RJQ='))); |
| 16 | + |
| 17 | +Graphics.prototype.setFontPaytoneOne = function(scale) { |
| 18 | + this.setFontCustom(fontBitmap, 46, atob("ER0mGCMjJiMkIiUkEg=="), 70|65536); |
| 19 | + return this; |
| 20 | +} |
| 21 | + |
| 22 | +let drawTimeout; |
| 23 | + |
| 24 | + |
| 25 | +const slopeHeight = 90; |
| 26 | +const fontBorder = 13; |
| 27 | +const hoursYPos=68; |
| 28 | +const minOffset=4; //offset from slope |
| 29 | +const slopeBorder = 4; |
| 30 | + |
| 31 | +let R; |
| 32 | +let dateStr = ""; |
| 33 | +let bgColor = settings.colorSaved; |
| 34 | +let changeBGColor = function() { |
| 35 | + let bgColors = []; |
| 36 | + if (settings.colorYellow) bgColors.push("#ff0"); |
| 37 | + if (settings.colorCyan) bgColors.push("#0ff"); |
| 38 | + if (settings.colorMagenta) bgColors.push("#f0f"); |
| 39 | + if (settings.colorWhite) bgColors.push("#fff"); |
| 40 | + if (settings.colorRed) bgColors.push("#f00"); |
| 41 | + if (settings.colorGreen) bgColors.push("#0f0"); |
| 42 | + if (settings.colorBlue) bgColors.push("#00f"); |
| 43 | + if (settings.colorOrange) bgColors.push("#FC6A03"); |
| 44 | + if (settings.colorPurple) bgColors.push("#B200ED"); |
| 45 | + if (settings.colorBlack) bgColors.push("#000"); |
| 46 | + |
| 47 | + let oldColorIdx = bgColors.indexOf(settings.colorSaved); |
| 48 | + if (oldColorIdx !== -1) bgColors.splice(oldColorIdx, 1); |
| 49 | + let col = bgColors[(Math.random()*bgColors.length)|0] || "#000"; |
| 50 | + |
| 51 | + settings.colorSaved = col; |
| 52 | + writeSettings(); |
| 53 | +} |
| 54 | +let checkForColorChange = function() { |
| 55 | + let dayNow = new Date().getDay(); |
| 56 | + if (settings.dayChanged != dayNow) { |
| 57 | + settings.dayChanged = dayNow; |
| 58 | + changeBGColor(); |
| 59 | + load(); |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +//draws bg color once, erases background |
| 64 | +let preDraw=function(){ |
| 65 | + g.setColor(g.theme.bg).fillRect(0,0,g.getWidth(),g.getHeight()); |
| 66 | + g.setColor(bgColor).fillRect( |
| 67 | + 0,slopeHeight,g.getWidth(), g.getHeight() |
| 68 | + ); |
| 69 | + |
| 70 | +} |
| 71 | +// Draw the hour, minute, and date |
| 72 | +let draw = function() { |
| 73 | + |
| 74 | + checkForColorChange(); |
| 75 | + |
| 76 | + if (drawTimeout) clearTimeout(drawTimeout); |
| 77 | + drawTimeout = setTimeout(draw, 60000 - (Date.now() % 60000)); |
| 78 | + |
| 79 | + R = Bangle.appRect; |
| 80 | + |
| 81 | + |
| 82 | + var date = new Date(); |
| 83 | + var local_time = require("locale").time(date, 1); |
| 84 | + var hourStr = " "+local_time.split(":")[0].padStart(2,'0')+" "; |
| 85 | + var minStr = " "+local_time.split(":")[1].padStart(2,'0')+" "; |
| 86 | + |
| 87 | + dateStr = require("locale").dow(date,1) + ', ' + |
| 88 | + require("locale").month(date,1) + " " + date.getDate(); |
| 89 | + |
| 90 | + //clear old hour |
| 91 | + g.setColor(g.theme.bg); |
| 92 | + g.fillRect(0,24,96,88); |
| 93 | + // Draw hour |
| 94 | + g.setColor(g.theme.fg) |
| 95 | + .setFontAlign(-1, 0) |
| 96 | + .setFont("PaytoneOne") |
| 97 | + .drawString(hourStr, fontBorder, hoursYPos); |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | + // draw minutes |
| 105 | + var yo = slopeHeight + minOffset; |
| 106 | + g.setColor(bgColor); |
| 107 | + //clear old minutes |
| 108 | + g.fillRect(92,92,g.getWidth(),152); |
| 109 | + g.setFontAlign(1, -1).setFont("PaytoneOne") |
| 110 | + .setColor(g.theme.bg).drawString(minStr,g.getWidth()-7, yo); |
| 111 | + |
| 112 | + // Transition bar |
| 113 | + g.setColor(g.theme.bg).fillRect( |
| 114 | + 0,slopeHeight-slopeBorder,g.getWidth(), slopeHeight |
| 115 | + ); |
| 116 | + // Draw date |
| 117 | + g.setColor(g.theme.bg) |
| 118 | + .setFontAlign(0, 0) |
| 119 | + .setFont("Vector",16) |
| 120 | + .drawString(dateStr, R.x + R.w/2, R.y+R.h-13); |
| 121 | + |
| 122 | +}; |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +// Clock info menus |
| 127 | +let clockInfoDraw = (itm, info, options) => { |
| 128 | + let texty = options.y+41; |
| 129 | + g.reset().setClipRect(options.x, options.y, options.x+options.w-1, options.y+options.h-1); |
| 130 | + g.setFont("Vector",15).setBgColor(options.bg).clearRect(options.x, texty-15, options.x+options.w-2, texty); |
| 131 | + |
| 132 | + g.setColor(options.focus ? options.hl : options.fg); |
| 133 | + if (options.x < g.getWidth()/2) { |
| 134 | + let x = options.x+2; |
| 135 | + if (info.img) g.clearRect(x, options.y, x+23, options.y+23).drawImage(info.img, x, options.y); |
| 136 | + g.setFontAlign(-1,1).drawString(info.text, x,texty); |
| 137 | + } else { |
| 138 | + let x = options.x+options.w-3; |
| 139 | + if (info.img) g.clearRect(x-23, options.y, x, options.y+23).drawImage(info.img, x-23, options.y); |
| 140 | + g.setFontAlign(1,1).drawString(info.text, x,texty); |
| 141 | + } |
| 142 | + g.setClipRect(0,0,g.getWidth()-1, g.getHeight()-1); |
| 143 | +}; |
| 144 | + |
| 145 | +let clockInfoItems = require("clock_info").load(); |
| 146 | +let clockInfoMenu = require("clock_info").addInteractive(clockInfoItems, { |
| 147 | + app:"slopeclockpp",x:98, y:38, w:70, h:50, |
| 148 | + draw : clockInfoDraw, bg : g.theme.bg, fg : g.theme.fg, hl : |
| 149 | + (g.theme.fg===g.toColor(bgColor))?"#f00":bgColor |
| 150 | +}); |
| 151 | +let clockInfoMenu2 = require("clock_info").addInteractive(clockInfoItems, { |
| 152 | + app:"slopeclockpp",x:10, y:102, w:70, h:50, |
| 153 | + draw : clockInfoDraw, bg : bgColor, fg : g.theme.bg, hl : |
| 154 | + (g.theme.fg===g.toColor(bgColor))?"#f00":g.theme.fg |
| 155 | +}); |
| 156 | + |
| 157 | +// Show launcher when middle button pressed |
| 158 | +Bangle.setUI({ |
| 159 | + mode : "clock", |
| 160 | + remove : function() { |
| 161 | + if (drawTimeout) clearTimeout(drawTimeout); |
| 162 | + drawTimeout = undefined; |
| 163 | + delete Graphics.prototype.setFontPaytoneOne; |
| 164 | + clockInfoMenu.remove(); |
| 165 | + delete clockInfoMenu; |
| 166 | + clockInfoMenu2.remove(); |
| 167 | + delete clockInfoMenu2; |
| 168 | + }, |
| 169 | + redraw: draw, |
| 170 | +}); |
| 171 | + |
| 172 | +Bangle.loadWidgets(); |
| 173 | +if (settings.hideWidgets) require("widget_utils").swipeOn(); |
| 174 | +else setTimeout(Bangle.drawWidgets,0); |
| 175 | +preDraw(); |
| 176 | +draw(); |
| 177 | +clockInfoMenu.redraw(); |
| 178 | +clockInfoMenu2.redraw(); |
| 179 | + |
| 180 | +} |
0 commit comments