Handling User Gestures

You already know how to listen for click events. You can also handle gestures, such as flings, scrolls, and taps, by using the GestureDetector class (android.view.GestureDetector). You can use the GestureDetector class by implementing the onTouchEvent() method within an activity.

The following are some of the gestures an application can watch for and handle:

► onDown—Occurs when the user first presses the touch screen

► onShowPress—Occurs after the user first presses the touch screen but before the user lifts up or moves around on the screen

► onSingleTapUp—Occurs when the user lifts up from the touch screen as part of a single-tap event

► onSingleTapConfirmed—Called when a single-tap event occurs

► onDoubleTap—Called when a double-tap event occurs

► onDoubleTapEvent—Called when an event within a double-tap gesture occurs, including any down, move, or up action onLongPress—Similar to onSingleTapUp but called if the user has held his or her finger down just long enough to not be a standard click but also didn't move the finger onScroll—Called after the user has pressed and then moved his or her finger in a steady motion and lifted up onFling—Called after the user has pressed and then moved his or her finger in an accelerating motion just before lifting it

In addition, the android.gesture package allows an application to recognize arbitrary gestures, as well as store, load, and draw them. This means almost any symbol a user can draw could be turned into a gesture with a specific meaning. Some versions of the SDK have a Gesture Builder application that can simplify the process of creating gestures for applications that don't have a gesture-recording feature.

For more information about the android.gesture package, see http://developer.android.com/resources/articles/gestures.html.

Was this article helpful?

0 0

Post a comment