用于话手势的控件是 <android.gesture.GestureOverlayView android:gestureStrokeType="multiple"//允许多笔手势 />
1.定义一个手势工厂 存放手势图案
private GestureLibrary gestureLibrary=GestureLibraries.fromRawResource(this, R.raw.gestures);
2.加载手势工厂
gestureLibrary.load();
3.然后监听手势控件上的手势
(gesture).addOnGesturePerformedListener(new GestureListener());//监听手势 这个只监听单笔手势new GestureListener回调函数 定义如下
public void onGesturePerformed(GestureOverlayView arg0, Gesture arg1)
{//第一个参数就是这里定义的接受手势的控件 第二个参数是手势画完了后的图案
// TODO Auto-generated method stub
ArrayList<Prediction> predictions = gestureLibrary.recognize(arg1);//看画出来的手势图案是否和手势工厂里存放的手势图案一样 返回ArrayList<Prediction>
Log.i("Tag","1");
if(predictions!=null)
{//不为空 则证明有手势图案
Log.i("Tag","2");
Prediction prediction = predictions.get(0);//取得栈顶的第一个最匹配的手势
if(prediction.score>=5)
{//判断手势的匹配度
Log.i("Tag","3");
Log.i("Tag",prediction.name);
if("call".equals(prediction.name))
{//判断是哪一种手势
Log.i("Tag","4");
Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:5556"));
startActivity(intent);
}
else if("out".equals(prediction.name))
{
finish();//不是关闭应用 只是关闭activity
}
}
else
{
Toast.makeText(getApplicationContext(), "匹配度不够", 2).show();
}
}
else
{
Toast.makeText(getApplicationContext(), "没有匹配记录", 2).show();
}
}