I have a toolbox that I want to use to test my application, but I cannot get scalable scaling to simulate correctly. Here is my current code. Its essence is that: press on finger 1 and finger 2, slide them closer to each other, then release them both.
private void performZoomTest(int numUpdates) { long downTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis(); float x1 = 0; float y1 = 0; Display main = activity.getWindowManager().getDefaultDisplay(); float x2 = main.getWidth(); float y2 = main.getHeight(); float xstep = x2 / (2 * numUpdates); float ystep = y2 / (2 * numUpdates); int id1 = 0 << MotionEvent.ACTION_POINTER_ID_SHIFT; int id2 = 1 << MotionEvent.ACTION_POINTER_ID_SHIFT; MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN + id1, x1, y1, 0); sendPointerSync(event); event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN + id2, x2, y2, 0); sendPointerSync(event); waitForIdleSync(); for (int i = 0; i < numUpdates; i++) { eventTime = SystemClock.uptimeMillis(); Log.i("",Integer.toString(i)); x1 += xstep; y1 += ystep; x2 -= xstep; y2 -= ystep; event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE + id1, x1, y1, 0); Log.i("id1", Integer.toString(MotionEvent.ACTION_MOVE + id1)); sendPointerSync(event); event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE + id2, x2, y2, 0); Log.i("id1", Integer.toString(MotionEvent.ACTION_MOVE + id2)); sendPointerSync(event); waitForIdleSync(); } eventTime = SystemClock.uptimeMillis(); event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP + id1, x1, y1, 0); sendPointerSync(event); event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP + id2, x2, y2, 0); sendPointerSync(event); waitForIdleSync(); }
The result is that the application considers the two events as different and does not register them as one event. Is there a better way to do this?