在MotionEvent的log中,当多点触碰的时候,我们可以看到action有时候会是105, 205, 106等等这样的形式,这是点index和事件的组合,
251 public static final int ACTION_POINTER_DOWN = 5;
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}
参考资料