手势

  优势:快捷

  步骤:

  制作手势

  1) 打开模拟器GesturesBuilder录制手势

  2) 将SDcard根目录中的gestures拷贝到res/raw目录中

  使用手势      

  1) 在布局中增加GestureOverlayView

  2) 初始化手势库

final GestureLibrary library =

   GestureLibraries.fromRawResource(this, R.raw.gestures);

     library.load();// 加载手势库

  3) 注册事件

   GestureOverlayView overlayView = (GestureOverlayView) findViewById(R.id.gestureOverlayView1);

overlayView.addOnGesturePerformedListener(new OnGesturePerformedListener()

{

@Override

public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture)

{

ArrayList<Prediction> recognize = library.recognize(gesture);

Prediction prediction = recognize.get(0);

if (prediction.score > 5.0)

{

if ("exit".equals(prediction.name))

{

finish();

}

else if ("test".equals(prediction.name))

{

Toast.makeText(MainActivity.this, "test", Toast.LENGTH_LONG).show();

}

}

else

{

Toast.makeText(MainActivity.this, "错误的手势", Toast.LENGTH_LONG).show();

}

}

});  



DEMO已上传