Input系统学习-----MotionEvent多点action的产生

在MotionEvent的log中,当多点触碰的时候,我们可以看到action有时候会是105, 205, 106等等这样的形式,这是点index和事件的组合,

251    public static final int ACTION_POINTER_DOWN     = 5;

252

253    /**

254     * Constant for {@link #getActionMasked}: A non-primary pointer has gone up.

255     * <p>

256     * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.

257     * </p><p>

258     * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the

259     * unmasked action returned by {@link #getAction}.

260     * </p>

261     */

262    public static final int ACTION_POINTER_UP       = 6;

这个组装处理是在InputReader的TouchInputMapper里完成的,组装完成后转发给InputDispatcher

对于down事件,调用dispatchMotion传入的action是AMOTION_EVENT_ACTION_POINTER_DOWN,在方法中对touch数量进行了判断,如果只有1个,转换为AMOTION_EVENT_ACTION_DOWN


 6449void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
6450        int32_t action, int32_t actionButton, int32_t flags,
6451        int32_t metaState, int32_t buttonState, int32_t edgeFlags, uint32_t deviceTimestamp,
6452        const PointerProperties* properties, const PointerCoords* coords,
6453        const uint32_t* idToIndex, BitSet32 idBits, int32_t changedId,
6454        float xPrecision, float yPrecision, nsecs_t downTime) {
6455    PointerCoords pointerCoords[MAX_POINTERS];
6456    PointerProperties pointerProperties[MAX_POINTERS];
6457    uint32_t pointerCount = 0;
6458    while (!idBits.isEmpty()) {
6459        uint32_t id = idBits.clearFirstMarkedBit();
6460        uint32_t index = idToIndex[id];
6461        pointerProperties[pointerCount].copyFrom(properties[index]);
6462        pointerCoords[pointerCount].copyFrom(coords[index]);
6463
6464        if (changedId >= 0 && id == uint32_t(changedId)) {
6465            action |= pointerCount << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
6466        }
6467
6468        pointerCount += 1;
6469    }
6470
6471    ALOG_ASSERT(pointerCount != 0);
6472
6473    if (changedId >= 0 && pointerCount == 1) {
6474        // Replace initial down and final up action.
6475        // We can compare the action without masking off the changed pointer index
6476        // because we know the index is 0.
6477        if (action == AMOTION_EVENT_ACTION_POINTER_DOWN) {
6478            action = AMOTION_EVENT_ACTION_DOWN;
6479        } else if (action == AMOTION_EVENT_ACTION_POINTER_UP) {
6480            action = AMOTION_EVENT_ACTION_UP;
6481        } else {
6482            // Can't happen.
6483            ALOG_ASSERT(false);
6484        }
6485    }
6486
6487    NotifyMotionArgs args(when, getDeviceId(), source, policyFlags,
6488            action, actionButton, flags, metaState, buttonState, edgeFlags,
6489            mViewport.displayId, deviceTimestamp, pointerCount, pointerProperties, pointerCoords,
6490            xPrecision, yPrecision, downTime);
6491    getListener()->notifyMotion(&args);
6492}

参考资料

Input系统分析详解-InputReader_飞_哥的博客-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值