I have an Android view that I am detecting a fling gesture on to perform an operation, and I want to write some tests to verify that the gesture is working correctly. I have tried TouchUtils.dragViewTo
and TouchUtils.drag
(with a very small number of steps) but neither of these seem to trigger the event.
Is there a way to simulate the fling gesture?
Ok, this is a really old question, but posting a solution which worked for me, may help others who come searching for this
int[] xy = new int[2];
View v = currentActivity.getCurrentFocus();
v.getLocationOnScreen(xy);
final int viewWidth = v.getWidth();
final int viewHeight = v.getHeight();
final float x = xy[0] + (viewWidth / 2.0f);
float fromY = xy[1] + (viewHeight / 2.0f);
int screenWidth = currentActivity.getWindowManager().getDefaultDisplay().getWidth();
//Drag from centre of screen to Leftmost edge of display
TouchUtils.drag(this, (screenWidth - 1), x, fromY, fromY , 5); //Vary the last parameter to sdjust speed of fling
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With