当前位置:网站首页>GestureOverlayView(手势识别2)
GestureOverlayView(手势识别2)
2022-07-27 17:02:00 【Ashurol】
GestureOverlayView:一种用于手势输入的透明覆盖层,用于识别各种手势,可以覆盖在控件上,也可以包含其他控件,有三个监听接口
1.GestureOverlayView.OnGestureListener//手势监听器
2.GestureOverlayView.OnGesturePerformed//手势执行监听器
3.GestureOverlayView.onGesturing//手势执行中监听器
//新建一项目,用来识别输入的手势与事先存在的手势库的匹配情况
建项目前,先在安卓模拟器中的Gesture Builder(安卓自带)添加自己的手势与对应的手势名称

添加后可以在对应的程序中的mnt中的sdcard路径中找到添加的手势文件,将其导出,再将其导入新的程序res里已建好的文件夹raw中。

public class MainActivity extends ActionBarActivity {
GestureOverlayView myGestureOverlayView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myGestureOverlayView=(GestureOverlayView) findViewById(R.id.gestureOverlayView);
//找到预设的手势文件
//加载手势文件的所有手势
//匹配,识别
//从资源库已经将资源文件加载进来
final GestureLibrary library= GestureLibraries.fromRawResource(this, R.raw.gestures);
library.load();
myGestureOverlayView.addOnGesturePerformedListener(new OnGesturePerformedListener() {
@Override
public void onGesturePerformed(GestureOverlayView arg0, Gesture gesture) {
// TODO Auto-generated method stub
//读出手势库的内容,识别手势
ArrayList<Prediction> mygesture=library.recognize(gesture);
Prediction prediction=mygesture.get(0);
if(prediction.score>=5)
{
if(prediction.name.equals("exit"))
{
finish();
}else if(prediction.name.equals("pervious"))
{
Toast.makeText(MainActivity.this, "上一页", Toast.LENGTH_SHORT).show();
}else if(prediction.name.equals("next"))
{
Toast.makeText(MainActivity.this, "下一页", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(MainActivity.this, "没有该手势", Toast.LENGTH_SHORT).show();
}
}
});
}
}

边栏推荐
- 成本高、落地难、见效慢,开源安全怎么办?
- Complete source code of E-commerce mall applet project (wechat applet)
- 【深度学习基础知识 - 46】贝叶斯定理与条件概率公式
- HDU1171_ Big event in HDU [01 backpack]
- Matplotlib(基本用法)
- Make your chat bubbles colorful
- Come to sword finger offer 03. Repeated numbers in the array
- 【深度学习基础知识 - 37】解决正负样本不均衡 Focal Loss
- [Huawei cloud stack] [shelf presence] issue 13: have you seen the decoupling architecture of the management area? Help government and enterprise customers solve big problems
- 应用程序池已被禁用
猜你喜欢

C language: 8. Makefile preparation

下放三星3J1传感器:代码暗示Pixel 7人脸识别安全性将大增

5W奖金池/面向高校,2022法律科技创新大赛报名火热进行中

Introduction to Flink operator

Flink简介以及运行架构

Cumulative output data of kettle Excel

Flink 算子简介

influxDB系列(四)TSM引擎(存储原理)

【深度学习基础知识 - 46】贝叶斯定理与条件概率公式

A lock faster than read-write lock. Don't get to know it quickly
随机推荐
Introduction to several wireless protocols
Embedded C language loop deployment
Original pw4203 step-down 1-3 lithium battery charging chip
大佬们,ORACLE CDC,本地运行,老是遇到这个An exception occurred in
记一次无准备的实习面试
全球手机芯片设计领域首家!紫光展锐荣膺TMMi4级国际认证
Low code implementation exploration (45) business parameters
低代码实现探索(四十五)业务参数
c语言:14、预处理
Yanghui triangle
Introduction to Flink operator
I want to consult. Our maxcompute spark program needs to access redis, development environment and production environment redis
[basic knowledge of deep learning - 49] kmeans
C language: 7. How to use C language multi source files
C language: 15. Structure
Flink 算子简介
嵌入式C语言对次数不定的循环的优化
C language: 9. Return in main function
High cost, difficult to implement, slow to take effect, what about open source security?
爱立信承认在中国等五国行贿,向美支付10.6亿美元罚款