• [Android Input系统学习]从mouse事件再看input分发


    Android手机连接蓝牙鼠标后,屏幕上可以显示鼠标图标,在/dev/input里可以看到相应的设备,滑动和点击鼠标,getevent命令可以看到input数据。

    但是,我们较为熟悉的事件接收方法View#onTouchEvent里并没有调进去,在onTouchEvent里添加log,在点击的时候会有输出,但是滑动时没有输出,mouse设备的滑动难道不一样?

    较为直观的分析方法是打开InputDispatcher里的log开关,可以看到,滑动的时候,还是会走到notifyMotion方法,我们还可以抓取systrace来查看方法调用流程。

    从log里可以看到,滑动时会有action为7的事件,

    查看MotionEvent.java里的定义

    264    /**
    265     * Constant for {@link #getActionMasked}: A change happened but the pointer
    266     * is not down (unlike {@link #ACTION_MOVE}).  The motion contains the most
    267     * recent point, as well as any intermediate points since the last
    268     * hover move event.
    269     * 

    270 * This action is always delivered to the window or view under the pointer. 271 *

    272 * This action is not a touch event so it is delivered to 273 * {@link View#onGenericMotionEvent(MotionEvent)} rather than 274 * {@link View#onTouchEvent(MotionEvent)}. 275 *

    276 */ 277 public static final int ACTION_HOVER_MOVE = 7;

     * This action is not a touch event so it is delivered to * {@link View#onGenericMotionEvent(MotionEvent)} rather than * {@link View#onTouchEvent(MotionEvent)}.

    使用onGenericMotionEvent(MotionEvent) 方法,就可以获取到mouse的滑动事件了。

    可以看出,mouse设备的事件分发流程和屏幕touch事件的流程是一样的,只是处理细节不一样。

    InputReader线程调用InputDispatcher的notifyMotion方法,然后把事件放入到InBound队列中,

    LoopOnce被唤醒,开始后面的处理,调用DiapatchMotionLock等方法。

    通过systrace查看input的相关调用顺序还是比较清楚的。

  • 相关阅读:
    【代码随想录】算法训练计划16
    centos7.9下安装SVN服务
    JAVA设计模式-建造者模式
    阿里云Code并配置IDEA
    ThreadLocal、InheritableThreadLoal、TransmittableThreadLocal使用说明以及适用场景
    AcWing 827. 双链表
    缓存与数据一致性问题
    redis : 持久化
    Spring基础——XML给Bean起别名
    线性变换及其基本性质
  • 原文地址:https://blog.csdn.net/aaajj/article/details/126795195