want to trigger on two fingers down
event for a few milliseconds.
I am able to trigger simple touch event by using this code:
objImageView.getLocationOnScreen(coords);
int xa = coords[0];
int ys = coords[1];
objImageView.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, xa, ys, 0.5f, 5, 0, 1, 1, 0, 0));
objImageView.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, xa, ys, 0.5f, 5, 0, 1, 1, 0, 0));
objImageView.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, xa, ys, 0.5f, 5, 0, 1, 1, 0, 0));
Now if I try to do the same for ACTION_POINTER_DOWN nothing is happening. Here is my code:
int[] coords = new int[2];
parentLayout.getLocationOnScreen(coords);
int xa = coords[0];
int ys = coords[1];
parentLayout.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_POINTER_DOWN, xa, ys, 0.5f, 5, 0, 1, 1, 0, 0));
parentLayout.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, xa, ys, 0.5f, 5, 0, 1, 1, 0, 0));
parentLayout.dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_POINTER_UP, xa, ys, 0.5f, 5, 0, 1, 1, 0, 0));
I want to trigger the same event which called when user places the two fingers down and hold fingers there for a few milliseconds.
To simulate "two fingers" you will need to create a motion event that includes more than one pointer, as you do now.
To do that, use the MotionEvent obtain
variation that supports multiple pointers as is documented here.
MotionEvent obtain (long downTime,
long eventTime,
int action,
int pointerCount,
PointerProperties[] pointerProperties,
PointerCoords[] pointerCoords,
int metaState,
int buttonState,
float xPrecision,
float yPrecision,
int deviceId,
int edgeFlags,
int source,
int flags)
First you should dispatch an event for the first finger (exactly like you did) and when you are about to simulate MotionEvent.ACTION_POINTER_DOWN
you should use the above obtain
variation.
Fields are pretty self explanatory, make sure the params are: