我将手势保存到手势文件,工作正常。但实际上我遇到了问题,即保存新手势时手势文件会被覆盖。
如何在手势文件中添加手势,而不是一直覆盖?
static File mStoreFile = new File ( Environment.getExternalStorageDirectory (), "gestures" );
if(!mStoreFile.exists ()){
Toast.makeText ( getApplicationContext (), "Datei war nicht vorhanden", Toast.LENGTH_SHORT ).show ();
File mStoreFile = new File ( Environment.getExternalStorageDirectory (), "gestures" );
}
GestureOverlayView gestureView = ( GestureOverlayView ) findViewById ( R.id.
gestureLayout );
gestureView.addOnGestureListener ( new GesturesProcessor () );
}
private class GesturesProcessor implements GestureOverlayView.OnGestureListener {
@Override
public void onGestureStarted ( GestureOverlayView overlay, MotionEvent event ) {
}
@Override
public void onGesture ( GestureOverlayView overlay, MotionEvent event ) {
}
@Override
public void onGestureEnded ( GestureOverlayView overlay, MotionEvent event ) {
String text;
gesture = overlay.getGesture ();
if ( gesture.getLength () < LENGTH_THRESHOLD ) {
text = "Geste war zu kurz";
Dialog_Anzeigen2 ( text );
overlay.clear ( false );
}
text = "Geste übernehmen?";
Dialog_Anzeigen(text);
}
@Override
public void onGestureCancelled ( GestureOverlayView overlay, MotionEvent event ) {
}
这是保存手势文件的部分:
public void confirm() {
if (gesture != null) {
Log.d ( "hier", "hier " );
GestureLibrary store = GestureLibraries.fromFile ( mStoreFile );
// über den Namen wird festgemacht, zu welcher Applikation die Geste gehören soll
store.addGesture(name, gesture);
store.save();
Log.d ( "hier1", "hier1 " );
Set<String> entries = store.getGestureEntries();
Log.d ( "entries1.size ()", "entries1.size() " + entries.size () );
setResult ( RESULT_OK );
} else {
Log.d ( "hier2", "hier2 " );
setResult(RESULT_CANCELED);
}
}
}
非常感谢您的帮助。