Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

voldisp: new app that displays volume change on Android device #3780

Merged
merged 9 commits into from
Mar 25, 2025
1 change: 1 addition & 0 deletions apps/voldisp/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.01: New App!
Binary file added apps/voldisp/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions apps/voldisp/boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
const WIDGET_UTILS_HIDE = function() {
//exports.cleanup();
if (!global.WIDGETS) return;
g.reset(); // reset colors
for (var w of global.WIDGETS) {
if (w._draw) return; // already hidden
w._draw = w.draw;
w.draw = () => {};
w._area = w.area;
w.area = "";
if (w.x!=undefined) g.clearRect(w.x,w.y,w.x+w.width-1,w.y+23);
}
};
/// Show any hidden widgets
const WIDGET_UTILS_SHOW = function() {
//exports.cleanup();
if (!global.WIDGETS) return;
for (var w of global.WIDGETS) {
if (!w._draw) return; // not hidden
w.draw = w._draw;
w.area = w._area;
delete w._draw;
delete w._area;
w.draw(w);
}
};

let isWeHidingTheWidgets = false;
let timeout;
let onMusicVolume = (volPercent)=>{
if (timeout) {clearTimeout(timeout);}

if (Bangle.CLOCK) {

let isAllWidgetsHidden = true;
if (!timeout) { // No need to do this if we already did it before and it wasn't undone. I.e. the timout to execute `goAway` never ran out.
if (global.WIDGETS) {
for (var w of global.WIDGETS) {
if (!w._draw) {
isAllWidgetsHidden = false;
break;
}
}
}
if (!isAllWidgetsHidden) {
WIDGET_UTILS_HIDE();
isWeHidingTheWidgets = true; // Remember if it was we who hid the widgets between draws of the volume bar.
}
}
let barWidth = g.getWidth()*volPercent/100;
g.
setColor(0x0000).fillRect(0,0,g.getWidth(),24).
setColor(0xF800).fillRect(0,0,barWidth,19).
setColor(0xFFFF).setFont("12x20").setFontAlign(1,-1).
drawString("volume",barWidth,1);

let goAway = ()=>{
if (isWeHidingTheWidgets) {
g.reset().clearRect(0,0,g.getWidth(),24);
WIDGET_UTILS_SHOW();
isWeHidingTheWidgets = false;
} else if (Bangle.uiRedraw) {
Bangle.uiRedraw();
} else {
Bangle.load();
}
timeout = undefined;
};
timeout = setTimeout(goAway, 3*1000);
}
};
Bangle.on("musicVolume", onMusicVolume);
//GB({t:"audio",v:66});
}
15 changes: 15 additions & 0 deletions apps/voldisp/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ "id": "voldisp",
"name": "Display Volume for Android",
"version":"0.01",
"description": "Display the media volume of your android device when it's changed. A bar shows up at the top of your Bangles screen. (Needs recent Gadgetbridge nightly or stable ver. 85 once out)",
"icon": "app.png",
"tags": "audio,media,android,volume,sound",
"type": "bootloader",
"supports" : ["BANGLEJS2"],
"screenshots" : [
{ "url":"screenshot.png" }
],
"storage": [
{"name":"voldisp.boot.js","url":"boot.js"}
]
}
Binary file added apps/voldisp/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.