Skip to content

Commit 4c10a95

Browse files
author
thyttan
committed
Merge branch 'spotrem' into app-loader
2 parents 910f160 + 9786176 commit 4c10a95

File tree

4 files changed

+152
-6
lines changed

4 files changed

+152
-6
lines changed

apps/spotrem/ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ when fastloading.
1212
0.11: Further refactoring to shorten the code. Fixed search and play that was broken in v0.10.
1313
0.12: Fix some warnings from the linter.
1414
0.13: Move ui-handlers inside setUI-call.
15+
0.14: Add volume knob.
16+

apps/spotrem/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Swipe input:
88

99
Swipe left/right to go to previous/next track. Swipe up/down to change the volume.
1010

11+
If you have changed the volume by swipe up/down, you can use a "volume knob" to continuously change the volume. Clock wise circle gesture on the screen increases volume and vice versa.
12+
1113
It's possible to start tracks by searching with the remote. Search term without tags will override search with tags.
1214

1315
To start playing 'from cold' the command for previous/next track via touch or swipe can be used. Pressing just play/pause is not guaranteed to initiate spotify in all circumstances (this will probably change with subsequent releases).

apps/spotrem/app.js

Lines changed: 147 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,160 @@ let swipeHandler = function(LR, _) {
9797
}
9898
};
9999

100+
let dx = 0;
101+
let dy = 0;
102+
let volumeChangedThisGoAround = false;
103+
let knobTimeout;
104+
let dragHandler = function(e) {
105+
106+
let cb = ud => {
107+
if (ud) Bangle.musicControl(ud<0 ? "volumedown" : "volumeup");
108+
}
109+
110+
let resetOuterScopeVariables = ()=>{
111+
dy=0;
112+
dx=0;
113+
volumeChangedThisGoAround=false;
114+
}
115+
116+
dx += e.dx;
117+
dy += e.dy;
118+
if (!e.b) {resetOuterScopeVariables();}
119+
120+
while (Math.abs(dy)>32) {
121+
if (dy>0) { dy-=32; cb(-1) }
122+
else { dy+=32; cb(1) }
123+
volumeChangedThisGoAround = true;
124+
Bangle.buzz(20);
125+
}
126+
127+
if (volumeChangedThisGoAround && Math.abs(dx)>32) {
128+
// setup volume knob here.
129+
cb(Math.sign(dx))
130+
resetOuterScopeVariables();
131+
let volumeKnob = dial(cb);
132+
let timingOutVolumeKnob = (e)=>{
133+
if (!e.b) {
134+
setKnobTimeout();
135+
} else if (knobTimeout) {
136+
clearTimeout(knobTimeout);
137+
knobTimeout = undefined;
138+
}
139+
volumeKnob(e);
140+
}
141+
let swipeMask = ()=>{
142+
E.stopEventPropagation();
143+
}
144+
let setKnobTimeout = ()=>{
145+
knobTimeout = setTimeout(()=>{
146+
Bangle.removeListener("drag", timingOutVolumeKnob)
147+
Bangle.removeListener("swipe", swipeMask);
148+
knobTimeout = undefined;
149+
print("removed volume knob")
150+
}, 350);
151+
}
152+
Bangle.prependListener("drag", timingOutVolumeKnob);
153+
Bangle.prependListener("swipe", swipeMask);
154+
}
155+
};
156+
157+
158+
dial = function(cb, options) {
159+
"ram";
160+
options = options || {};
161+
162+
const SCREEN_W = g.getWidth();
163+
const SCREEN_H = g.getHeight();
164+
165+
const DIAL_RECT = options.dialRect || {
166+
x: 0,
167+
y: 0,
168+
x2: SCREEN_W - 1,
169+
y2: SCREEN_H - 1,
170+
w: SCREEN_W,
171+
h: SCREEN_H,
172+
};
173+
174+
const CENTER = {
175+
x: DIAL_RECT.x + DIAL_RECT.w / 2,
176+
y: DIAL_RECT.y + DIAL_RECT.h / 2,
177+
};
178+
179+
const BASE_SCREEN_W = 176;
180+
const STEPS_PER_TURN = options.stepsPerWholeTurn || 10;
181+
const BASE_THRESHOLD = 50;
182+
const THRESHOLD =
183+
BASE_THRESHOLD *
184+
(10 / STEPS_PER_TURN) *
185+
(DIAL_RECT.w / BASE_SCREEN_W);
186+
187+
let cumulative = 0;
188+
189+
function onDrag(e) {
190+
"ram";
191+
192+
if (
193+
e.x < DIAL_RECT.x ||
194+
e.x > DIAL_RECT.x2 ||
195+
e.y < DIAL_RECT.y ||
196+
e.y > DIAL_RECT.y2
197+
) {
198+
return;
199+
}
200+
201+
if (e.y < CENTER.y) {
202+
cumulative += e.dx;
203+
} else {
204+
cumulative -= e.dx;
205+
}
206+
207+
if (e.x < CENTER.x) {
208+
cumulative -= e.dy;
209+
} else {
210+
cumulative += e.dy;
211+
}
212+
213+
function stepHandler(step) {
214+
Bangle.buzz(20, 0.3);
215+
cumulative -= THRESHOLD * step;
216+
cb(step);
217+
}
218+
219+
while (cumulative > THRESHOLD) {
220+
stepHandler(1);
221+
}
222+
while (cumulative < -THRESHOLD) {
223+
stepHandler(-1);
224+
}
225+
226+
E.stopEventPropagation();
227+
}
228+
229+
return onDrag;
230+
/*
231+
if (exports.dial._handler) {
232+
Bangle.removeListener("drag", dial._handler);
233+
}
234+
235+
exports.dial._handler = onDrag;
236+
Bangle.prependListener("drag", onDrag);
237+
238+
Bangle.prependListener("swipe", ()=>{
239+
E.stopEventPropagation();
240+
}
241+
);*/
242+
};
243+
100244
// Navigation input on the main layout
101245
let setUI = function() {
102246
Bangle.setUI(
103-
{mode : "updown",
247+
{mode : "custom",
104248
touch: touchHandler,
105249
swipe: swipeHandler,
250+
drag: dragHandler,
106251
btn: ()=>load(),
107252
remove : ()=>widgetUtils.show(),
108-
},
109-
ud => {
110-
if (ud) Bangle.musicControl(ud>0 ? "volumedown" : "volumeup");
111-
}
253+
}
112254
);
113255
};
114256

apps/spotrem/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "spotrem",
33
"name": "Remote for Spotify",
4-
"version": "0.13",
4+
"version": "0.14",
55
"description": "Control spotify on your android device.",
66
"readme": "README.md",
77
"type": "app",

0 commit comments

Comments
 (0)