您好,登錄后才能下訂單哦!
一丶首先創(chuàng)建一個(gè)手勢(shì)庫(kù)
二丶手勢(shì)實(shí)例
布局文件:
在布局文件中有:
<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;//手勢(shì)控件
private GestureLibrary gestureLibrary;//加載手勢(shì)庫(kù)
private boolean loadStatus;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//拿到控件
gv = (GestureOverlayView) findViewById(R.id.gv);
//創(chuàng)建加載手勢(shì)庫(kù)的工具
gestureLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
//加載手勢(shì)庫(kù)
loadStatus = gestureLibrary.load();
//給gv加一個(gè)監(jiān)聽(tīng)器
//監(jiān)聽(tīng)一種手勢(shì)
gv.addOnGesturePerformedListener(new OnGesturePerformedListener() {
@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
//手勢(shì)加載成功
if(loadStatus){
//識(shí)別手勢(shì) Prediction(手勢(shì)相似度)
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(), "手勢(shì)不匹配", 0).show();
}
}else{
Toast.makeText(MainActivity.this, "手勢(shì)庫(kù)加載失敗", 0).show() ;
}
}
}
});
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。