原文地址: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. ListView style
  2. kalilinux设置开机自启动:update-rc.d -f apache2 defaults
  3. 优秀大数据GitHub项目一览
  4. 人工智能 | 自然语言处理研究报告(技术篇)
  5. python决策树可视化_「决策树」| Part3—Python实现之可视化
  6. 平台系统表怎么修改为普通表
  7. char怎么比较_为什么阿里巴巴Java开发手册中强制要求整型包装类对象值用 equals 方法比较?...
  8. 在适当的场合使用FlagsAttribute修饰枚举
  9. 软件产品质量要求与评价_软件质量模型
  10. 魅族手机usb计算机连接文件夹,手机连接电脑传输文件(手机usb连接电脑只充电)...
  11. 小爱音箱显示服务器连接不上,小爱音箱无法连接WiFi解决方法
  12. 刷 百度排名,百度(google)搜索提示下拉关联词的一个简易思路··
  13. Excel导入数据库(vue+py)py部分
  14. 浅析微信小程序的底层架构原理
  15. Java中的23种设计模式
  16. 传统企业如何做数字化转型?弄懂这3大底层逻辑你就懂了
  17. 校园文化建设计算机教室标语,【校园文化宣传墙】_校园文化建设墙上布置必备标语宣传画大全...
  18. 从无到有:七步教你做数值(1)
  19. 2012中国情爱报告
  20. 2021-05上海自行车展

热门文章

  1. 三维GIS和数字孪生的融合实现了哪些应用?
  2. 交流电路红的视在功率VA数值上是电压与电流的乘积等于有功功率的平方加上无功功率的平方,再开平方。无功功率将电感或电容元件与交流电源往复交换的功率。虽然无功元件整体做功是0.吸收和释放相等
  3. towad for mysql_for,to,toward,towards的区别
  4. 基于Ffmpeg解码器的简单播放器(a simple audio player based on Ffmpeg)
  5. sequelize与mysql_Sequelize 和 MySQL 对照
  6. 多组学整合2连发,肠道研究新突破:人参残渣有大用
  7. 考研经验---初试篇
  8. 运筹学 知识点总结(四)
  9. Python中函数ravel()的说明:
  10. Digix:密码学资产中的黄金标准