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

时间:2011-03-03 14:42:15

标签: android testing instruments multi-touch

我可以简单地模拟单个触摸 - 在我的测试中点击,滑动,按住等,但完全坚持使用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]

这是我的问题:

  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 **]
  3. 如何生成4个坐标的事件(pid 0 x0 y0和pid 1 x1 y1)?

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

    public static MotionEvent获取(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&lt;&lt; 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

    仍然没有想法如何实现它,有人发过多点触控事件吗?

2 个答案:

答案 0 :(得分:2)

我相信你只需要在传递给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

答案 1 :(得分:0)

我认为this可以帮助你..