How to use gestures in android

Source: Internet
Author: User

Steps:

1. Use gestures builder in the simulator to create a gesture. If the simulator does not have this, create an android sample project, select gestures builder, and run it.) create several gestures.

2. Export the created gestrues file in the SD card directory in ddms.

3. Create a raw directory and copy the gestrues file.

4. In the layout xml, use the gestures overlay view control.

5. Read the gesture library in the Code and import it To the memory.

6. Match the gesture and compare the gesture entered by the user with the library. Sort the gesture according to the similarity to monitor the event.


The Code is as follows:

Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // read the gesture library final GestureLibrary library = GestureLibraries. fromRawResource (this, R. raw. gestures); library. load (); // import the gesture library and load it To the memory. // match the GestureOverlayView overlayView = (GestureOverlayView) findViewById (R. id. gestureOverlay View1); overlayView. addongesturesponmedlistener (new ongesturesponmedlistener () {// gesture listening event @ Override // Gesture indicates the gesture public void ongesturesponmed (GestureOverlayView overlay, gesture Gesture) {ArrayList <Prediction> recognize = library. recognize (gesture); // The user-input gesture matches the gesture in the library to get the recognize container, which is sorted from high to low according to the matching similarity, 0 ~ 10 minutes Prediction prediction = recognize. get (0); // obtain the most similar if (prediction. score> = 5) // similar score {if ("toast ". equals (prediction. name) // gesture name {Toast. makeText (MainActivity. this, "toast", Toast. LENGTH_LONG ). show ();} else if ("exit ". equals (prediction. name) {finish () ;}}}) ;}@ Override public boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true ;}}


This article is from the "wangcuijing" blog, please be sure to keep this source http://wangcuijing.blog.51cto.com/7233352/1286594

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.