Я пытаюсь сгенерировать жест масштабирования/щипка для тестирования. Я пытался использовать Android API MotionEvent.obtain (), но обнаружил, что реализовать события масштабирования/щипка сложно.
Я ссылался на API из MotionEvent.obtain . Можете ли вы сказать мне правильный метод?
Вот моя реализация:
//for zoom, we need four points coordinations: start0, start1, end0, end1
Instrumentation inst;
// action down event
MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 1, prop_start0, pointerCoords_start0, 0, 0, 0, 0, 0, 0, 0, 0 );
inst.sendPointerSync(event);
// action pointer 2 down event
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_2_DOWN, 2, properties_start0_1, pointerCoords_start0_1, 0, 0, 0, 0, 0, 0, 0, 0);
inst.sendPointerSync(event);
// action move events
duration = 1000; //1000 ms
event_interval = 10;//time interval between consecutive events 10ms
moveEventNum = duration / event_interval;
stepx0 = (end0.x - start0.x)/moveEventNum;
stepy0 = (end0.y - start0.y)/moveEventNum;
stepx1 = (end1.x - start1.x)/moveEventNum;
stepy1 = (end1.y - start1.y)/moveEventNum;
move_event0= start0;
move_event1 = start1;
for ( int i = 0; i < moveEventNum; i++) {
// [generate middle points here ]
mov_event0.x += stepx0;
mov_event0.y += stepy0;
mov_event1.x += stepx1;
mov_event1.y += stepy1;
eventTime += event_interval;
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 2, properties_move_event, pointerCoords_move_event0_1, 0, 0, 0, 0, 0, 0, 0, 0);
inst.sendPointerSync(event);
}
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_2_UP, 2, properties_end0_1, pointerCoords_end0_1, 0, 0, 0, 0, 0, 0, 0, 0);
inst.sendPointerSync(event);
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, 1, end1, pointerCoords_end1, 0, 0, 0, 0, 0, 0, 0, 0 );
inst.sendPointerSync(event);