android手势
来源:互联网 发布:淘宝卖家申请直播入口 编辑:程序博客网 时间:2024/04/29 19:43
<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>
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手势
- Android:手势
- Android手势
- Android手势
- Android 手势
- Android手势
- Android--手势
- Android手势
- Android 手势
- android手势
- Android开发 Android手势
- Android手势源码浅析-----手势绘制(GestureOverlayView)
- Android手势源码浅析----手势识别
- Android输入手势和手势匹配
- 初学Android,增加手势到手势库
- Android手势源码浅析-----手势绘制(GestureOverlayView)
- Android权限之三共享UID和签名
- paypal error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure
- 六大步骤提高企业云计算安全
- MediaPlayer 听筒播放音乐
- C# 中的委托和事件
- android手势
- SuperSocket 1.5 发布,.NET Socket服务器框架
- (JAVA自学笔记)创建一个对象都在内存中做了什么事情
- Android工具HierarchyViewer 代码导读(2) -- 建立Eclipse调试环境
- IOS 非空判断(待续)
- Android 开发源码分享
- 技术知识图
- JavaScript Function详解
- C#中的委托和事件(续)