Toggle a checkbox on a card with long press does not work

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Toggle a checkbox on a card with long press does not work

Post by keram » Sun Feb 15, 2015 3:35 am

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
Attachments
long press+checkbox selection.zip
(4 KiB) Downloaded 255 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Toggle a checkbox on a card with long press does not wor

Post by jacque » Sun Feb 15, 2015 6:52 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: Toggle a checkbox on a card with long press does not wor

Post by keram » Mon Feb 16, 2015 4:51 am

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
Attachments
long press+checkbox selection2.zip
stack with the corrected script
(4.01 KiB) Downloaded 254 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Toggle a checkbox on a card with long press does not wor

Post by jacque » Mon Feb 16, 2015 4:41 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: Toggle a checkbox on a card with long press does not wor

Post by keram » Wed Feb 18, 2015 1:52 am

Yes, that works very well. Thanks!
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Post Reply