private GestureLibrary gesLib;
private GestureOverlayView gesOverlay;
private String gesPath;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.get_gesture);
/* 查看SDCard是否存在 */
if (!Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())) {
/* SD卡不存在,显示Toast信息 */
Toast.makeText(GetGesture.this, "SD卡不存在!程序无法运行", Toast.LENGTH_LONG)
.show();
finish();
}
else {
/* 取得GestureLibrary的文件路径 */
gesPath = new File(Environment.getExternalStorageDirectory(),
"gestures").getAbsolutePath();
File file = new File(gesPath);
if (!file.exists()) {
/* gestures文件不存在,显示Toast信息 */
Toast.makeText(GetGesture.this, "gestures文件不存在!程序无法运行",
Toast.LENGTH_LONG).show();
finish();
}
else {
/* 初始化GestureLibrary */
gesLib = GestureLibraries.fromFile(gesPath);
if (!gesLib.load()) {
/* 读取失败,显示Toast信息 */
Toast.makeText(GetGesture.this, "gestures文件读取失败!程序无法运行",
Toast.LENGTH_LONG).show();
finish();
} else {
/* GestureOverlayView初始化 */
gesOverlay = (GestureOverlayView) findViewById(R.id.myGestures1);
gesOverlay.addOnGesturePerformedListener(new MyListener(
this));
}
}
}
}
/* 告定义OnGesturePerformedListener */
public class MyListener implements OnGesturePerformedListener {
private Context context;
public MyListener(Context context) {
this.context = context;
}
public void onGesturePerformed(GestureOverlayView overlay,
Gesture gesture) {
/* 手势比对 */
ArrayList<Prediction> predictions = gesLib.recognize(gesture);
if (predictions.size() > 0) {
/* 取最接近的手势 */
Prediction prediction = predictions.get(0);
/* 取得预测值吹少己于1.0 */
if (prediction.score > 1.0) {
/* prediction.name?为?串预测结果 */
Toast.makeText(this.context, prediction.name,
Toast.LENGTH_SHORT).show();
} else {
/* 比对不到,显示Toast */
Toast.makeText(this.context, "找不到匹配的Gesture!",
Toast.LENGTH_SHORT).show();
}
} else {
/* 比对不到,显示Toast */
Toast.makeText(this.context, "找不到匹配的Gesture!",
Toast.LENGTH_SHORT).show();
}
}
}
<?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">
<TextView
android:id="@+id/myTextView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="请在屏幕上画出Gesture"
android:textSize="18sp" />
<android.gesture.GestureOverlayView
android:id="@+id/myGestures1"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
android:gestureStrokeType="multiple" />
</LinearLayout>
分享到:
相关推荐
GESTURE
smooth gesture for chrome. chrome的插件
Kinect+Gesture+recognition Kinect+Gesture+recognition
js touch触屏gesture手势demo
Paper on gesture recognition
gesture的识别和自定义gesture
Android Gesture Builder
gesture-detector java source code
Gesture Driven Fuzzy Interface System for Car Racing Game....Pages 117-134 Type-2 Fuzzy Classifier Based Pathological Disorder Recognition....Pages 135-194 Probabilistic Neural Network Based Dance ...
hand gesture recognition
Android Gesture 手势 的识别,本程序只识别已经添加的0-9的数字
SmartGesture,驱动工具。华硕触摸板使用的SmartGesture,驱动工具。华硕触摸板使用的
UnityVR手势识别插件VR Infinite Gesture1.1.3HTCVIVE
VR Infinite Gesture——最新的版本,assetsore上可以买到的,现在买了免费送给大家
hand gesture recognition system
Android Gesture Detectors Framework Introduction Since I was amazed Android has a ScaleGestureDetector since API level 8 but (still) no such thing as a RotateGestureDetector I decided to create this ...
Hand Gesture Recognition
对应博客的例子,ViewFlipper和Gesture的使用(一)
这是在android gesturebuilder基础上开发的一个小小创意,通过将一个手势和电话簿中的联系人关联 打电话发短信不用翻电话簿 直接一个手势 就搞定 这个程序在删除手势后可能会引起关联错误 有兴趣的朋友可以在源码上...
VR Infinite Gesture 一款SteamVR1.2.3可用的手柄手势识别插件,用户可以编辑录入手势,然后在VR游戏中使用手势触发对应的事件。