Android手势识别应用
2013-02-21 23:44
411 查看
1、建立手势库,利用Android samples 里边的GestureBuilder项目实现(后附源码),完成后把gestures文件拷到项目的raw文件夹下
2、应用代码:
GestureBuilder:http://pan.baidu.com/share/link?shareid=274431&uk=1796216265
项目源码:http://pan.baidu.com/share/link?shareid=274433&uk=1796216265
2、应用代码:
package cn.itcast.gesture; 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.Prediction; import android.gesture.GestureOverlayView.OnGesturePerformedListener; import android.net.Uri; import android.os.Bundle; import android.util.Log; public class MainActivity extends Activity { private boolean success; private GestureLibrary library; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //找到手势库 library = GestureLibraries.fromRawResource(this, R.raw.gestures); //加载手势库 success = library.load(); GestureOverlayView gestureView = (GestureOverlayView)this.findViewById(R.id.gestures); gestureView.addOnGesturePerformedListener(new GestureListener()); } private final class GestureListener implements OnGesturePerformedListener{ @Override public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) { if(success){ //从手势库中查找匹配的手势,最匹配的记录会放在最前面 ArrayList<Prediction> predictions = library.recognize(gesture); if(!predictions.isEmpty()){ Prediction prediction = predictions.get(0); Log.i("MainActivity", "score:"+ prediction.score); if(prediction.score>3){ if("agree".equals(prediction.name)){ android.os.Process.killProcess(android.os.Process.myPid()); }else if("5556".equals(prediction.name)){ Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:5556")); startActivity(intent); } } } } } } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <android.gesture.GestureOverlayView android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1.0" android:gestureStrokeType="multiple" android:id="@+id/gestures" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.itcast.gesture" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="8" /> <uses-permission android:name="android.permission.CALL_PHONE"/> </manifest>
GestureBuilder:http://pan.baidu.com/share/link?shareid=274431&uk=1796216265
项目源码:http://pan.baidu.com/share/link?shareid=274433&uk=1796216265
相关文章推荐
- Android 手势识别应用
- android GestureDetector应用(手势识别)
- Android 手机应用开发经验之手势识别Gesture的
- Android应用开发之手势识别
- Android应用开发中触摸屏手势识别的实现方法解析
- Android 手机应用开发经验之手势识别Gesture的研究
- Android应用开发基础篇(13)-----GestureDetector(手势识别)
- Android 手势锁的实现 让自己的应用更加安全吧
- android 手势识别(二)
- 开发具备语音识别功能的 Android* 应用
- Android 手势操作识别
- Android的手势识别
- android的手势识别
- 编写 Android 触摸屏手势识别程序
- Android手势识别
- android可以识别用户的手势
- Android的手势操作识别
- 理解Android的手势识别
- Android Gesture 手势识别使用实例 - Android - mobile - ITeye论坛
- 【Android】手势识别