Merge pull request #2756 from thyttan/lightswitch
[Light Switch Widget] handle and intercept swipe eventmaster
commit
dd3357ac75
|
|
@ -4,3 +4,4 @@
|
||||||
0.04: Add masking widget input to other apps (using espruino/Espruino#2151), add a oversize option to increase the touch area.
|
0.04: Add masking widget input to other apps (using espruino/Espruino#2151), add a oversize option to increase the touch area.
|
||||||
0.05: Prevent drawing into app area.
|
0.05: Prevent drawing into app area.
|
||||||
0.06: Fix issue where .draw was being called by reference (not allowing widgets to be hidden)
|
0.06: Fix issue where .draw was being called by reference (not allowing widgets to be hidden)
|
||||||
|
0.07: Handle the swipe event that is generated when draging to change light intensity, so it doesn't trigger some other swipe handler.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"id": "lightswitch",
|
"id": "lightswitch",
|
||||||
"name": "Light Switch Widget",
|
"name": "Light Switch Widget",
|
||||||
"shortName": "Light Switch",
|
"shortName": "Light Switch",
|
||||||
"version": "0.06",
|
"version": "0.07",
|
||||||
"description": "A fast way to switch LCD backlight on/off, change the brightness and show the lock status. All in one widget.",
|
"description": "A fast way to switch LCD backlight on/off, change the brightness and show the lock status. All in one widget.",
|
||||||
"icon": "images/app.png",
|
"icon": "images/app.png",
|
||||||
"screenshots": [
|
"screenshots": [
|
||||||
|
|
|
||||||
|
|
@ -165,13 +165,12 @@
|
||||||
w.changeValue(value, event.b);
|
w.changeValue(value, event.b);
|
||||||
|
|
||||||
// masks this drag event by messing up the event handler
|
// masks this drag event by messing up the event handler
|
||||||
// see https://github.com/espruino/Espruino/issues/2151
|
E.stopEventPropagation&&E.stopEventPropagation();
|
||||||
Bangle.removeListener("drag", w.dragListener);
|
|
||||||
Bangle["#ondrag"] = [w.dragListener].concat(Bangle["#ondrag"]);
|
|
||||||
|
|
||||||
// on touch release remove drag listener and reset drag status to indicate stopped drag action
|
// on touch release remove drag listener and reset drag status to indicate stopped drag action
|
||||||
if (!event.b) {
|
if (!event.b) {
|
||||||
Bangle.removeListener("drag", w.dragListener);
|
Bangle.removeListener("drag", w.dragListener);
|
||||||
|
Bangle.removeListener("swipe", w.swipeListener);
|
||||||
w.dragStatus = "off";
|
w.dragStatus = "off";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,6 +180,11 @@
|
||||||
value = undefined;
|
value = undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
swipeListener: function(_,__) {
|
||||||
|
// masks this swipe event by messing up the event handler
|
||||||
|
E.stopEventPropagation&&E.stopEventPropagation();
|
||||||
|
},
|
||||||
|
|
||||||
// listener function //
|
// listener function //
|
||||||
// touch listener for light control
|
// touch listener for light control
|
||||||
touchListener: function(button, cursor) {
|
touchListener: function(button, cursor) {
|
||||||
|
|
@ -197,12 +201,14 @@
|
||||||
Bangle.buzz(25);
|
Bangle.buzz(25);
|
||||||
// check if drag is disabled
|
// check if drag is disabled
|
||||||
if (w.dragDelay) {
|
if (w.dragDelay) {
|
||||||
// add drag listener at first position
|
// add drag and swipe listeners at respective first position
|
||||||
Bangle["#ondrag"] = [w.dragListener].concat(Bangle["#ondrag"]);
|
Bangle["#ondrag"] = [w.dragListener].concat(Bangle["#ondrag"]);
|
||||||
|
Bangle["#onswipe"] = [w.swipeListener].concat(Bangle["#onswipe"]);
|
||||||
// set drag timeout
|
// set drag timeout
|
||||||
w.dragStatus = setTimeout((w) => {
|
w.dragStatus = setTimeout((w) => {
|
||||||
// remove drag listener
|
// remove drag and swipe listeners
|
||||||
Bangle.removeListener("drag", w.dragListener);
|
Bangle.removeListener("drag", w.dragListener);
|
||||||
|
Bangle.removeListener("swipe", w.swipeListener);
|
||||||
// clear drag timeout
|
// clear drag timeout
|
||||||
if (typeof w.dragStatus === "number") clearTimeout(w.dragStatus);
|
if (typeof w.dragStatus === "number") clearTimeout(w.dragStatus);
|
||||||
// reset drag status to indicate stopped drag action
|
// reset drag status to indicate stopped drag action
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue