From a7ad62a030c46162b8e0c44e7597dccdb9028177 Mon Sep 17 00:00:00 2001 From: Kedlub Date: Tue, 22 Nov 2022 13:52:21 +0100 Subject: [PATCH] qcenter: New app --- apps/qcenter/ChangeLog | 1 + apps/qcenter/README.md | 20 +++++++ apps/qcenter/app-icon.js | 1 + apps/qcenter/app.js | 114 +++++++++++++++++++++++++++++++++++++ apps/qcenter/app.png | Bin 0 -> 265 bytes apps/qcenter/metadata.json | 14 +++++ apps/qcenter/settings.js | 114 +++++++++++++++++++++++++++++++++++++ 7 files changed, 264 insertions(+) create mode 100644 apps/qcenter/ChangeLog create mode 100644 apps/qcenter/README.md create mode 100644 apps/qcenter/app-icon.js create mode 100644 apps/qcenter/app.js create mode 100644 apps/qcenter/app.png create mode 100644 apps/qcenter/metadata.json create mode 100644 apps/qcenter/settings.js diff --git a/apps/qcenter/ChangeLog b/apps/qcenter/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/qcenter/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/qcenter/README.md b/apps/qcenter/README.md new file mode 100644 index 000000000..eb40e63ed --- /dev/null +++ b/apps/qcenter/README.md @@ -0,0 +1,20 @@ +# Quick Center + +App with status bar showing various info, and up to six shortcuts for your favorite apps! +Meant to be used with any kind of quick launcher, such as Quick Launch or Pattern Launcher + +Add screen shots (if possible) to the app folder and link then into this file with ![](.png) + +## Usage + +Pin apps using settings, and then run this using your favorite quick launcher to access them quickly +If you don't have any pinned apps, it shows setting and about app as an example + +## Features + +Showing battery and temperature (for now) +Up to six shortcuts to your favorite apps + +## Upcoming features +- Quick toggles for toggleable functions, such as Bluetooth, or it's HID mode +- Customizable status info \ No newline at end of file diff --git a/apps/qcenter/app-icon.js b/apps/qcenter/app-icon.js new file mode 100644 index 000000000..bfc94d10a --- /dev/null +++ b/apps/qcenter/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4UB6cA/4ACBYNVAElQHAsFBYZFHCxIYEoALHgILNOxILChWqAAmgBYNUBZMVBYIAIBc0C1WAlWoAgQL/O96D/Qf4LZqoLJqoLMoAKHgILNqALHgoLBGBAKCDA4WDAEQA=")) \ No newline at end of file diff --git a/apps/qcenter/app.js b/apps/qcenter/app.js new file mode 100644 index 000000000..0493805ac --- /dev/null +++ b/apps/qcenter/app.js @@ -0,0 +1,114 @@ +require("Font8x12").add(Graphics); + +// load pinned apps from config +var settings = require("Storage").readJSON("qcenter.json", 1) || {}; +var pinnedApps = settings.pinnedApps || []; +var exitGesture = settings.exitGesture || "swipeup"; + +// if empty load a default set of apps as an example +if (pinnedApps.length == 0) { + pinnedApps = [ + { src: "setting.app.js", icon: "setting.img" }, + { src: "about.app.js", icon: "about.img" }, + ]; +} + +// button drawing from Layout.js, edited to have completely custom button size with icon +function drawButton(l) { + var x = l.x + (0 | l.pad), + y = l.y + (0 | l.pad), + w = l.w - (l.pad << 1), + h = l.h - (l.pad << 1); + var poly = [ + x, + y + 4, + x + 4, + y, + x + w - 5, + y, + x + w - 1, + y + 4, + x + w - 1, + y + h - 5, + x + w - 5, + y + h - 1, + x + 4, + y + h - 1, + x, + y + h - 5, + x, + y + 4, + ], + bg = l.selected ? g.theme.bgH : g.theme.bg2; + g.setColor(bg) + .fillPoly(poly) + .setColor(l.selected ? g.theme.fgH : g.theme.fg2) + .drawPoly(poly); + if (l.src) + g.setBgColor(bg).drawImage( + "function" == typeof l.src ? l.src() : l.src, + l.x + l.w / 2, + l.y + l.h / 2, + { scale: l.scale || undefined, rotate: Math.PI * 0.5 * (l.r || 0) } + ); +} + +// function to split array into group of 3, for button placement +function groupBy3(data) { + var result = []; + for (var i = 0; i < data.length; i += 3) result.push(data.slice(i, i + 3)); + return result; +} + +// generate object with buttons for apps by group of 3 +var appButtons = groupBy3(pinnedApps).map((appGroup, i) => { + return appGroup.map((app, j) => { + return { + type: "custom", + render: drawButton, + width: 50, + height: 50, + pad: 5, + src: require("Storage").read(app.icon), + scale: 0.75, + cb: (l) => Bangle.load(app.src), + }; + }); +}); + +// create basic layout content with status info on top +var layoutContent = [ + { + type: "h", + pad: 5, + c: [ + { type: "txt", font: "8x12", label: E.getBattery() + "%" }, + { type: "txt", font: "8x12", label: " " + E.getTemperature() + "°C" }, + ], + }, +]; + +// create rows for buttons and add them to layoutContent +appButtons.forEach((appGroup) => { + layoutContent.push({ + type: "h", + pad: 2, + c: appGroup, + }); +}); + +var Layout = require("Layout"); +var layout = new Layout({ + type: "v", + c: layoutContent, +}); +g.clear(); +layout.render(); + +// add swipe event listener for exit gesture +Bangle.on("swipe", function (lr, ud) { + if(exitGesture == "swipeup" && ud == -1) Bangle.showClock(); + if(exitGesture == "swipedown" && ud == 1) Bangle.showClock(); + if(exitGesture == "swipeleft" && lr == -1) Bangle.showClock(); + if(exitGesture == "swiperight" && lr == 1) Bangle.showClock(); +}); \ No newline at end of file diff --git a/apps/qcenter/app.png b/apps/qcenter/app.png new file mode 100644 index 0000000000000000000000000000000000000000..27ec75f1c09f4503465e233ec2f3183a072d9476 GIT binary patch literal 265 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA3?vioaBc-sjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$1AIbUnWg6a|NkGzlQ=%#3`jAT1o;I61+Jgs1*&D>EbxddW? z8eR=R!75J|#}E(iw-X%s8Wea~HvX^QazJky^R=rk$x|$^bQ!bzludGP7I9GBy!Ou~ z?yX`UOj^{Iv4r?=uGrPThVYYmuN?b(Y0 z?|L^zI2@hQ5Vbty!jZ=o3!gd82{>7@`q { + var a = require("Storage").readJSON(app, 1); + return ( + a && { name: a.name, type: a.type, sortorder: a.sortorder, src: a.src, icon: a.icon } + ); + }) + .filter( + (app) => + app && + (app.type == "app" || + app.type == "launch" || + app.type == "clock" || + !app.type) + ); + apps.sort((a, b) => { + var n = (0 | a.sortorder) - (0 | b.sortorder); + if (n) return n; // do sortorder first + if (a.name < b.name) return -1; + if (a.name > b.name) return 1; + return 0; + }); + + function save(key, value) { + settings[key] = value; + require("Storage").write("qcenter.json", settings); + } + + var pinnedApps = settings.pinnedApps || []; + var exitGesture = settings.exitGesture || "swipeup"; + + function showMainMenu() { + var mainmenu = { + "" : { "title" : "Quick Center" }, + "< Back" : ()=>{load();} + }; + + // Set exit gesture + mainmenu["Exit Gesture: " + exitGesture] = function() { + E.showMenu(exitGestureMenu); + }; + + //List all pinned apps + for (let i = 0; i < pinnedApps.length; i++) { + mainmenu[pinnedApps[i].name] = function() { + E.showMenu({ + "" : { "title" : pinnedApps[i].name }, + "< Back" : showMainMenu, + "Unpin" : function() { + pinnedApps.splice(i, 1); + save("pinnedApps", pinnedApps); + showMainMenu(); + } + }); + }; + } + + // Show pin app button only if there is less than 6 pinned apps, else show the button that shows alert that max apps has been pinned + if (pinnedApps.length < 6) { + mainmenu["Pin App"] = pinAppMenu; + } + else { + mainmenu["Pin App"] = function() { + E.showAlert("You can only pin 6 apps"); + }; + } + + return E.showMenu(mainmenu); + } + + // menu for adding apps to the quick launch menu, listing all apps + var pinAppMenu = { + "" : { "title" : "Add App" }, + "< Back" : showMainMenu + }; + apps.forEach((a)=>{ + pinAppMenu[a.name] = function() { + // strip unncecessary properties + delete a.type; + delete a.sortorder; + delete a.name; + pinnedApps.push(a); + save("pinnedApps", pinnedApps); + showMainMenu(); + }; + }); + + // menu for setting exit gesture + var exitGestureMenu = { + "" : { "title" : "Exit Gesture" }, + "< Back" : showMainMenu + }; + exitGestureMenu["Swipe Up"] = function() { + save("exitGesture", "swipeup"); + showMainMenu(); + } + exitGestureMenu["Swipe Down"] = function() { + save("exitGesture", "swipedown"); + showMainMenu(); + } + exitGestureMenu["Swipe Left"] = function() { + save("exitGesture", "swipeleft"); + showMainMenu(); + } + exitGestureMenu["Swipe Right"] = function() { + save("exitGesture", "swiperight"); + showMainMenu(); + } + +});