The techniques outlined here allow us to detect, locate, and discriminate between any number of touch events. Using MotionEvent methods such as getX()
and getY()
to determine an event's position and getEventTime()
, getDownTime()
and others to provide information about when these events took place, we can build all sorts of complex shape recognition routines.
Constructing high level gestures this way could soon become cumbersome. Android provides the GestureDetector class along with one or two subclasses that allow us to detect gestures such as scrolling, flinging, and long-pressing.
This recipe shows how to recognize a fling gesture. This is when a user quickly moves and then releases a finger in a specific direction. As we only demonstrate how to capture the event and interpret its data here, you can apply these techniques to any application you wish.
Start up a new Android project in Eclipse.