论坛首页 移动开发技术论坛

gesture手势相关操作

浏览 2347 次
精华帖 (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);
  • 大小: 14.3 KB
论坛首页 移动开发技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics