课程目标:

学习Android必不可少的手势的功能

了解手势识别原理 , 掌握制作,加载以及识别手势

写出自己的手势Demo

重点难点:手势机制的了解     手势库的制作

考核目标:请说一下手势库的机制 ,同时类似推演语音识别机制

二、手势的原理

(1)使用GuesturesBuilder创建手势库

生成手势文件到:/sdcard/gestures

(2)加载手势库

把生成的文件放到res/raw下面,这就是手势库文件,供加载匹配

mLibrary = GestureLibraries.fromRawResource(this, R.raw.spells);

if (!mLibrary.load()) {

finish();

}

(3)识别手势

 1,
<android.gesture.GestureOverlayView
android:id="@+id/gestures"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0" />
2,
GestureOverlayView gestures = (GestureOverlayView)
findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this); 3,
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<prediction> predictions = mLibrary.recognize(gesture); // We want at least one prediction
if (predictions.size() > 0) {
Prediction prediction = predictions.get(0);
// We want at least some confidence in the result
if (prediction.score > 1.0) {
// Show the spell
Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT).show();
}
}
}

(4)Gestures overlay

【自己独立View识别】

【嵌套其它View】

 And here is what the XML layout looks like:

 <android.gesture.GestureOverlayView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gestures"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gestureStrokeType="multiple"
android:eventsInterceptionEnabled="true"
android:orientation="vertical"> <ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /> </android.gesture.GestureOverlayView>
In this application, the gestures view is an overlay on top of a regular ListView. The overlay also specifies a few properties that we did not need before: gestureStrokeType: indicates whether we want to recognize gestures made of a single stroke or multiple strokes. Since one of our gestures is the "+" symbol, we need multiple strokes
eventsInterceptionEnabled: when set to true, this property tells the overlay to steal the events from its children as soon as it knows the user is really drawing a gesture. This is useful when there's a scrollable view under the overlay, to avoid scrolling the underlying child as the user draws his gesture
orientation: indicates the scroll orientation of the views underneath. In this case the list scrolls vertically, which means that any horizontal gestures (like action_delete) can immediately be recognized as a gesture. Gestures that start with a vertical stroke must contain at least one horizontal component to be recognized. In other words, a simple vertical line cannot be recognized as a gesture since it would conflict with the list's scrolling.
The code used to load and set up the gestures library and overlay is exactly the same as before. The only difference is that we now check the name of the predictions to know what the user intended to do: public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
ArrayList<Prediction> predictions = mLibrary.recognize(gesture);
if (predictions.size() > 0 && predictions.get(0).score > 1.0) {
String action = predictions.get(0).name;
if ("action_add".equals(action)) {
Toast.makeText(this, "Adding a contact", Toast.LENGTH_SHORT).show();
} else if ("action_delete".equals(action)) {
Toast.makeText(this, "Removing a contact",
Toast.LENGTH_SHORT).show();
} else if ("action_refresh".equals(action)) {
Toast.makeText(this, "Reloading contacts",
Toast.LENGTH_SHORT).show();
}
}
}

三、Case:练习手势的制作以及加载和识别

GestureLibrary store = GestureLibraries

.fromFile("/sdcard/gestures");

store.addGesture(textView.getText().toString(), gesture);

store.save();

四、Sample&Case:实现手势来跳转Activity

通过手势来跳转Activity

建立5个Activity ,分别放置一张大图

向右滑动是下一个Activity ,向左滑动是上一个Activity ,向上滑动是到第一个Activity , 向下滑动是到最后一个Activity

17、手势(Gesture)的更多相关文章

  1. android学习笔记52——手势Gesture,增加手势、识别手势

    手势Gesture,增加手势 android除了提供了手势检测之外,还允许应用程序把用户手势(多个持续的触摸事件在屏幕上形成特定的形状)添加到指定文件中,以备以后使用 如果程序需要,当用户下次再次画出 ...

  2. android学习笔记51——SQLite 手势Gesture

    手势Gesture 所谓手势,是指用户手指或触摸笔在触摸屏幕上的连续触碰行为. Androi对两种手势行为都提供了支持: 1.对于第一种手势而言,android提供了手势检测,并为手势检测提供了相应的 ...

  3. 【转】 iOS开发之手势gesture详解

    原文:http://www.cnblogs.com/salam/archive/2013/04/30/iOS_gesture.html 前言 在iOS中,你可以使用系统内置的手势识别 (Gesture ...

  4. 0128——手势Gesture

    UIGestureRecognizer: 1.locationinView 获取手势在某个视图里面的坐标位置 2.delegate监听手势的行为 3.state状态 开始:UIGestureRecog ...

  5. iOS开发之手势gesture详解(二)

    与其他用户界面控件交互 UIControl子类会覆盖parentView的gesture.例如当用户点击UIButton时,UIButton会接受触摸事件,它的parentView不会接收到.这仅适用 ...

  6. iOS开发之手势gesture详解(一)

    前言 在iOS中,你可以使用系统内置的手势识别(GestureRecognizer),也可以创建自己的手势.GestureRecognizer将低级别的转换为高级别的执行行为,是你绑定到view的对象 ...

  7. HoloLens开发笔记之Gesture input手势输入

    手势是HoloLens三个首要输入形式之一.一旦你使用凝视定位了一个全息图像,手势允许你与它交互.手势输入允许你使用手或者点击器原生地与全息图像交互. 手势之外,你也可以在应用中使用语音输入来交互. ...

  8. 手势识别(一)--手势基本概念和ChaLearn Gesture Challenge

    以下转自: http://blog.csdn.net/qq1175421841/article/details/50312565 像点击(clicks)是GUI平台的核心,轻点(taps)是触摸平台的 ...

  9. HoloLens开发手记 - 手势输入 Gesture input

    手势是HoloLens三个首要输入形式之一.一旦你使用凝视定位了一个全息图像,手势允许你与它交互.手势输入允许你使用手或者点击器原生地与全息图像交互. 手势之外,你也可以在应用中使用语音输入来交互. ...

  10. EasyTouch5插件使用 EasyTouch手势检测功能

    (1)导入EasyTouch5插件,注意该插件对Unity有版本要求 (2)首先在场景中创建一个EasyTouch,这个是必需的,它是进行检测的核心组件,场景中有任何物体使用了EasyTouch的东西 ...

随机推荐

  1. 黑马程序员 SaveFileDialog的跨线程调用 (专题三)

    <a href="http://edu.csdn.net"target="blank">ASP.Net+Android+IO开发S</a> ...

  2. 南京邮电大学CTF隐写术部分Writeup

    女神 听说这是女神的私房照,里面藏着flag哦 http://115.28.150.176/misc1.jpg 这个链接居然打不开,摔!万念俱灰!主办方可否给力点! P.S.为了方便日后学习,暂时列下 ...

  3. TCP报头

    源端口和目的端口: 各占16位 ,服务相对应的源端口和目的端口. 序列号: 占32位,它的范围在[0~2^32-1],序号随着通信的进行不断的递增,当达到最大值的时候重新回到0在开始递增.TCP是面向 ...

  4. Objective C 四舍五入,float处理

    NSLog(@"平方:%.f", pow(3,2) ); //result 9 NSLog(@"上舍入:%.f", ceil(3.000000000001)); ...

  5. 李洪强漫谈iOS开发[C语言-011] - C语言标示符

    /** *    标示符 2016年 7月 14日 01 低级语言和高级语言的最大不同: 低级语言用的是机器指令 高级语言就是写一些人可以看得懂的代码-汇编语言 标示符 就是名字 命名规则: 1) 只 ...

  6. seek和tell的用法--获取文件内容大小(字节)

    /*获取文件中存取的数据内容的大小(字节数) ellg() 和 tellp() 这两个成员函数不用传入参数,返回pos_type 类型的值(根据ANSI-C++ 标准) ,就是一个整数,代表当前get ...

  7. C#基础精华02(静态类,值类型,引用类型,枚举,结构,ref与out)

    静态类 静态类不能被其他类继承,静态成员亦不能被继承(访问的是同一个),备注1. 静态类只能继承自Object类.(静态类不能继承自其它类.) 继承(多态).静态本身就是相反的. 静态类不能实现任何接 ...

  8. std::advance 给迭代器增加指定偏移量

    template <class InputIterator, class Distance> void advance (InputIterator& it, Distance n ...

  9. 最短路径算法之三——Bellman-Ford算法

    Bellman-Ford算法 Dijkstra算法无法判断含负权边的图的最短路. 如果遇到负权,在没有负权回路存在时,即便有负权的边,也可以采用Bellman-Ford算法正确求出最短路径. PS:负 ...

  10. Android studio中不同颜色代表什么意思

    和你的版本控制工具相关 绿色,已经加入控制暂未提交红色,未加入版本控制蓝色,加入,已提交,有改动白色,加入,已提交,无改动