gesture手势相关操作
程序员文章站
2022-03-16 16:21:27
...
一:保存手势到文件中:
[img]http://dl.iteye.com/upload/attachment/573646/a68c303f-2a8b-3ec7-a7b8-143f27da2f00.jpg[/img]
二:根据文件中保存的手势执行对应的操作
三:手势转图片
private final File mStoreFile = new File(Environment.getExternalStorageDirectory(), "gestures");//在sdk目录生成一个gestures文件
GestureLibrary library = GestureLibraries.fromFile(mStoreFile);
GestureOverlayView overlay=(GestureOverlayView)findViewById(R.id.gestures_overlay);
overlay.addOnGestureListener(new GestureOverlayView.OnGestureListener() {
@Override
public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) {
}
@Override
public void onGestureEnded(GestureOverlayView overlay,
MotionEvent event) {
Gesture gesture = overlay.getGesture();
library.addGesture("给手势取一个名字吧", mGesture);
library.save();
if (mGesture.getLength() < LENGTH_THRESHOLD) {
overlay.clear(false);
}
}
@Override
public void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) {
}
@Override
public void onGesture(GestureOverlayView overlay, MotionEvent event) {
}
});
[img]http://dl.iteye.com/upload/attachment/573646/a68c303f-2a8b-3ec7-a7b8-143f27da2f00.jpg[/img]
二:根据文件中保存的手势执行对应的操作
private GestureLibrary mLibrary = GestureLibraries.fromRawResource(context, R.raw.gestures);
mLibrary.load();
overlay.addOnGesturePerformedListener(new OnGesturePerformedListener() {
@Override
public void onGesturePerformed(GestureOverlayView overlay,Gesture gesture) {
ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
if (predictions.size() > 0) {
Prediction prediction = predictions.get(0);
if(prediction.name.equals("close")){
//执行关闭操作
}else if(prediction.name.equals("come on")){
//执行come on 操作
}else if(prediction.name.equals("yes")){
//执行yes 操作
}
}
}
});
三:手势转图片
Bitmap bitmap = gesture.toBitmap(width, height, inset, color);