浏览 2347 次
锁定老帖子 主题:gesture手势相关操作
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-10-20
最后修改:2011-10-20
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) { } }); 二:根据文件中保存的手势执行对应的操作 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); 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |