How to make MotionEvent to increase?

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?

+4
source share
4 answers

look here: https://stackoverflow.com/questions/522312/best-practices-for-unit-testing-android-apps

I think multitouch unit testing is not possible with the standard Android platform.

+1
source

I'm not sure exactly what you are doing wrong, but I think there are some articles that can help you.

This blog post from Google is dedicated to working with multi-touch and even shows how you can make a Two-finger Zoom (i.e., zoom), which is different from slide / scroll / drag gestures with one finger.

Below is a link to the code from the example.

0
source

I think the android API MotionEvent API (ACTION_POINTER_DOWN, ACTION_MOVE, ACTION_POINTER_UP) will solve the problem with a few touches. However, I do not know how to get the "numUpdates" parameter.

0
source

This is possible as fooobar.com/questions/347988 / ... demonstrates. Solves a problem for my installation.

0
source

All Articles