private void moveZoomTilt() {
long downTime = SystemClock.uptimeMillis();
// event time MUST be retrieved only by this way!
long eventTime = SystemClock.uptimeMillis();
Instrumentation inst = getInstrumentation();
View view = solo.getView(R.id.crop_window);
Rect viewRect = new Rect();
view.getGlobalVisibleRect(viewRect);
//set Overall coords and properties of gestures
PointerCoords[] pointCoords = new PointerCoords[2];
pointCoords[0] = new PointerCoords();
pointCoords[0].pressure = 1;
pointCoords[0].size = 1;
pointCoords[1] = new PointerCoords();
pointCoords[1].pressure = 1;
pointCoords[1].size = 1;
PointerProperties[] props = new PointerProperties[2];
props[0] = new PointerProperties();
props[0].id = 0;
props[0].toolType = MotionEvent.TOOL_TYPE_FINGER;
props[1] = new PointerProperties();
props[1].id = 1;
props[1].toolType = MotionEvent.TOOL_TYPE_FINGER;
//Pinch
// Set start point of fingers. Both in the vertical middle, the first on 1/3 of the horizantal scale, the second on 2/3
float finger2XStart = viewRect.left + (viewRect.width() / 3);
float finger2YStart = viewRect.top + (viewRect.height() / 2);
float finger3XStart = viewRect.left + ((viewRect.width() / 3)*2);
float finger3YStart = viewRect.top + (viewRect.height() / 2);
// finger tracks
float[] tracking2X = { -15, -30, -45, -30, -15, 0, 15, 30, 45, 30, 15, 0, -15, -30 };
float[] tracking2Y = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
float[] tracking3X = { 15, 30, 45, 30, 15, 0, -15, -30, -45, -30, -15, 0, 15, 30 };
float[] tracking3Y = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
// set Start Coordinates
pointCoords[0].x = finger2XStart;
pointCoords[0].y = finger2YStart;
pointCoords[1].x = finger3XStart;
pointCoords[1].y = finger3YStart;
try {
// first finger down
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 1, props, pointCoords, 0, 0, 1, 1, 0, 0, 0, 0);
inst.sendPointerSync(event);
// second finger down
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_2_DOWN, 2, props, pointCoords, 0, 0, 1, 1, 0, 0, 0, 0);
inst.sendPointerSync(event);
// move fingers (in j steps)
for(int j = 0; j < tracking2X.length; j++) {
eventTime = SystemClock.uptimeMillis() + 50;
pointCoords[0].x = finger2XStart + tracking2X[j];
pointCoords[0].y = finger2YStart + tracking2Y[j];
pointCoords[1].x = finger3XStart + tracking3X[j];
pointCoords[1].y = finger3YStart + tracking3Y[j];
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 2, props, pointCoords, 0, 0, 1, 1, 0, 0, 0, 0);
inst.sendPointerSync(event);
}
eventTime = SystemClock.uptimeMillis();
// second finger up
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_2_UP, 2, props, pointCoords, 0, 0, 1, 1, 0, 0, 0, 0);
inst.sendPointerSync(event);
// first finger up
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, 1, props, pointCoords, 0, 0, 1, 1, 0, 0, 0, 0);
inst.sendPointerSync(event);
} catch (Exception exception) {
Log.e("pinchError", exception.getMessage());
}