Gestures in Android

Source: Internet
Author: User

Android provides support for two gesture behaviors:
1, for the first gesture behavior, Android provides gesture detection, and for gesture detection provides a corresponding listener.
2, for the second gesture behavior, Android allows developers to add gestures, and provide the appropriate API to identify user gestures.

Gesturedetector.ongesturelistener is a listener that is responsible for providing the user with the gesture behavior.
Boolean Ondown (Motionevent e): Triggers the method when the touch event is pressed.
Boolean onfling (motionevent e1,motionevent e2,float velocityx,float velocityy): This method is triggered when the user "drags" on the touchscreen. Among them, Velocityx and velocityy represent the speed of "dragging" the action in the transverse and longitudinal direction.
abstract void Onlongpress (Motionevent e): The method is triggered when the user is on the screen for a long time.
Boolean onscroll (motionevent e1,motionevent e2,float distancex,float Distancey): This method is triggered when the user scrolls on the screen.
void Onshowpress (Motionevent e): Triggers the method when the user presses on the touchscreen and has not moved and released.
Boolean onsingletapup (Motionevent e): The user taps the event on the touchscreen to trigger the method.

Gesture detection using Android requires only the following two steps:
1. Create a Gesturedetector object. A Gesturedetector.ongesturelistener listener instance must be implemented when the object is created.
2, the TouchEvent event binding listener for the application activity (which can occasionally also be a specific component), in event handling, specifies that the Touchevnet event on the activity (or specific component) is given to gesturedetector processing.

Android uses Gesturelibrary to represent the gesture library and provides the Gesturelibraries tool class to create a gesture library, Gesturelibraries provides the following 4 static methods to load the gesture library from different locations.
1, Static gesturelibrary FromFile (String path): Loads the gesture library from the file represented by path.
2, static gesturelibrary fromfile (file path): Loads the gesture library from the file represented by path.
3, Static gesturelibrary fromprivatefile (Context context,string name): Loads the gesture library from the name file in the specified application's Data folder.
4, Static gesturelibrary Fromrawresource (Context context,int Resourceld): Loads the gesture library from the resource represented by Resourceld.

Once the Gesturelibrary object has been obtained in the program, the object provides the following methods to add gestures and identify gestures.
1, void Addgesture (String entryname,gesture Gesture): Adds a gesture called entryName.
2, Set<string> getgestureentries (): Gets the name of all the gestures in the gesture library.
3. Arraylist<gesture> getgestures (String entryName): Gets all the gestures that correspond to the EntryName name.
4, arraylist<prediction> recognize (Gesture Gesture): Identify all gestures that match Gesture from the current gesture library.
5. void RemoveEntry (String entryName): Removes the entryName corresponding gesture from the gesture library.
6, void Removegesture (String entryname,gesture Gesture): Delete the gesture library entryName, Gesture corresponding gestures.
7. Boolean Save (): Call this method to save the gesture library when you add or remove gestures from the gesture library.

Gestures in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.