Target effect:
The program runs, draws the left arrow hint on the previous, draws the right arrow to prompt the next, and can also draw the symbol to exit the program.
The custom gestures here are set by Gestureoverlayview, and the SDK2.0 system comes with a gesturebuilder gesture library, SDK4.2 the previous path is android-sdk-windows\samples\ android-10\gesturebuilder,4.2 after the path is Sdk-extras-android-support-samples-gesturebuilder, sometimes it is possible to install themselves and do not have this library, Then you need to download a directory that is placed in the path, http://pan.baidu.com/s/1bpbno6r.
1. First need to import the gesture library, add gesture files, the simulator has ready-made software This step can be omitted, but the real machine test need to import on the phone to run, because I was imported once, so the bottom of the hint red wrong number and finish can not click, the first import is normal. (Direct click Next without the icon)
2. After running, there will be one more applet on the simulator or mobile phone.
3. Open after adding the item required gesture, save after three, prompt to save the path, the simulator save path is Storage-sdcard-gestures, the true machine save path is storage-emulated-0-gestures. (different phone paths may vary)
4. Now just find the gestures file, open the file Explorer, figure one is the emulator's path storage-sdcard-gestures, figure two is the real machine's file path mnt-shell-emulated-0-gestures. (I don't quite understand why the path of the real machine is not quite the same as the prompt when saving)
5. Import the gestures file to the desktop, create a new project, create a new raw folder under the Res folder, and copy the gestures file to the raw folder.
The 6.activity_main.xml page places a ImageView control and Gestureoverlayview control and uses the Gestureoverlayview control to include the ImageView control. (not included or Yes, Gestureoverlayview controls are default above all controls)
Activity_main.xml page:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Tools:context =". Mainactivity "> <!--android:eventsinterceptionenabled defines whether the gesture is intercepted when the gesture is already recognized android:fadeduration when the user finishes drawing, The time that the gesture effect fades out android:fadeenabled the color of the android:gesturecolor gesture when the user finishes drawing it android:gesturestroketype the type of stroke Droid:geaturestrokewidth Stroke Weight--<android.gesture.gestureoverlayview android:gesturecolor= "#ff0000" Android:gesturestrokewidth= "android:id=" @+id/gestureoverlayview "android:layout_width=" Match_pare NT "android:layout_height=" Match_parent "> <imageview android:id=" @+id/ivshow "a Ndroid:layout_width= "Match_parent" android:layout_height= "Match_parent" Android:layout_alignparentle Ft= "true" ANDROID:LAYOUT_ALIGNPArenttop= "true" android:src= "@drawable/ic_launcher"/> </android.gesture.gestureoverlayview></re Lativelayout>
7.mainactivity.java page Match recognition gesture. Mainactivity.java page:
Package Com.example.gestureoverlayview;import Java.util.arraylist;import Android.os.bundle;import Android.app.activity;import Android.gesture.gesture;import Android.gesture.gesturelibraries;import Android.gesture.gesturelibrary;import Android.gesture.gestureoverlayview;import Android.gesture.gestureoverlayview.ongestureperformedlistener;import Android.gesture.prediction;import Android.view.menu;import Android.widget.toast;public class Mainactivity extends Activity {private Gestureoverlayview Gestureoverlayview; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate) ; Setcontentview (R.layout.activity_main); gestureoverlayview= (Gestureoverlayview) Findviewbyid ( R.id.gestureoverlayview)/* Find the Pre-set gesture file and load it in */final gesturelibrary Library=gesturelibraries.fromrawresource ( Mainactivity.this,r.raw.gestures);//Get Gesture file Library.load ();/* Match recognition */ Gestureoverlayview.addongestureperformedlistener (New Ongestureperformedlistener () {@Overridepublic void Ongestureperformed (GeStureoverlayview arg0, Gesture Gesture) {//read out gesture library content recognition gesture arraylist<prediction> mygesture=library.recognize ( gesture); Prediction Predction=mygesture.get (0); if (predction.score>=4.0) {//similarity is greater than a value (the larger the number means the more similar the requirement), the gesture if ( Predction.name.equals ("Exit")) {finish ();} else if (predction.name.equals ("Next")) {Toast.maketext (Mainactivity.this, "Next", Toast.length_short). Show (); else if (predction.name.equals ("previous")) {Toast.maketext (mainactivity.this, "prev", Toast.length_short). Show ();}} Else{toast.maketext (Mainactivity.this, "No this gesture", Toast.length_short). Show ();}});}}
8. Run to show the target effect.
Android-gestureoverlayview Custom Gesture Commands