在我的测试中,我可以简单地模拟单点触摸——点击、滑动、按住等等,但是在使用Android 2.2上的HTС Desire模拟多点触摸时完全卡住了。
请问你能否建议一下,如何重现事件链以测试多点触摸?
我认为我需要使用一些巧妙的MotionEvent,比如MASK之类的东西,但我不知道如何做到这一点。
我在这里找到了一个复制缩放事件的转储: http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-3-understanding-touch-events/1775?tag=mantle_skin;content
1. event ACTION_DOWN[#0(pid 0)=135,179]
2. event ACTION_MOVE[#0(pid 0)=135,184]
3. event ACTION_MOVE[#0(pid 0)=144,205]
4. event ACTION_MOVE[#0(pid 0)=152,227]
5. event ACTION_POINTER_DOWN(pid 1)[#0(pid 0)=153,230;#1(pid 1)=380,538]
6. event ACTION_MOVE[#0(pid 0)=153,231;#1(pid 1)=380,538]
7. event ACTION_MOVE[#0(pid 0)=155,236;#1(pid 1)=364,512]
8. event ACTION_MOVE[#0(pid 0)=157,240;#1(pid 1)=350,498]
9. event ACTION_MOVE[#0(pid 0)=158,245;#1(pid 1)=343,494]
10. event ACTION_POINTER_UP(pid 0)[#0(pid 0)=158,247;#1(pid 1)=336,484]
11. event ACTION_MOVE[#0(pid 1)=334,481]
12. event ACTION_MOVE[#0(pid 1)=328,472]
13. event ACTION_UP[#0(pid 1)=327,471]
这是我的问题:
- 事件 ACTION_POINTER_DOWN(pid 1)[#0(pid 0)=153,230;#1(pid 1)=380,538]
- 事件 ACTION_MOVE[#0**(pid 0)=153,231**;#1**(pid 1)=380,538**]
我如何生成带有4个坐标(pid 0 x0 y0 和 pid 1 x1 y1)的事件?
看起来我需要找到以下事件的使用方式:
public static MotionEvent obtain (long downTime, long eventTime, int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source, int flags)
感谢 Dan 的回复,我已经尝试了这个逻辑,但仍然遇到了添加坐标的问题:
MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 135, 179, 0);
inst.sendPointerSync(event);
// eventTime+=100;
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 135, 184, 0);
inst.sendPointerSync(event);
// eventTime+=100;
int pointerToMove = 1; // pointer IDs are zero-based
event = MotionEvent.obtain(downTime, eventTime, (pointerToMove << MotionEvent.ACTION_POINTER_INDEX_SHIFT) + MotionEvent.ACTION_POINTER_DOWN, 138, 189, 0);
inst.sendPointerSync(event);
event = MotionEvent.obtain(downTime, eventTime, (pointerToMove << MotionEvent.ACTION_POINTER_INDEX_SHIFT) + MotionEvent.ACTION_MOVE, 158, 220, 0);
inst.sendPointerSync(event);
// eventTime+=100;
event = MotionEvent.obtain(downTime, eventTime, (2 * 256) + MotionEvent.ACTION_MOVE, 138, 180, 0);
inst.sendPointerSync(event);
// eventTime+=100;
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 135, 184, 0);
这些事件序列被我的测试存根捕获并以以下方式转储:
(14368): event ACTION_DOWN[#0(pid 0)=135,179]
(14368): event ACTION_MOVE[#0(pid 0)=135,184]
(14368): event ACTION_POINTER_DOWN(pid 1)[#0(pid 0)=138,189]
(14368): event ACTION_MOVE[#0(pid 0)=158,220]
(14368): event ACTION_MOVE[#0(pid 0)=138,180]
(14368): event ACTION_MOVE[#0(pid 0)=135,184]
在这里,您可以看到(2 * 256) + MotionEvent.ACTION_MOVE并不会改变事件的指针ID:( ,而pointerToMove << MotionEvent.ACTION_POINTER_INDEX_SHIFT方法对ACTION_POINTER_DOWN无效,也许我不能在POINTER_DOWN中使用这种方式?我的问题是我无法为Pointer 0和Pointer 1生成2个坐标对。
(14368): event ACTION_POINTER_DOWN(pid 1)[#0(pid 0)=138,189]
您可以看到,使用您的逻辑,我已将pid1添加到事件中,但它仍然没有坐标,因为x和y与pid 0相关联..
提前感谢。
Yahor
我仍然不知道如何实现它,有人发送过多点触控事件吗?