【Android】物理接触式touch的type

在Android设备中,我们可以使用手指来进行屏幕触控操作,也有触控笔等设备,也有自动点击器这样的设备,这里我们来看看他们在MotionEvent中的type是什么,如果type一致,不同的设备touch事件可以共存。

在代码中添加log,打印MotionEvent即可观察

java 复制代码
public class MainActivity extends AppCompatActivity {

    @Override
    public boolean onTouchEvent(MotionEvent motionEvent) {
        Log.i("test114", "motionevent=" + motionEvent);
        return false;
    }
  1. 手指touch,toolType[0]=TOOL_TYPE_FINGER
java 复制代码
08-10 19:40:44.048 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=1571.3867, y[0]=400.75, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=121686176, downTime=121686176, deviceId=8, source=0x1002, displayId=0, eventId=99301767 }
08-10 19:40:44.053 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1571.3867, y[0]=400.75, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=121686181, downTime=121686176, deviceId=8, source=0x1002, displayId=0, eventId=309619483 }
08-10 19:40:44.054 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=1571.3867, y[0]=400.75, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=121686194, downTime=121686176, deviceId=8, source=0x1002, displayId=0, eventId=566998607 }
  1. 普通的导电触屏笔,toolType[0]=TOOL_TYPE_FINGER
java 复制代码
08-10 19:42:54.423 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=1623.3662, y[0]=411.74316, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=121816559, downTime=121816559, deviceId=8, source=0x1002, displayId=0, eventId=323824768 }
08-10 19:42:54.428 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1623.3662, y[0]=411.74316, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=121816565, downTime=121816559, deviceId=8, source=0x1002, displayId=0, eventId=365482332 }
  1. 特殊的触控笔,toolType[0]=TOOL_TYPE_STYLUS
java 复制代码
08-10 19:44:07.289 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=1468.749, y[0]=391.1748, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=121889428, downTime=121889428, deviceId=7, source=0x5002, displayId=0, eventId=902540448 }
08-10 19:44:07.293 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1468.749, y[0]=391.1748, toolType[0]=TOOL_TYPE_STYLUS, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=121889430, downTime=121889428, deviceId=7, source=0x5002, displayId=0, eventId=417635430 }
  1. 点击器设备,这种设备可以搜到很多
java 复制代码
08-10 19:50:03.541 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=122245665, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=529445397 }
08-10 19:50:03.559 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=122245696, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=285560474 }
08-10 19:50:03.567 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=122245705, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=695468747 }
08-10 19:50:03.575 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=122245713, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=1021987380 }
08-10 19:50:03.584 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=122245721, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=24098659 }
08-10 19:50:03.592 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=122245730, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=947573210 }
08-10 19:50:03.601 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=122245738, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=1023697170 }
08-10 19:50:03.609 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=122245747, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=914557326 }
08-10 19:50:03.617 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=122245755, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=1024595037 }
08-10 19:50:03.626 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=122245763, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=610083777 }
08-10 19:50:03.634 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=122245771, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=417593152 }
08-10 19:50:03.660 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=122245801, downTime=122245665, deviceId=8, source=0x1002, displayId=0, eventId=922423896 }
08-10 19:50:03.866 14115 14115 I test114 : motionevent=MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=1996.2207, y[0]=1148.2822, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=122246004, downTime=122246004, deviceId=8, source=0x1002, displayId=0, eventId=347762606 }

可以看到,除了down,up事件,还有很多的move事件

有时候可以注意到,通电的充电线也可以在屏幕上出现touch效果,这个touch和手指touch不会发生冲突,其type应该也是TOOL_TYPE_FINGER

相关推荐
刘龙超2 小时前
如何应对 Android 面试官 -> 玩转 RxJava (基础使用)
android·rxjava
柿蒂3 小时前
从动态缩放自定义View,聊聊为什么不要把问题复杂化
android·ai编程·android jetpack
kerli3 小时前
kotlin协程系列:callbackFlow
android·kotlin
没有了遇见4 小时前
Android 原生定位实现(替代融合定位收费,获取经纬度方案)
android·kotlin
一枚小小程序员哈4 小时前
基于Android的车位预售预租APP/基于Android的车位租赁系统APP/基于Android的车位管理系统APP
android·spring boot·后端·struts·spring·java-ee·maven
诸神黄昏EX4 小时前
Android SystemServer 系列专题【篇四:SystemServerInitThreadPool线程池管理】
android
用户2018792831675 小时前
pm path 和 dumpsys package 的区别
android
是店小二呀5 小时前
【C++】智能指针底层原理:引用计数与资源管理机制
android·java·c++
DoubleYellowIce6 小时前
一次混淆XLog导致的crash分析记录
android
你听得到117 小时前
弹窗库1.1.0版本发布!不止于统一,更是全面的体验升级!
android·前端·flutter