Notifications - fullscreen now works with Bangle.js 2, and better supports themes

master
Gordon Williams 2021-09-21 10:50:04 +01:00
parent aaea30f303
commit 3b15a7f922
6 changed files with 32 additions and 25 deletions

View File

@ -94,7 +94,7 @@
"name": "Notifications (default)", "name": "Notifications (default)",
"shortName":"Notifications", "shortName":"Notifications",
"icon": "notify.png", "icon": "notify.png",
"version":"0.09", "version":"0.10",
"description": "A handler for displaying notifications that displays them in a bar at the top of the screen", "description": "A handler for displaying notifications that displays them in a bar at the top of the screen",
"tags": "widget", "tags": "widget",
"type": "notify", "type": "notify",
@ -107,9 +107,9 @@
"name": "Fullscreen Notifications", "name": "Fullscreen Notifications",
"shortName":"Notifications", "shortName":"Notifications",
"icon": "notify.png", "icon": "notify.png",
"version":"0.10", "version":"0.11",
"description": "A handler for displaying notifications that displays them fullscreen. This may not fully restore the screen after on some apps. See `Notifications (default)` for more information about the notifications library.", "description": "A handler for displaying notifications that displays them fullscreen. This may not fully restore the screen after on some apps. See `Notifications (default)` for more information about the notifications library.",
"tags": "widget", "tags": "widget,b2",
"type": "notify", "type": "notify",
"storage": [ "storage": [
{"name":"notify","url":"notify.js"} {"name":"notify","url":"notify.js"}
@ -155,7 +155,7 @@
"icon": "app.png", "icon": "app.png",
"version":"0.24", "version":"0.24",
"description": "The default notification handler for Gadgetbridge notifications from Android", "description": "The default notification handler for Gadgetbridge notifications from Android",
"tags": "tool,system,android,widget", "tags": "tool,system,android,widget,b2",
"readme": "README.md", "readme": "README.md",
"type":"widget", "type":"widget",
"dependencies": { "notify":"type" }, "dependencies": { "notify":"type" },

View File

@ -6,3 +6,4 @@
0.07: Auto-calculate height, and pad text down even when there's no title (so it stays on-screen) 0.07: Auto-calculate height, and pad text down even when there's no title (so it stays on-screen)
0.08: Don't turn on screen during Quiet Mode 0.08: Don't turn on screen during Quiet Mode
0.09: Add onHide callback 0.09: Add onHide callback
0.10: Improvements to help notifications work with themes

View File

@ -5,6 +5,10 @@ A handler for displaying notifications that displays them in a bar at the top of
This is not an app, but instead it is a library that can be used by This is not an app, but instead it is a library that can be used by
other applications or widgets to display messages. other applications or widgets to display messages.
**Note:** There are other implementations of this library available such
as `notifyfs` (Fullscreen Notifications). These can be used in the exact
same way from code, but they look different to the user.
## Usage ## Usage
```JS ```JS

View File

@ -96,15 +96,17 @@ exports.show = function(options) {
b = y+h-1, r = x+w-1; // bottom,right b = y+h-1, r = x+w-1; // bottom,right
g.setClipRect(x,y, r,b); g.setClipRect(x,y, r,b);
// clear area // clear area
g.setColor(options.bgColor||0).fillRect(x,y, r,b); g.reset();
if (options.bgColor!==undefined) g.setColor(options.bgColor);
g.clearRect(x,y, r,b);
// bottom border // bottom border
g.setColor(0x39C7).fillRect(0,b-1, r,b); g.setColor("#333").fillRect(0,b-1, r,b);
b -= 2;h -= 2; b -= 2;h -= 2;
// title bar // title bar
if (options.title || options.src) { if (options.title || options.src) {
g.setColor(options.titleBgColor||0x39C7).fillRect(x,y, r,y+20); g.setColor(options.titleBgColor||0x39C7).fillRect(x,y, r,y+20);
const title = options.title||options.src; const title = options.title||options.src;
g.setColor(-1).setFontAlign(-1, -1, 0).setFont("6x8", 2); g.setColor(g.theme.fg).setFontAlign(-1, -1, 0).setFont("6x8", 2);
g.drawString(title.trim().substring(0, 13), x+25,y+3); g.drawString(title.trim().substring(0, 13), x+25,y+3);
if (options.title && options.src) { if (options.title && options.src) {
g.setFont("6x8", 1).setFontAlign(1, 1, 0); g.setFont("6x8", 1).setFontAlign(1, 1, 0);
@ -122,7 +124,7 @@ exports.show = function(options) {
} }
// body text // body text
if (options.body) { if (options.body) {
g.setColor(-1).setFont("6x8", 1).setFontAlign(-1, -1, 0).drawString(text, x+6,y+4); g.setColor(g.theme.fg).setFont("6x8", 1).setFontAlign(-1, -1, 0).drawString(text, x+6,y+4);
} }
if (options.render) { if (options.render) {

View File

@ -8,3 +8,4 @@
0.08: Don't turn on screen during Quiet Mode 0.08: Don't turn on screen during Quiet Mode
0.09: Add onHide callback 0.09: Add onHide callback
0.10: Ensure dismissing a notification dismissal doesn't enter launcher if in clock mode 0.10: Ensure dismissing a notification dismissal doesn't enter launcher if in clock mode
0.11: Improvements to help notifications work with themes, Bangle.js 2 support

View File

@ -50,22 +50,24 @@ exports.show = function(options) {
if (options.on===undefined) options.on=true; if (options.on===undefined) options.on=true;
id = ("id" in options)?options.id:null; id = ("id" in options)?options.id:null;
let size = options.size||120; let size = options.size||120;
if (size>120) {size=120} if (size>120) size=120;
Bangle.setLCDMode("direct"); try { Bangle.setLCDMode("direct"); } catch(e) {} // not supported/needed on Bangle.js 2
let x = 0, let x = 0,
y = 40, y = 40,
w = 240, w = g.getWidth(),
h = size; h = size;
// clear screen // clear screen
g.setColor(options.bgColor||0).fillRect(0,0,g.getWidth(),g.getHeight()); g.reset();
if (options.bgColor!==undefined) g.setColor(options.bgColor);
g.clearRect(0,0,g.getWidth(),g.getHeight());
// top bar // top bar
if (options.title||options.src) { if (options.title||options.src) {
const title = options.title || options.src const title = options.title || options.src;
g.setColor(options.titleBgColor||0x39C7).fillRect(x, y, x+w-1, y+30); g.setColor(options.titleBgColor||"#333").fillRect(x, y, x+w-1, y+30);
g.setColor(-1).setFontAlign(-1, -1, 0).setFont("6x8", 3); g.setColor(g.theme.fg).setFontAlign(-1, -1, 0).setFont("6x8", 3);
g.drawString(title.trim().substring(0, 13), x+5, y+3); g.drawString(title.trim().substring(0, 13), x+5, y+3);
if (options.title && options.src) { if (options.title && options.src) {
g.setColor(-1).setFontAlign(1, 1, 0).setFont("6x8", 2); g.setColor(g.theme.fg).setFontAlign(1, 1, 0).setFont("6x8", 2);
// above drawing area, but we are fullscreen // above drawing area, but we are fullscreen
g.drawString(options.src.substring(0, 10), w-16, y-4); g.drawString(options.src.substring(0, 10), w-16, y-4);
} }
@ -73,8 +75,8 @@ exports.show = function(options) {
} }
if (options.icon) { if (options.icon) {
let i = options.icon, iw,ih; let i = options.icon, iw,ih;
if ("string"==typeof i) {iw=i.charCodeAt(0); ih=i.charCodeAt(1)} if ("string"==typeof i) {iw=i.charCodeAt(0); ih=i.charCodeAt(1);}
else {iw=i[0]; ih=i[1]} else {iw=i[0]; ih=i[1];}
const iy=y ? (y+4) : (h-ih)/2; // show below title bar if present, otherwise center vertically const iy=y ? (y+4) : (h-ih)/2; // show below title bar if present, otherwise center vertically
g.drawImage(i, x+4,iy); g.drawImage(i, x+4,iy);
x += iw+4;w -= iw+4; x += iw+4;w -= iw+4;
@ -84,16 +86,13 @@ exports.show = function(options) {
const maxRows = Math.floor((h-4)/16), // font=2*(6x8) const maxRows = Math.floor((h-4)/16), // font=2*(6x8)
maxChars = Math.floor((w-4)/12), maxChars = Math.floor((w-4)/12),
text=fitWords(options.body, maxRows, maxChars); text=fitWords(options.body, maxRows, maxChars);
g.setColor(-1).setFont("6x8", 2).setFontAlign(-1, -1, 0).drawString(text, x+4, y+4); g.setColor(g.theme.fg).setFont("6x8", 2).setFontAlign(-1, -1, 0).drawString(text, x+4, y+4);
} }
if (options.render) { if (options.render)
const area={x:x, y:y, w:w, h:h} options.render({x:x, y:y, w:w, h:h});
options.render(area); if (options.on && !(require('Storage').readJSON('setting.json',1)||{}).quiet)
}
if (options.on && !(require('Storage').readJSON('setting.json',1)||{}).quiet) {
Bangle.setLCDPower(1); // light up Bangle.setLCDPower(1); // light up
}
Bangle.on("touch", exports.hide); Bangle.on("touch", exports.hide);
if (options.onHide) if (options.onHide)
hideCallback = options.onHide; hideCallback = options.onHide;