diff --git a/apps.json b/apps.json index c379a1de4..0a69096c8 100644 --- a/apps.json +++ b/apps.json @@ -4858,7 +4858,7 @@ "id": "ptlaunch", "name": "Pattern Launcher", "shortName": "Pattern Launcher", - "version": "0.10", + "version": "0.11", "description": "Directly launch apps from the clock screen with custom patterns.", "icon": "app.png", "screenshots": [{"url":"main_menu_add.png"}, {"url":"add_pattern.png"}, {"url":"select_app.png"}, {"url":"main_menu_manage.png"}, {"url":"manage_patterns.png"}], diff --git a/apps/ptlaunch/ChangeLog b/apps/ptlaunch/ChangeLog index de38d715a..23031cff3 100644 --- a/apps/ptlaunch/ChangeLog +++ b/apps/ptlaunch/ChangeLog @@ -1,4 +1,5 @@ 0.01: Initial creation of the pattern launch app 0.02: Turn on lcd when launching an app if the lock screen was disabled in the settings 0.03: Make tap to confirm new pattern more reliable. Also allow for easier creation of single circle patterns. -0.10: Improve the management of existing patterns: Draw the linked pattern on the left hand side of the app name within a scroller, similar to the default launcher. Slighlty clean up the code to make it less horrible. \ No newline at end of file +0.10: Improve the management of existing patterns: Draw the linked pattern on the left hand side of the app name within a scroller, similar to the default launcher. Slighlty clean up the code to make it less horrible. +0.11: Respect theme colors. Fix: Do not pollute global space with internal variables ans functions in boot.js \ No newline at end of file diff --git a/apps/ptlaunch/app.js b/apps/ptlaunch/app.js index b5a3bf610..9cd566e3d 100644 --- a/apps/ptlaunch/app.js +++ b/apps/ptlaunch/app.js @@ -119,8 +119,7 @@ var recognizeAndDrawPattern = () => { return new Promise((resolve) => { E.showMenu(); g.clear(); - g.setColor(0, 0, 0); - CIRCLES.forEach((circle) => drawCircle(circle)); + drawCirclesWithPattern([]); var pattern = []; @@ -369,7 +368,6 @@ var drawAppWithPattern = (i, r, storedPatterns) => { offset: { x: 1, y: 3 + r.y }, }); - g.setColor(0, 0, 0); if (!storedPattern.wrappedAppName) { storedPattern.wrappedAppName = g .wrapString(app.name, g.getWidth() - 64) @@ -490,7 +488,10 @@ var drawCircle = (circle, drawBuffer, scale) => { log("drawing circle"); log({ x: x, y: y, r: r }); + drawBuffer.setColor(0); drawBuffer.fillCircle(x, y, r); + drawBuffer.setColor(1); + drawBuffer.drawCircle(x, y, r); }; var cachedCirclesDrawings = {}; @@ -535,17 +536,16 @@ var drawCirclesWithPattern = (pattern, options) => { { msb: true } ); - drawBuffer.setColor(1); CIRCLES.forEach((circle) => drawCircle(circle, drawBuffer, scale)); - drawBuffer.setColor(0); + drawBuffer.setColor(1); drawBuffer.setFontAlign(0, 0); - drawBuffer.setFont("6x8", 4 * scale); + drawBuffer.setFont("Vector", scale === 1 ? 40 : 20); pattern.forEach((circleIndex, patternIndex) => { var circle = CIRCLES[circleIndex]; drawBuffer.drawString( patternIndex + 1, - circle.x * scale, + (circle.x + 5) * scale, circle.y * scale ); }); diff --git a/apps/ptlaunch/boot.js b/apps/ptlaunch/boot.js index a23607768..6fbd3ca41 100644 --- a/apps/ptlaunch/boot.js +++ b/apps/ptlaunch/boot.js @@ -1,167 +1,167 @@ -var DEBUG = true; -var log = (message) => { - if (DEBUG) { - console.log(JSON.stringify(message)); - } -}; - -var storedPatterns; -var positions = []; -var dragHandler = (position) => { - positions.push(position); - - debounce().then(() => { - log(positions.length); - - var CIRCLE_RADIUS = 25; - var CIRCLE_RADIUS_2 = CIRCLE_RADIUS * CIRCLE_RADIUS; - - var circles = [ - { x: 25, y: 25, i: 0 }, - { x: 87, y: 25, i: 1 }, - { x: 150, y: 25, i: 2 }, - { x: 25, y: 87, i: 3 }, - { x: 87, y: 87, i: 4 }, - { x: 150, y: 87, i: 5 }, - { x: 25, y: 150, i: 6 }, - { x: 87, y: 150, i: 7 }, - { x: 150, y: 150, i: 8 }, - ]; - var pattern = []; - - var step = Math.floor(positions.length / 100) + 1; - - var p, a, b, circle; - - for (var i = 0; i < positions.length; i += step) { - p = positions[i]; - - circle = circles[0]; - if (circle) { - a = p.x - circle.x; - b = p.y - circle.y; - if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { - pattern.push(circle.i); - circles.splice(0, 1); - } - } - - circle = circles[1]; - if (circle) { - a = p.x - circle.x; - b = p.y - circle.y; - if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { - pattern.push(circle.i); - circles.splice(1, 1); - } - } - - circle = circles[2]; - if (circle) { - a = p.x - circle.x; - b = p.y - circle.y; - if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { - pattern.push(circle.i); - circles.splice(2, 1); - } - } - - circle = circles[3]; - if (circle) { - a = p.x - circle.x; - b = p.y - circle.y; - if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { - pattern.push(circle.i); - circles.splice(3, 1); - } - } - - circle = circles[4]; - if (circle) { - a = p.x - circle.x; - b = p.y - circle.y; - if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { - pattern.push(circle.i); - circles.splice(4, 1); - } - } - - circle = circles[5]; - if (circle) { - a = p.x - circle.x; - b = p.y - circle.y; - if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { - pattern.push(circle.i); - circles.splice(5, 1); - } - } - - circle = circles[6]; - if (circle) { - a = p.x - circle.x; - b = p.y - circle.y; - if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { - pattern.push(circle.i); - circles.splice(6, 1); - } - } - circle = circles[7]; - if (circle) { - a = p.x - circle.x; - b = p.y - circle.y; - if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { - pattern.push(circle.i); - circles.splice(7, 1); - } - } - - circle = circles[8]; - if (circle) { - a = p.x - circle.x; - b = p.y - circle.y; - if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { - pattern.push(circle.i); - circles.splice(8, 1); - } - } - } - positions = []; - - pattern = pattern.join(""); - - if (pattern) { - if (storedPatterns[pattern]) { - var app = storedPatterns[pattern].app; - if (!!app && !!app.src) { - if (storedPatterns.settings) { - if (storedPatterns.settings.lockDisabled) { - Bangle.setLCDPower(true); - } - } - - Bangle.removeListener("drag", dragHandler); - load(app.src); - } - } - } - }); -}; - -var debounceTimeoutId; -var debounce = (delay) => { - if (debounceTimeoutId) { - clearTimeout(debounceTimeoutId); - } - - return new Promise((resolve) => { - debounceTimeoutId = setTimeout(() => { - debounceTimeoutId = undefined; - resolve(); - }, delay || 500); - }); -}; - (function () { + var DEBUG = false; + var log = (message) => { + if (DEBUG) { + console.log(JSON.stringify(message)); + } + }; + + var storedPatterns; + var positions = []; + var dragHandler = (position) => { + positions.push(position); + + debounce().then(() => { + log(positions.length); + + var CIRCLE_RADIUS = 25; + var CIRCLE_RADIUS_2 = CIRCLE_RADIUS * CIRCLE_RADIUS; + + var circles = [ + { x: 25, y: 25, i: 0 }, + { x: 87, y: 25, i: 1 }, + { x: 150, y: 25, i: 2 }, + { x: 25, y: 87, i: 3 }, + { x: 87, y: 87, i: 4 }, + { x: 150, y: 87, i: 5 }, + { x: 25, y: 150, i: 6 }, + { x: 87, y: 150, i: 7 }, + { x: 150, y: 150, i: 8 }, + ]; + var pattern = []; + + var step = Math.floor(positions.length / 100) + 1; + + var p, a, b, circle; + + for (var i = 0; i < positions.length; i += step) { + p = positions[i]; + + circle = circles[0]; + if (circle) { + a = p.x - circle.x; + b = p.y - circle.y; + if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { + pattern.push(circle.i); + circles.splice(0, 1); + } + } + + circle = circles[1]; + if (circle) { + a = p.x - circle.x; + b = p.y - circle.y; + if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { + pattern.push(circle.i); + circles.splice(1, 1); + } + } + + circle = circles[2]; + if (circle) { + a = p.x - circle.x; + b = p.y - circle.y; + if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { + pattern.push(circle.i); + circles.splice(2, 1); + } + } + + circle = circles[3]; + if (circle) { + a = p.x - circle.x; + b = p.y - circle.y; + if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { + pattern.push(circle.i); + circles.splice(3, 1); + } + } + + circle = circles[4]; + if (circle) { + a = p.x - circle.x; + b = p.y - circle.y; + if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { + pattern.push(circle.i); + circles.splice(4, 1); + } + } + + circle = circles[5]; + if (circle) { + a = p.x - circle.x; + b = p.y - circle.y; + if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { + pattern.push(circle.i); + circles.splice(5, 1); + } + } + + circle = circles[6]; + if (circle) { + a = p.x - circle.x; + b = p.y - circle.y; + if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { + pattern.push(circle.i); + circles.splice(6, 1); + } + } + circle = circles[7]; + if (circle) { + a = p.x - circle.x; + b = p.y - circle.y; + if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { + pattern.push(circle.i); + circles.splice(7, 1); + } + } + + circle = circles[8]; + if (circle) { + a = p.x - circle.x; + b = p.y - circle.y; + if (CIRCLE_RADIUS_2 - (a * a + b * b) >= 0) { + pattern.push(circle.i); + circles.splice(8, 1); + } + } + } + positions = []; + + pattern = pattern.join(""); + + if (pattern) { + if (storedPatterns[pattern]) { + var app = storedPatterns[pattern].app; + if (!!app && !!app.src) { + if (storedPatterns.settings) { + if (storedPatterns.settings.lockDisabled) { + Bangle.setLCDPower(true); + } + } + + Bangle.removeListener("drag", dragHandler); + load(app.src); + } + } + } + }); + }; + + var debounceTimeoutId; + var debounce = (delay) => { + if (debounceTimeoutId) { + clearTimeout(debounceTimeoutId); + } + + return new Promise((resolve) => { + debounceTimeoutId = setTimeout(() => { + debounceTimeoutId = undefined; + resolve(); + }, delay || 500); + }); + }; + var sui = Bangle.setUI; Bangle.setUI = function (mode, cb) { sui(mode, cb);