MotionEvent doesn\'t get a constructor, I wanted to manually create a MotionEvent in my unit test, then how to get that? Thanks.
Here is an example illustrating the accepted answer:
// get the coordinates of the view
int[] coordinates = new int[2];
myView.getLocationOnScreen(coordinates);
// MotionEvent parameters
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
int action = MotionEvent.ACTION_DOWN;
int x = coordinates[0];
int y = coordinates[1];
int metaState = 0;
// dispatch the event
MotionEvent event = MotionEvent.obtain(downTime, eventTime, action, x, y, metaState);
myView.dispatchTouchEvent(event);
KeyEvent.META_SHIFT_ON, etc.