8 ② RecognizedGesture 本例识别不了 待解决

------------------------main.java------------------

package com.example.resultgesture;


import java.util.ArrayList;


import android.app.AlertDialog;
import android.gesture.Gesture;
import android.gesture.GestureLibraries;
import android.gesture.GestureLibrary;
import android.gesture.GestureOverlayView;
import android.gesture.GestureOverlayView.OnGesturePerformedListener;
import android.gesture.Prediction;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.ArrayAdapter;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity {


// 定义手势编辑组件
GestureOverlayView gestureView;
// 记录手机上已有的手势库
GestureLibrary gestureLibrary;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 读取上一个程序所创建的手势库
gestureLibrary = GestureLibraries
.fromFile("/sdcard/mygestures");
if (gestureLibrary.load())
{
Toast.makeText(MainActivity.this,"手势文件装载成功!" ,
8000).show();
}
else
{
Toast.makeText(MainActivity.this,"手势文件装载失败!" ,
8000).show();
}
// 获取手势编辑组件
gestureView = (GestureOverlayView) findViewById(R.id.gesture);
// 为手势编辑组件绑定事件监听器
gestureView.addOnGesturePerformedListener(
new OnGesturePerformedListener()
{
@Override
public void onGesturePerformed(GestureOverlayView overlay,
Gesture gesture)
{
// 识别用户刚刚所绘制的手势
ArrayList<Prediction> predictions = gestureLibrary
.recognize(gesture);
ArrayList<String> result = new ArrayList<String>();
//遍历所有找到的Prediction对象
for (Prediction pred : predictions)
{
// 只有相似度大于2.0的手势才会被输出
if (pred.score > 2.0)
{
result.add("与手势【" + pred.name + "】相似度为"
+ pred.score);
}
}
if (result.size() > 0)
{
ArrayAdapter adapter = new ArrayAdapter(
MainActivity.this,
android.R.layout.simple_dropdown_item_1line, result
.toArray());
// 使用一个带List的对话框来显示所有匹配的手势
new AlertDialog.Builder(MainActivity.this)
.setAdapter(adapter, null)
.setPositiveButton("确定", null).show();
}
else
{
Toast.makeText(MainActivity.this,"无法找到能匹配的手势!" ,
8000).show();
}
}
});
}
}

。。。。。。main.xml。。。。。。。。。。。。。。

<?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:id="@+id/gesture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gestureStrokeType="multiple" />
</LinearLayout>

。。。。。。。。。。。。。/res/layout/result.xml。。。。。。。。。。。。。。。。。


<?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">
<ListView 
android:id="@+id/show"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值