Android测试,如何使用仪器模拟多点触控(放大/缩小)?

发布于 2024-10-19 20:58:23 字数 3442 浏览 3 评论 0原文

在我的测试中,我可以简单地模拟单点触摸 - 点击、滑动、按住等,但完全无法在使用 Android 2.2 的 HTС Desire 上模拟多点触摸。

您能否建议我如何重现事件链来测试多点触摸?

我想我需要使用一些棘手的 MotionEvent,如 MASK 或类似的东西,但不知道如何做到这一点。

我在这里找到了复制缩放事件的转储:

 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]

这是我的问题:

  1. 事件 ACTION_POINTER_DOWN(pid 1)[#0(pid 0)=153,230;#1(pid 1)=380,538]
  2. 事件 ACTION_MOVE[#0**(pid 0) )=153,231**;#1**(pid 1)=380,538**]

如何生成具有 4 个坐标的事件(pid 0 x0 y0 和 pid 1 x1 y1)?

看起来我需要找到如何使用以下事件的方法:

public static MotionEvent acquire (long downTime, long eventTime, int action, intPointers, 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 :( 和 移动指针 << MotionEvent.ACTION_POINTER_INDEX_SHIFT 该方法不适用于 ACTION_POINTER_DOWN,可能是我不允许对 POINTER_DOWN 使用这种方法?

我的问题是我无法为指针 0 和指针 1 生成 2 对坐标:

(14368): event ACTION_POINTER_DOWN(pid 1)[#0(pid 0)=138,189]

在这里您可以看到,使用您的逻辑我已将 pid1 添加到事件中,但它仍然没有坐标,因为 x 和 y 是与 pid 0 相关联。

提前谢谢您。

Yahor

仍然不知道如何实现它,有人发送过多点触控事件吗?

I can simply simulate single touches - tap, swipe, hold etc in my tests, but completely stuck with simulating multi touch on HTС Desire with Android 2.2.

Could you please advise, how can I reproduce events chain to test multi-touches?

I think I need to use some tricky kind of MotionEvent like MASK or something like this, but have no idea how do this.

I have found here a dump of events of reproduced zooming:
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]

Here is my issue:

  1. event ACTION_POINTER_DOWN(pid 1)[#0(pid 0)=153,230;#1(pid 1)=380,538]
  2. event ACTION_MOVE[#0**(pid 0)=153,231**;#1**(pid 1)=380,538**]

How can I generate events with 4 coordinates (pid 0 x0 y0 and pid 1 x1 y1)?

Looks like I need to find the way how to use following event:

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)

Thanks to Dan for reply, I have tried this logic, but still encountering problems to add coordinates:

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);

These events sequence are caught in my test stub and dumped like:

(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]

Here you can see, that
(2 * 256) + MotionEvent.ACTION_MOVE
doesn't change the pointer ID for event :(
And
pointerToMove << MotionEvent.ACTION_POINTER_INDEX_SHIFT
approach is not working for ACTION_POINTER_DOWN, may be I'm not allowed to use such way for POINTER_DOWN?

My issue is that I can't generate 2 pair of coords for Pointer 0 and Pointer 1:

(14368): event ACTION_POINTER_DOWN(pid 1)[#0(pid 0)=138,189]

Here you can see, that using your logic I have added pid1 to the event, but it is still has no coordinates, cause x and y was associated with pid 0..

Thank you in advance.

Yahor

Still have no ideas how to implement it, did somebody ever send a multitouch event?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

許願樹丅啲祈禱 2024-10-26 20:58:23

我相信您只需要在传递给 MotionEvent.obtain 的“action”参数中指示指针索引。具体来说,动作的高8位是指针索引,低8位是动作(例如MotionEvent.ACTION_MOVE)。因此,如果您想移动第二个指针,这应该可行:

int pointerToMove = 1; // pointer IDs are zero-based
event = MotionEvent.obtain(downTime, eventTime, (pointerToMove << MotionEvent.ACTION_POINTER_INDEX_SHIFT) + MotionEvent.ACTION_MOVE, x0, y0, 0);
inst.sendPointerSync(event);

-Dan

I believe you just need to indicate the pointer index in the 'action' parameter passed to MotionEvent.obtain. Specifically, the upper 8-bits of the action is the pointer index and the lower 8-bits is the action (e.g. MotionEvent.ACTION_MOVE). So, if you want to move the second pointer this should work:

int pointerToMove = 1; // pointer IDs are zero-based
event = MotionEvent.obtain(downTime, eventTime, (pointerToMove << MotionEvent.ACTION_POINTER_INDEX_SHIFT) + MotionEvent.ACTION_MOVE, x0, y0, 0);
inst.sendPointerSync(event);

-Dan

ι不睡觉的鱼゛ 2024-10-26 20:58:23

我想 这个可以帮助你..

I supposed this can help you..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文