【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

相关推荐
Estar.Lee2 小时前
查手机号归属地免费API接口教程
android·网络·后端·网络协议·tcp/ip·oneapi
温辉_xh3 小时前
uiautomator案例
android
工业甲酰苯胺4 小时前
MySQL 主从复制之多线程复制
android·mysql·adb
少说多做3434 小时前
Android 不同情况下使用 runOnUiThread
android·java
Estar.Lee6 小时前
时间操作[计算时间差]免费API接口教程
android·网络·后端·网络协议·tcp/ip
找藉口是失败者的习惯6 小时前
从传统到未来:Android XML布局 与 Jetpack Compose的全面对比
android·xml
Jinkey7 小时前
FlutterBasic - GetBuilder、Obx、GetX<Controller>、GetxController 有啥区别
android·flutter·ios
大白要努力!9 小时前
Android opencv使用Core.hconcat 进行图像拼接
android·opencv
天空中的野鸟10 小时前
Android音频采集
android·音视频
小白也想学C11 小时前
Android 功耗分析(底层篇)
android·功耗