原文地址:http://bbs.seacat.cn/thread-900-1-1.html

可以通过Android sdk访问Glass触控板的原始数据。但GDK提供一个 gesture detector ,可以自动识别通用手势,包括触摸、滑动和滚动。

通过D-pad keys识别手势

默认情况下,Glass系统会将简单的手势转换为D-pad keys事件。可以监听onKeyDown() 和 onKeyUp() 事件来处理D-pad keys:

1、触摸事件转义为 KEYCODE_DPAD_CENTER
2、相机按钮按下事件转义为 KEYCODE_CAMERA.
3、下滑事件转移为 KEYCODE_BACK

这是一小段触控事件的代码:

public class MyActivity extends Activity {...@Overridepublic boolean onKeyDown(int keycode, KeyEvent event) {if (keycode == KeyEvent.KEYCODE_DPAD_CENTER) {// user tapped touchpad, do somethingreturn true;}...return false;}
}

通过gesture detector识别

使用gesture detector可以识别更多复杂的手势,例如多点触控或滚动。复杂的手势没有对应的D-pad key。

你可以实现 GestureDetector 提供的监听接口来通知 Gesture

识别activity层级的手势

1、创建一个 GestureDetector 的监听来处理识别的手势
2、重写activity的 onGenericMotionEvent() 方法,传入motion events给gesture detector的onMotionEvent()方法

当一个motion时间发生时,系统将它传给gesture detector。如果被识别了,gesture detector通知相关的监听接口来处理事件。

public class MainActivity extends Activity {private GestureDetector mGestureDetector;// ...@Overrideprotected void onCreate(Bundle savedInstanceState) {// ...mGestureDetector = createGestureDetector(this);}private GestureDetector createGestureDetector(Context context) {GestureDetector gestureDetector = new GestureDetector(context);//Create a base listener for generic gesturesgestureDetector.setBaseListener( new GestureDetector.BaseListener() {@Overridepublic boolean onGesture(Gesture gesture) {if (gesture == Gesture.TAP) {// do something on tapreturn true;} else if (gesture == Gesture.TWO_TAP) {// do something on two finger tapreturn true;} else if (gesture == Gesture.SWIPE_RIGHT) {// do something on right (forward) swipereturn true;} else if (gesture == Gesture.SWIPE_LEFT) {// do something on left (backwards) swipereturn true;}return false;}});gestureDetector.setFingerListener(new GestureDetector.FingerListener() {@Overridepublic void onFingerCountChanged(int previousCount, int currentCount) {// do something on finger count changes}});gestureDetector.setScrollListener(new GestureDetector.ScrollListener() {@Overridepublic boolean onScroll(float displacement, float delta, float velocity) {// do something on scrolling}});return gestureDetector;}/** Send generic motion events to the gesture detector*/@Overridepublic boolean onGenericMotionEvent(MotionEvent event) {if (mGestureDetector != null) {return mGestureDetector.onMotionEvent(event);}return false;}
}

识别view层级的手势

1、创建 一个自定义view并重写 dispatchGenericFocusedEvent() 方法。当一个motion 时间发生时,这个方法传入motion事件给gesture detector。

2、设置view为focusable ,以便当view获取焦点的时候能检测到事件。

3、创建一个 GestureDetector 的监听来处理识别的手势

当gesture detector识别到一个motion 的时候,gesture detector通知相关的监听接口来处理事件。

/*** TextView that handles touchpad input (currently only TAP).*/
public class TouchpadHandlingTextView extends TextViewimplements OnAttachStateChangeListener{private final GestureDetector mTouchDetector;public TouchpadHandlingTextView(Context context, AttributeSet attrs) {super(context, attrs);mTouchDetector = createGestureDetector(context);// must set the view to be focusablesetFocusable(true);setFocusableInTouchMode(true);}public TouchpadHandlingTextView(Context context) {this(context, null);}@Overridepublic void onViewAttachedToWindow(View v) {requestFocus();}@Overridepublic void onViewDetachedFromWindow(View v) {}/*** Pass a MotionEvent into the gesture detector*/@Overridepublic boolean dispatchGenericFocusedEvent(MotionEvent event) {if (isFocused()) {return mTouchDetector.onMotionEvent(event);}return super.dispatchGenericFocusedEvent(event);}/*** Create gesture detector that triggers onClickListener. Implement* onClickListener in your Activity and override* onClick() to handle the "tap" gesture.*/private GestureDetector createGestureDetector(Context context) {GestureDetector gd = new GestureDetector(context);gd.setBaseListener(new GestureDetector.BaseListener() {@Overridepublic boolean onGesture(Gesture gesture) {if (gesture == Gesture.TAP) {return performClick();}return false;}});return gd;}
}

谷歌眼镜GDK开发指南之触控手势相关推荐

  1. 谷歌眼镜GDK开发指南之Immersions

    原文地址:http://bbs.seacat.cn/thread-899-1-1.html Immersions(沉浸式)可以提供更多的自定义体验. 可以使用Android标准的Activity来创建 ...

  2. 谷歌眼镜GDK开发指南之快速开始

    原文链接:http://bbs.seacat.cn/thread-894-1-1.html 在你开始使用GDK之前,你需要了解下安卓开发方面的更多知识. 这个快速开始教程能教你安装GDK开发环境,以及 ...

  3. 谷歌眼镜GDK开发指南之语音输入

    原文链接:http://bbs.seacat.cn/thread-901-1-1.html Glass可以让你声明语音命令,从ok glass 语音菜单中启动你的Glassware. 你也可以调用语音 ...

  4. 谷歌眼镜GDK开发指南之动态卡片

    原文地址:http://bbs.seacat.cn/thread-896-1-1.html 动态卡片出现在时间轴的现在和将来区域,显示当前时间段的关联信息. 你可以低频率的渲染动态卡片,几秒一次更新. ...

  5. 谷歌眼镜GDK开发指南之Camera

    原文链接:http://bbs.seacat.cn/thread-903-1-1.html 你可以使用Glass Camera来拍照.录像和相机预览. 拍照或录像你有两个选择: 1.通过 startA ...

  6. Linux的触屏手势软件安装,如何添加Mac的多点触控手势到Ubuntu | MOS86

    虽然Mac操作系统有很多故障,易于使用是苹果在其他地方超越的主要地方.在Mac笔记本电脑上,由于macOS如何实现触摸板手势,因此用户可以期待出色的令人印象深刻的触摸板体验. On默认情况下Ubunt ...

  7. 【已解决】机械革命s1-01触控手势失效解决方案

    0 背景 机械革命s1-01系统更新或者重装系统后可能会出现触控手势失效的情况.据了解,该型号出厂时的驱动版本较老,更新系统后会默认安装较新版本驱动,导致手势无法使用. 1 失败尝试 方法一:从官网下 ...

  8. 惠普触控板使用指南_Windows10触控板的正确使用方法

    如何正确使用Windows10系统的触控板?Windows的触控板虽然不及MacBook,但是它的功能也不能小觑哦!如果你觉得Windows的触控板太LOW了,可能是你的使用方法不对.下面小编给大家分 ...

  9. Linux 设置多指触控手势,以 Manjaro 为例

    Linux 设置多指触控手势,以 Manjaro 为例 date: 2020-09-5 lastmod: 2021-09-29 在 Plasma(KDE) 上借助 gestures.xdotool 设 ...

最新文章

  1. word受权限保护无法打开_双击文档无法打开到底是啥毛病?简单一招解决
  2. Android协程学习
  3. 【转】C# 动态对象(dynamic)的用法
  4. php中ajax方法的理解,基本的PHP和AJAX
  5. 判断点在直线的哪一侧_【倒车入库】车身是否“正直”该怎么判断?
  6. mysql中的存储机制_Mysql的存储引擎
  7. 芯烨Xprinter XP-D3601B 打印机驱动
  8. BIN文件和HEX文件差异
  9. Proteus 8.9SP2仿真软件
  10. my97日期范围限制
  11. 述职答辩提问环节一般可以问些什么_01、述职答辩操作流程指引
  12. 整合+策略:微网通联的GMP平台如何帮助企业搭建统一智慧通信架构
  13. Scrape Center爬虫平台之spa8案例
  14. day29 | 黑马程序员Java全程笔记 | 第二阶段MySQL高级事务-索引-视图-触发器-存储过程
  15. [人工智能-深度学习-81]:视觉 - 视频换脸软件大全
  16. 高龄白菜java学习第101天(java数据结构和算法(19))
  17. 【生信分析】clusterProfiler: universal enrichment tool for functional and comparative study(3)
  18. [Swift]LeetCode473. 火柴拼正方形 | Matchsticks to Square
  19. 牛客小白月赛B JAVA大数或String
  20. 磁共振信号库matlab,【图文详解】磁共振(MRI)信号汇总

热门文章

  1. 救生福 救生手表 救生手环 自救手环
  2. cv练习:看图说话(Image Captioning)--2
  3. CF1520G To Go Or Not To Go?
  4. Node.js基础入门第四天
  5. Link Error : L1907: Fixup overflow in _FSTRUNC, to F_TOLONGK type 3, at offs
  6. 孕妇可以使用计算机,电脑对孕妇的危害有多大 孕妇能用电脑吗
  7. spring的基本配置
  8. Primavera P6 EPPM R8.3.X Patch/Update(补丁/更新)
  9. MATLAB计算并显示h的64×64点的频率响应
  10. 代码行数统计 通过命令