[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     * <p>
270     * This action is always delivered to the window or view under the pointer.
271     * </p><p>
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     * </p>
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的相关调用顺序还是比较清楚的。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值