MainActivity:
public class MainActivity extends Activity {
GestureOverlayView gestureOverlayView1;
EditText editText1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gestureOverlayView1 = (GestureOverlayView) findViewById(R.id.gestureOverlayView1);
editText1 = (EditText) findViewById(R.id.editText1);
final GestureLibrary library = GestureLibraries.fromRawResource(this,R.raw.gestures);
library.load();
gestureOverlayView1.addOnGesturePerformedListener(new OnGesturePerformedListener() {
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> mygesture = library.recognize(gesture);
Prediction prediction = mygesture.get(0);
if(prediction.score>=1.0){
if(prediction.name.equals("1")){
editText1.setText(editText1.getText()+prediction.name);
}
}
}
});
}
}
布局:
<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" >
<android.gesture.GestureOverlayView
android:id="@+id/gestureOverlayView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gestureColor="#000"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="手势输入数字">
</EditText>
</android.gesture.GestureOverlayView>
</RelativeLayout>