cancel
Showing results for 
Search instead for 
Did you mean: 

Given a container, how can we differentiate between short press, long press and swipe events?

BParh.1
Senior III

So assume there is a container that should react differently in either of the following conditions:

  1. Short press (i.e. single click)
  2. Long press e.g. > 1s
  3. Swipe (e.g. swipe left or right).

Is this doable? Could someone maybe post the pseudocode?

I know how to handle single click, by checking in the 'Click Listener' of the container. Then in the screen handleTickEvent() I can differentiate whether the container still pressed or not to differentiate between short press and long press. But now, how to detect swipe event?

4 REPLIES 4
Romain DIELEMAN
ST Employee

Hi,

You could use the handleDragEvent() function which will detect the swipe. I think there are a couple of posts on this forum on how to work with it, or custom code to get the deltaX (to handle the swipe).

/Romain

Thank you @Romain DIELEMAN​ , but we have to define a swipe container to have handleDragEvent() handler available to us? This would not be available in normal container?

This function is available in all containers. You just have to override it with your own definition…

To distinguish between short and long press, you've got to override the 'handleClickEvent' and 'handleTickEvent' function… When you catch a 'ClickEvent::PRESSED' in your handleClickEvent, simply call the function registerTimerWidget and start counting the time in the handleTickEvent function… If your counter goes past 1sec, you know it's a long press… And don't forget to call unregisterTimerWidget once you're done measuringr the time (for instance when you receive a ClickEvent::RELEASED or ClickEvent::CANCEL.

BParh.1
Senior III

Thank you @GMeur​ , I did override the handleDragEvent() , but when I dragged my box, it never hit the breakpoint set inside the handler function.