【Android】关于touch设备TOOL_TYPE_STYLUS

2023-10-14 14:04

本文主要是介绍【Android】关于touch设备TOOL_TYPE_STYLUS,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这里通过log来查看触控笔的motionEvent,

    @Overridepublic boolean onTouchEvent(MotionEvent event) {Log.i(tag, "event=" + event);return true;}@Overridepublic boolean onGenericMotionEvent(MotionEvent event) {Log.i(tag, "G event=" + event);return true;}

在靠近屏幕时,调用到onGenericMotionEvent

在触碰到屏幕时,调用onTouchEvent,

toolType[0]=TOOL_TYPE_STYLUS

一次点击的完整log

10-14 12:25:30.040  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_ENTER, actionButton=0, id[0]=0, x[0]=2142.9934, y[0]=1068.1862, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798665, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=16461402 }
10-14 12:25:30.067  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2146.1409, y[0]=1059.1779, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=13, eventTime=142798692, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=983447964 }
10-14 12:25:30.083  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2148.7458, y[0]=1056.4645, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=7, eventTime=142798710, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=645840300 }
10-14 12:25:30.092  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2149.6143, y[0]=1055.9219, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=142798713, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=62681315 }
10-14 12:25:30.099  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2152.1106, y[0]=1054.4023, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=5, eventTime=142798726, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=1026885681 }
10-14 12:25:30.108  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2155.041, y[0]=1053.5342, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798734, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=738838838 }
10-14 12:25:30.116  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2157.9717, y[0]=1052.9915, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798742, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=945623392 }
10-14 12:25:30.125  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2160.034, y[0]=1052.9915, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798750, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=209887185 }
10-14 12:25:30.133  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2163.1816, y[0]=1053.4255, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798759, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=372229236 }
10-14 12:25:30.141  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2165.678, y[0]=1054.0768, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798767, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=216054123 }
10-14 12:25:30.150  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2168.3914, y[0]=1054.728, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798775, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=101492618 }
10-14 12:25:30.153  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2171.756, y[0]=1054.9451, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=142798780, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=861304425 }
10-14 12:25:30.153  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_EXIT, actionButton=0, id[0]=0, x[0]=2171.756, y[0]=1054.9451, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798782, downTime=0, deviceId=7, source=0x5002, displayId=0, eventId=866096615 }
10-14 12:25:30.155  6190  6190 I test9   : event=MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=2171.756, y[0]=1054.9451, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798782, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=406230247 }
10-14 12:25:30.158  6190  6190 I test9   : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2171.539, y[0]=1054.9451, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=142798785, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=120979047 }
10-14 12:25:30.166  6190  6190 I test9   : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2170.3452, y[0]=1054.728, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798794, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=72378347 }
10-14 12:25:30.174  6190  6190 I test9   : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2169.6938, y[0]=1053.9683, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798802, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=72421242 }
10-14 12:25:30.183  6190  6190 I test9   : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2168.8257, y[0]=1053.2085, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798810, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=507279949 }
10-14 12:25:30.191  6190  6190 I test9   : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2168.3914, y[0]=1052.7744, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798819, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=103703126 }
10-14 12:25:30.200  6190  6190 I test9   : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2167.5232, y[0]=1052.6659, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798827, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=385426269 }
10-14 12:25:30.208  6190  6190 I test9   : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2167.0889, y[0]=1052.2317, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798835, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=752640004 }
10-14 12:25:30.216  6190  6190 I test9   : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2166.4377, y[0]=1052.1232, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798844, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=42588775 }
10-14 12:25:30.225  6190  6190 I test9   : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2166.2207, y[0]=1052.1232, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798852, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=1020026684 }
10-14 12:25:30.226  6190  6190 I test9   : event=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=2166.0037, y[0]=1052.1232, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x2000000, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798852, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=191886775 }
10-14 12:25:30.232  6190  6190 I test9   : event=MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=2166.0037, y[0]=1052.1232, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798854, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=1059956846 }
10-14 12:25:30.234  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_ENTER, actionButton=0, id[0]=0, x[0]=2165.7866, y[0]=1052.3402, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798854, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=156568735 }
10-14 12:25:30.235  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2165.3523, y[0]=1052.5574, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=142798858, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=277665343 }
10-14 12:25:30.241  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2164.2668, y[0]=1054.0768, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798867, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=98280364 }
10-14 12:25:30.249  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2161.4448, y[0]=1056.4645, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798875, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=421868677 }
10-14 12:25:30.257  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2157.9717, y[0]=1059.0693, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798883, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=485500730 }
10-14 12:25:30.266  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2154.4985, y[0]=1061.3485, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798891, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=152502290 }
10-14 12:25:30.274  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2147.8774, y[0]=1063.5192, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798900, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=926486184 }
10-14 12:25:30.283  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2139.086, y[0]=1066.0155, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=3, eventTime=142798908, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=338019200 }
10-14 12:25:30.291  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2128.7747, y[0]=1070.3568, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=142798918, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=1058054799 }
10-14 12:25:30.300  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=2126.9294, y[0]=1071.9849, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=2, eventTime=142798924, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=497747189 }
10-14 12:25:30.300  6190  6190 I test9   : G event=MotionEvent { action=ACTION_HOVER_EXIT, actionButton=0, id[0]=0, x[0]=2126.9294, y[0]=1071.9849, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=142798928, downTime=142798782, deviceId=7, source=0x5002, displayId=0, eventId=588130330 }

在 Android 中,触控笔(Stylus)是一种特殊的输入设备,它可以提供更精确和细致的输入方式。Android 提供了相应的触控笔事件处理机制,以支持触控笔的使用。

触控笔事件与触摸事件略有不同,因为触控笔通常提供了更多的信息,如压力、倾斜角度等。在处理触控笔事件时,你可以使用以下方法和属性:

  1. onTouchEvent(): 在 View 或 Activity 中重写 onTouchEvent() 方法,可以接收触控笔事件。你可以根据事件的类型和属性来处理触控笔事件。

  2. MotionEvent: 触控笔事件使用 MotionEvent 类表示,它提供了许多有用的方法来获取触控笔事件的信息。例如,使用 event.getToolType() 方法可以检测事件的工具类型,通过 event.getPressure() 方法可以获取触压力度,使用 event.getOrientation() 方法可以获取触控笔的倾斜角度等。

在 Android 中,onGenericMotionEvent() 是一个回调方法,用于处理通用输入事件(Generic Motion Event)。它是 View 类的一个方法,用于接收并处理与输入设备相关的通用事件。

通用输入事件可以包括鼠标、轨迹球、游戏手柄等多种输入设备的事件。这些事件与触摸事件略有不同,因为它们提供了更丰富的输入信息,如鼠标滚轮的滚动、轨迹球的移动、游戏手柄的摇杆操作等。

这篇关于【Android】关于touch设备TOOL_TYPE_STYLUS的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/211005

相关文章

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo

Android平台播放RTSP流的几种方案探究(VLC VS ExoPlayer VS SmartPlayer)

技术背景 好多开发者需要遴选Android平台RTSP直播播放器的时候,不知道如何选的好,本文针对常用的方案,做个大概的说明: 1. 使用VLC for Android VLC Media Player(VLC多媒体播放器),最初命名为VideoLAN客户端,是VideoLAN品牌产品,是VideoLAN计划的多媒体播放器。它支持众多音频与视频解码器及文件格式,并支持DVD影音光盘,VCD影

android-opencv-jni

//------------------start opencv--------------------@Override public void onResume(){ super.onResume(); //通过OpenCV引擎服务加载并初始化OpenCV类库,所谓OpenCV引擎服务即是 //OpenCV_2.4.3.2_Manager_2.4_*.apk程序包,存

从状态管理到性能优化:全面解析 Android Compose

文章目录 引言一、Android Compose基本概念1.1 什么是Android Compose?1.2 Compose的优势1.3 如何在项目中使用Compose 二、Compose中的状态管理2.1 状态管理的重要性2.2 Compose中的状态和数据流2.3 使用State和MutableState处理状态2.4 通过ViewModel进行状态管理 三、Compose中的列表和滚动

如何编写Linux PCIe设备驱动器 之二

如何编写Linux PCIe设备驱动器 之二 功能(capability)集功能(capability)APIs通过pci_bus_read_config完成功能存取功能APIs参数pos常量值PCI功能结构 PCI功能IDMSI功能电源功率管理功能 功能(capability)集 功能(capability)APIs int pcie_capability_read_wo

Android 10.0 mtk平板camera2横屏预览旋转90度横屏拍照图片旋转90度功能实现

1.前言 在10.0的系统rom定制化开发中,在进行一些平板等默认横屏的设备开发的过程中,需要在进入camera2的 时候,默认预览图像也是需要横屏显示的,在上一篇已经实现了横屏预览功能,然后发现横屏预览后,拍照保存的图片 依然是竖屏的,所以说同样需要将图片也保存为横屏图标了,所以就需要看下mtk的camera2的相关横屏保存图片功能, 如何实现实现横屏保存图片功能 如图所示: 2.mtk

android应用中res目录说明

Android应用的res目录是一个特殊的项目,该项目里存放了Android应用所用的全部资源,包括图片、字符串、颜色、尺寸、样式等,类似于web开发中的public目录,js、css、image、style。。。。 Android按照约定,将不同的资源放在不同的文件夹中,这样可以方便的让AAPT(即Android Asset Packaging Tool , 在SDK的build-tools目

Android fill_parent、match_parent、wrap_content三者的作用及区别

这三个属性都是用来适应视图的水平或者垂直大小,以视图的内容或尺寸为基础的布局,比精确的指定视图的范围更加方便。 1、fill_parent 设置一个视图的布局为fill_parent将强制性的使视图扩展至它父元素的大小 2、match_parent 和fill_parent一样,从字面上的意思match_parent更贴切一些,于是从2.2开始,两个属性都可以使用,但2.3版本以后的建议使

Android Environment 获取的路径问题

1. 以获取 /System 路径为例 /*** Return root of the "system" partition holding the core Android OS.* Always present and mounted read-only.*/public static @NonNull File getRootDirectory() {return DIR_ANDR

Oracle type (自定义类型的使用)

oracle - type   type定义: oracle中自定义数据类型 oracle中有基本的数据类型,如number,varchar2,date,numeric,float....但有时候我们需要特殊的格式, 如将name定义为(firstname,lastname)的形式,我们想把这个作为一个表的一列看待,这时候就要我们自己定义一个数据类型 格式 :create or repla