您好,登錄后才能下訂單哦!
一丶首先創建一個手勢庫
二丶手勢實例
布局文件:
在布局文件中有:
<android.gesture.GestureOverlayView
android:id="@+id/gv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gestureStrokeWidth="10"
android:gestureColor="#ff0000"
/>
MainActivity中
public class MainActivity extends Activity {
private GestureOverlayView gv;//手勢控件
private GestureLibrary gestureLibrary;//加載手勢庫
private boolean loadStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//拿到控件
gv = (GestureOverlayView) findViewById(R.id.gv);
//創建加載手勢庫的工具
gestureLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
//加載手勢庫
loadStatus = gestureLibrary.load();
//給gv加一個監聽器
//監聽一種手勢
gv.addOnGesturePerformedListener(new OnGesturePerformedListener() {
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
//手勢加載成功
if(loadStatus){
//識別手勢 Prediction(手勢相似度)
ArrayList<Prediction> pres = gestureLibrary.recognize(gesture);
if(!pres.isEmpty()){
Prediction pre = pres.get(0);
if(pre.score > 6){
if("close".equals(pre.name)){
finish();
}else if("tel".equals(pre.name)){
//打電話
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel://110"));
startActivity(intent);
}else if("right".equals(pre.name)){
Toast.makeText(getApplicationContext(), "正確", 0).show();
}
}else{
Toast.makeText(getApplicationContext(), "手勢不匹配", 0).show();
}
}else{
Toast.makeText(MainActivity.this, "手勢庫加載失敗", 0).show() ;
}
}
}
});
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。