Avoid (or delaying) handling the first touch in case the user touches with two fingers

29 Views Asked by At

I want to create a view in Android where I can tap (and potentially drag) to draw dots (or lines). This is easy to do with an OnTouchListener.

However, I also need to enable zooming and rotating with two fingers. I can use an OnTouchListener for this too, and check the number of fingers used with the getPointerCount fuction. Now the problem is that when I try to zoom, using two fingers, obviously one of the fingers will touch first, resulting in a MotionEvent being fired, with pointer count 1. Then, after a few milliseconds, the second finger hits, and now I can invoke the zooming (or whatever) functionality.

So currently, I am going to implement a short delay (say, 100 ms) in the listener, before starting to draw, in case the user intends to zoom instead of drawing. However, this seems a bit messy, and I though maybe there was some other way to solve this issue?

Or, to rephrase: Is there a (simple or common) way to avoid handling the first touch event, in cases where a second touch event (with a second finger) immediately follows?

0

There are 0 best solutions below