I know how to detect a double-click and a two-finger touch event, but how can I combine these to react so somebody needs to double click with two fingers?
By default, Android has the long press to act as a second form of clicking, but I’m specifically looking for a two-finger double-click.
I wanted a simple and reusable interface that listens for two finger double taps and behaves like GestureDetector. So that you could use it like this (all cut & paste runnable code):
I created SimpleTwoFingerDoubleTapDetector. (It’s a long name, but it is descriptive. You can rename it as anything you want.) Save this new file inside your project or as a library:
First, a few notes about Android (one-touch) GestureDetector:
onDoubleTap()event uses a standard timeout value from ViewConfiguration. I refer to the same time.onDoubleTap()andonDoubleTapEvent().onDoubleTap()is fired only when the second tap’s finger-down event occurs.onDoubleTapEvent()is fired for every action by the second tap: down, move, and up.A few notes on SimpleTwoFingerDoubleTapDetector:
onTwoFingerDoubleTap().Final note:
You can easily change this to behave like an OnTouchListener:
Change SimpleTwoFingerDoubleTapDetector’s definition:
Add a new class variable:
Change the
ACTION_DOWNcase:Pass
mFirstViewinside theACTION_UPcase:Last, change the
onTwoFingerDoubleTap()method to reflect which View was tapped: