Skip to content

Commit

Permalink
Added ability to have fullscreen notifications (fix #130)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Jun 4, 2020
1 parent 8c230be commit dc8d2fc
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@
{"name":"notify","url":"notify.js"}
]
},
{ "id": "notifyfs",
"name": "Fullscreen Notifications",
"shortName":"Notifications",
"icon": "notify.png",
"version":"0.01",
"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",
"type": "notify",
"storage": [
{"name":"notify","url":"notify.js"}
]
},
{ "id": "welcome",
"name": "Welcome",
"icon": "app.png",
Expand Down
1 change: 1 addition & 0 deletions apps/notifyfs/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.01: New Library!
92 changes: 92 additions & 0 deletions apps/notifyfs/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
var pos = 0;
var oldg;

/**
options = {
on : bool // turn screen on, default true
size : int // height of notification, default 120 (max)
title : string // optional title
src : string // optional source name
body : string // optional body text
icon : string // optional icon (image string)
render function(y) // function callback to render
}
*/
exports.show = function(options) {
if (oldg) g=oldg;
options = options||{};
if (options.on===undefined) options.on=true;
var h = options.size||120;
Bangle.setLCDMode("direct");
var y = 40;
var x = 4;
// clear area
g.clear(1);
// top bar
var top = 0;
if (options.title) {
g.setColor(0x39C7).fillRect(0, y, 239, y+30);
g.setColor(-1).setFontAlign(-1, -1, 0).setFont("6x8", 3);
g.drawString(options.title.trim().substring(0, 13), 5, y+3);
y+=30;
}
if (options.src) {
g.setColor(-1).setFontAlign(1, 1, 0).setFont("6x8", 2);
g.drawString(options.src.substring(0, 10), 235, y-32);
}
if (options.icon) {
let i = options.icon;
g.drawImage(i, x,y+4);
if ("string"==typeof i) x += i.charCodeAt(0);
else x += i[0];
}
// body text
if (options.body) {
var body = options.body;
const maxChars = Math.floor((300-x)/16);
var limit = maxChars;
let row = 1;
let words = body.trim().replace("\n", " ").split(" ");
body = "";
for (var i = 0; i < words.length; i++) {
if (body.length + words[i].length + 1 > limit) {
if (row>=8) {
body += "...";
break;
}
body += "\n " + words[i];
row++;
limit += maxChars;
if (row==8) limit -= 4;
} else {
body += " " + words[i];
}
}
g.setColor(-1).setFont("6x8", 2).setFontAlign(-1, -1, 0).drawString(body, x-4, y+4);
}

if (options.render) options.render(320 - h);

if (options.on) Bangle.setLCDPower(1); // light up
Bangle.on("touch", exports.hide);
// Create a fake graphics to hide draw attempts
oldg = g;
g = Graphics.createArrayBuffer(8,8,1);
g.flip = function() {};
};

exports.hide = function() {
g=oldg;
oldg = undefined;
Bangle.removeListener("touch", exports.hide);
g.clear();
Bangle.drawWidgets();
// flipping the screen off then on often triggers a redraw - it may not!
Bangle.setLCDPower(0);
Bangle.setLCDPower(1);
// hack for E.showMenu/showAlert/showPrompt - can force a redraw by faking next/back
if (Bangle.btnWatches) {
global["\xff"].watches[Bangle.btnWatches[0]].callback();
global["\xff"].watches[Bangle.btnWatches[1]].callback();
}
};
Binary file added apps/notifyfs/notify.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dc8d2fc

Please sign in to comment.