【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

相关推荐
Cao_Shixin攻城狮2 小时前
Flutter运行Android项目时显示java版本不兼容(Unsupported class file major version 65)的处理
android·java·flutter
呼啦啦呼啦啦啦啦啦啦5 小时前
利用pdfjs实现的pdf预览简单demo(包含翻页功能)
android·javascript·pdf
idjl7 小时前
Mysql测试题
android·adb
游戏开发爱好者810 小时前
iOS App 电池消耗管理与优化 提升用户体验的完整指南
android·ios·小程序·https·uni-app·iphone·webview
人生游戏牛马NPC1号10 小时前
学习 Flutter (四):玩安卓项目实战 - 中
android·学习·flutter
星辰也为你祝福h11 小时前
Android原生Dialog
android
梁同学与Android12 小时前
Android ---【CPU优化】需要优化的原因及优化的地方
android
Misha韩13 小时前
React Native 基础tabBar和自定义tabBar - bottom-tabs
android·react native
iHero13 小时前
【Nextcloud】在 Ubuntu 22.04.3 LTS 上的 Nextcloud Hub 10 (31.0.2) 后台任务cron 的优化
android·linux·ubuntu·nextcloud
yuanlaile17 小时前
Flutter Android打包学习指南
android·flutter·flutter打包·flutter android