MainActivity is as follows:
Package cn. c; import java. io. file; import java. util. arrayList; import android. app. activity; import android. gesture. gesture; import android. gesture. gestureLibraries; import android. gesture. gestureLibrary; import android. gesture. gestureOverlayView; import android. gesture. gestureOverlayView. ongesturew.medlistener; import android. gesture. prediction; import android. OS. bundle; import android. OS. environment; impo Rt android. view. keyEvent; import android. view. view; import android. view. view. onKeyListener; import android. widget. button; import android. widget. editText;/*** Requirement Description: * adds Gesture Recognition Based on Example 1. * You do not need to add a gesture. * error Summary: * mGestureLibrary is not executed during gesture recognition. load () * causes mGestureLibrary. recognize () method failed. * This error is similar to * Editor does not execute the commit () method **/public class MainActivity extends Activity {private EditTe when the SharedPreferences operation is started. Xt mEditText; private GestureLibrary mGestureLibrary; private Gesture mGesture; private Button mSaveButton; private Button mResetButton; private String success; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); init ();} private void init () {mEditText = (EditText) FindViewById (R. id. editText); mEditText. setOnKeyListener (new OnKeyListener () {public boolean onKey (View v, int keyCode, KeyEvent event) {if (mGesture! = Null & mEditText. getText (). toString (). length ()> 0) {mSaveButton. setEnabled (true);} else {mSaveButton. setEnabled (false) ;}return false ;}); mGestureOverlayView = (GestureOverlayView) findViewById (R. id. gestureOverlayView); mSaveButton = (Button) findViewById (R. id. saveButton); mSaveButton. setEnabled (false); mResetButton = (Button) findViewById (R. id. resetButton); // path of the GestureLibrary file mGestureLibraryPath = Envi Ronment. getExternalStorageDirectory () + File. separator + "gesturesTest"; // Add the listening event mGestureOverlayView for GestureOverlayView. addongesturew.medlistener (new listener ();} private class implements ongesturew.medlistener {public void ongesturesponmed (GestureOverlayView overlay, Gesture gesture) {// load the Gesture library under this path. // if it does not exist, a gesture library mGestureLibraryPath = Envir will be created in the path Onment. getExternalStorageDirectory () + File. separator + "gesturesTest"; mGestureLibrary = GestureLibraries. fromFile (mGestureLibraryPath); // load the gesture library // You must execute the load () method. Otherwise, recognize () is useless! If (mGestureLibrary. load () {ArrayList <Prediction> predictionsList = mGestureLibrary. recognize (gesture); if (predictionsList. size ()> 0) {Prediction bestPrediction = predictionsList. get (0); if (bestPrediction. score> 7.0) {System. out. println ("xxxx1111 this gesture already exists") ;}} else {System. out. println ("xxxx1111 this gesture does not exist") ;}} else {System. out. println ("xxxx1111 failed to load the gesture library ");}}}}
Main. xml is as follows:
<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"> <LinearLayout android: id = "@ + id/linearLayout" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: layout_alignParentTop = "true" android: orientation = "horizontal"> <TextView android: id = "@ + id/textView" android: layout_width = "100dip" android: layout_height = "wrap_content" android: text = "gesture name:"/> <EditText android: id = "@ + id/editText" android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: hint = "input here"/> </LinearLayout> <android. gesture. gestureOverlayView android: id = "@ + id/gestureOverlayView" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: layout_below = "@ id/linearLayout" android: layout_marginBottom = "50dip" android: gestureStrokeType = "multiple"/> <LinearLayout android: layout_width = "fill_parent" android: layout_height = "50dip" android: true = "android: orientation = "horizontal"> <Button android: id = "@ + id/saveButton" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_weight = "1" android: text = "save"/> <Button android: id = "@ + id/resetButton" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_weight = "1" android: text = "reset"/> </LinearLayout> </RelativeLayout>