Android手势识别
来源:互联网 发布:jsp和java的关系 编辑:程序博客网 时间:2024/06/05 20:43
1、页面
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<android.gesture.GestureOverlayView
android:id="@+id/gestures"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="10">
</android.gesture.GestureOverlayView>
<Button
android:id="@+id/btn"
android:onClick="gesture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="识别手势"
android:layout_weight="1"
/>
</LinearLayout>
2、代码部分
package com.hbsi.csdn.gesturetest;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGestureListener;
import android.gesture.Prediction;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button btn;
private GestureOverlayView gov;
private GestureLibrary libray;
private Gesture mygesture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gov = (GestureOverlayView) findViewById(R.id.gestures); // 获取到手势的控件
libray = GestureLibraries.fromRawResource(this,R.raw.gestures); // 获取到手势库文件
gov.addOnGestureListener(new OnGestureListener() {
@Override
public void onGesture(GestureOverlayView overlay, MotionEvent event) {
// TODO Auto-generated method stub
System.out.println("手势正在画的时候调用的方法");
}
@Override
public void onGestureCancelled(GestureOverlayView overlay,
MotionEvent event) {
System.out.println("手势取消的时候调用的方法");
}
@Override
public void onGestureEnded(GestureOverlayView overlay,
MotionEvent event) {
// TODO Auto-generated method stub
mygesture = overlay.getGesture();
}
@Override
public void onGestureStarted(GestureOverlayView overlay,
MotionEvent event) {
// TODO Auto-generated method stub
System.out.println("开始画的时候调用");
}
});
}
public void gesture(View v) {
libray.load(); // 加载手势库
ArrayList<Prediction> predictions = libray.recognize(mygesture);// 从手势库中查询匹配的内容,匹配的结果可能包括多个相似的结果,匹配度最高的结果放在最前面
Prediction prediction=predictions.get(0);//把匹配度最高的结果获取过来
if(prediction.score>=5){
if(prediction.name.equals("call")){
Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:119"));
startActivity(intent);
}else if(prediction.name.equals("close")){
finish();
}else if(prediction.name.equals("Toast")){
Toast.makeText(this, "woshitosi", 0).show();
}
}else{
Toast.makeText(this, "手势不能识别", 0).show();
}
}
}
- Android-自定义手势识别-复杂手势识别
- Android+手势识别详解
- android手势Gesture识别
- android之手势识别
- Android 多点手势识别
- Android触摸屏手势识别
- android基础--手势识别
- android手势识别实例
- Android GestureDetector手势识别
- Android 多点手势识别
- Android 手势识别
- android之手势识别
- Android手势识别
- android之手势识别
- android---手势识别
- Android手势识别
- android识别手势
- android手势识别
- iSCSI 协议
- 物理删除联系人
- 程序员修炼篇:成为C语言高手
- mysql日志
- Android对齐方法介绍
- Android手势识别
- zubao
- Java 各种进制转换
- Android应用插件式开发解决方法之一
- 调优过程中知悉的命令
- nearmobile xml
- 编程需要知道多少数学知识?
- linux下shutdown, halt, reboot的区别
- vc 实时显示系统时间