我正在开发一个包含手势的示例应用程序,我也经历了一些示例代码,我无法理解。
a) 在我的应用程序中,当我画一个字母 (T) 或 (Q) 时,我需要启动一个新活动。
b)我已经创建了 res/raw 文件夹,我应该如何保持手势。
c)我有一些示例代码,我将其粘贴在下面以供参考。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gestureResult = (TextView)findViewById(R.id.gestureresult);
//To load the gestures into your application GestureLibrary is used.gestures are stored under res/raw/gestures.
gestureLibrary = GestureLibraries.fromRawResource(this, R.raw.gesture);
if (!gestureLibrary.load()) {
finish();
}
// A gesture overlay acts as a simple drawing board on which the user can draw his gestures.
gestureOverlayView = (GestureOverlayView)findViewById(R.id.gestures);
gestureOverlayView.addOnGesturePerformedListener(gesturePerformedListener);
}
OnGesturePerformedListener gesturePerformedListener = new OnGesturePerformedListener(){
@Override
public void onGesturePerformed(GestureOverlayView view, Gesture gesture) {
// TODO Auto-generated method stub
ArrayList<Prediction> prediction = gestureLibrary.recognize(gesture);
if(prediction.size() > 0){
System.out.println("prediction::>"+prediction);
gestureResult.setText(prediction.get(0).name);
}
}};
在下一行,gestureLibrary.load()活动即将完成,因为手势无法加载。在我的日志中收到以下异常。
05-15 13:17:06.027: D/ddm-heap(3012): Got feature list request
05-15 13:17:06.257: D/Gestures(3012): Could not load the gesture library from raw resource com.gesture.testgesture:raw/gesture
05-15 13:17:06.257: D/Gestures(3012): java.io.EOFException
05-15 13:17:06.257: D/Gestures(3012): at java.io.DataInputStream.readShort(DataInputStream.java:395)
05-15 13:17:06.257: D/Gestures(3012): at android.gesture.GestureStore.load(GestureStore.java:285)
05-15 13:17:06.257: D/Gestures(3012): at android.gesture.GestureLibraries$ResourceGestureLibrary.load(GestureLibraries.java:132)
05-15 13:17:06.257: D/Gestures(3012): at com.gesture.testgesture.GestureIdentifierActivity.onCreate(GestureIdentifierActivity.java:28)
05-15 13:17:06.257: D/Gestures(3012): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
05-15 13:17:06.257: D/Gestures(3012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
05-15 13:17:06.257: D/Gestures(3012): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
05-15 13:17:06.257: D/Gestures(3012): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
05-15 13:17:06.257: D/Gestures(3012): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
最后是如何通过绘制手势字母 T 和 Q 从一个活动切换到另一个活动。