-
• #2
I believe you should remove the listener used for selecting mode once you've made the selection, in your example function(n, event). I don't know, but I suspect you might need to break function(n, event) out into a function with it's own name to make it work, maybe
function selectOnTouch(n, event) { ... } ... Bangle.removeListener('touch', selectOnTouch);
and then your code would be something like
function selectOnTouch(n, event) { if(event.y<60){ walking_subactivity(); Bangle.removeListener('touch', selectOnTouch); } else if(event.y>=60 && event.y<120){ jogging_subactivity(); Bangle.removeListener('touch', selectOnTouch); } else { cycling_subactivity(); Bangle.removeListener('touch', selectOnTouch); } }); Bangle.on('touch', selectOnTouch); //start the listener for touch input here
I'm not 100% on these things though - but I think that's basically how it works. This is relevant I think: http://www.espruino.com/Reference#l_Object_removeListener
I hope I'm not leading you astray with this :P
-
• #4
Nice! I just recently learned about removing listeners myself - it was something of a revelation. :)
I wanted to implement touch individually for these features. I posted this on the forum and they suggested I implement it in this manner.
The issue now is that once I am on the working screen, if I click on the middle portion of the touch screen it takes me to the jogging screen. My main issue is that once I choose the walking option, the screen should remain there even if I click at some other part of the screen and do not jump to the jogging and cycling screen.
I have written the function names in the if-else condition in order to make the code a bit more readable for the sake of this doubt.
Thank you in advance.
4 Attachments