List of usage examples for android.app Activity dispatchTouchEvent
public boolean dispatchTouchEvent(MotionEvent ev)
From source file:org.catrobat.catroid.uitest.util.UiTestUtils.java
public static void longClickAndDrag(final Solo solo, final float xFrom, final float yFrom, final float xTo, final float yTo, final int steps) { final Activity activity = solo.getCurrentActivity(); Handler handler = new Handler(activity.getMainLooper()); handler.post(new Runnable() { public void run() { MotionEvent downEvent = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, xFrom, yFrom, 0); activity.dispatchTouchEvent(downEvent); downEvent.recycle();/* ww w. jav a 2s. c om*/ } }); solo.sleep(ViewConfiguration.getLongPressTimeout() + 200); handler.post(new Runnable() { public void run() { double offsetX = xTo - xFrom; offsetX /= steps; double offsetY = yTo - yFrom; offsetY /= steps; for (int i = 0; i <= steps; i++) { float x = xFrom + (float) (offsetX * i); float y = yFrom + (float) (offsetY * i); MotionEvent moveEvent = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, x, y, 0); activity.dispatchTouchEvent(moveEvent); solo.sleep(20); moveEvent.recycle(); } } }); solo.sleep(steps * 20 + 200); handler.post(new Runnable() { public void run() { MotionEvent upEvent = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, xTo, yTo, 0); activity.dispatchTouchEvent(upEvent); upEvent.recycle(); Log.d(TAG, "longClickAndDrag finished: " + (int) yTo); } }); solo.sleep(1000); }