Page 1 of 1
Toggle a checkbox on a card with long press does not work
Posted: Sun Feb 15, 2015 3:35 am
by keram
Hello,
I have a checkbox on a card. The script on the card has this code to imitate Android long press:
Code: Select all
on mouseDown
wait 700 millisecs with messages
if the mouse is down then
## treat like long mouseClick
-- do something
end if
end mouseDown
When I click to select the checkbox it does show its selection icon but it reverts back to unselected right away. I have to hold the mouse down little bit longer to get it selected so it stays on.
Of course it has to do with the mouseDown handler in the card. I just cannot figure out how to bypass that handler for the checkbox.
How to do it?
keram
EDIT: added a stack that shows what I want to fix
Re: Toggle a checkbox on a card with long press does not wor
Posted: Sun Feb 15, 2015 6:52 pm
by jacque
Set a script local variable on mouseDown that holds the current milliseconds. On mouseUp, compare the current milliseconds to the number in the variable. If it is > 700 then it is a long press. The mouseUp handler should do all the actual work, the mouseDown handler only records the time of the press.
Re: Toggle a checkbox on a card with long press does not wor
Posted: Mon Feb 16, 2015 4:51 am
by keram
Thanks Jacqueline,
I changed it to:
Code: Select all
local sPressStart
on mouseDown
put the milliseconds into sPressStart
end mouseDown
on mouseUp
put the milliseconds into tPressStop
if tPressStop - sPressStart > 700 then
show grp "a"
hide grp "b"
put "this was a LONG press" into fld "message"
wait 1 sec
else
put "this was a SHORT press" into fld "message"
end if
show grp "b"
put tPressStop - sPressStart && "milliseconds" into fld "duration"
end mouseUp
Now the selection of the checkbox works properly. But it's a little bit different kind of long press since the "doing something" happens first on mouseUp, e.g. the buttons 1-3 show first when the press is released, while in the original post they show up after 700 millisec while the press is still down which is more Android-like.
But I guess there is no other way? The calculation has to be done.
keram
Re: Toggle a checkbox on a card with long press does not wor
Posted: Mon Feb 16, 2015 4:41 pm
by jacque
You could try moving the long press code into a mouseStillDown. That should work if you make sure to exit the handler if the time is shorter than 700 ms. Continue to use mouseUp for a plain tap.
Re: Toggle a checkbox on a card with long press does not wor
Posted: Wed Feb 18, 2015 1:52 am
by keram
Yes, that works very well. Thanks!