【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

相关推荐
运维Z叔2 小时前
云安全 | AWS S3存储桶安全设计缺陷分析
android·网络·网络协议·tcp/ip·安全·云计算·aws
Reese_Cool3 小时前
【C语言二级考试】循环结构设计
android·java·c语言·开发语言
平凡シンプル3 小时前
安卓 uniapp跨端开发
android·uni-app
elina80133 小时前
安卓实现导入Excel文件
android·excel
严文文-Chris3 小时前
【设计模式-享元】
android·java·设计模式
趋势大仙4 小时前
SQLiteDatabase insert or replace数据不生效
android·数据库
DS小龙哥4 小时前
QT For Android开发-打开PPT文件
android·qt·powerpoint
试行5 小时前
Android实现自定义下拉列表绑定数据
android·java
Dingdangr10 小时前
Android中的Intent的作用
android
技术无疆10 小时前
快速开发与维护:探索 AndroidAnnotations
android·java·android studio·android-studio·androidx·代码注入