Hi all,
I've been trying to emulate user scrolling on touch screens with no
luck. In order to do this, I'm creating the associated Motion Events
that get called: Down - Move, Move, ... Move - Up. I found this
sequence by attaching a TouchListener to a view and manually doing a
scroll in the emulator. I am imitating this sequence with all the
parameters, but the scroll never happens in the screen.
Here's the code:
public void scroll() {
long downTime = SystemClock.uptimeMillis();
MotionEvent event;
// Down
event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(),
MotionEvent.ACTION_DOWN, 160.00002f, 180.0f,0.0f,0.0f,0,0.0f,0.0f,
0,0);
s.dispatchTouchEvent(event);
// Move
event.setAction(MotionEvent.ACTION_MOVE);
event.setLocation(160.00002f, 175.0f);
s.dispatchTouchEvent(event);
event.setLocation(160.00002f, 158.0f);
s.dispatchTouchEvent(event);
event.setLocation(160.00002f, 142.0f);
s.dispatchTouchEvent(event);
event.setLocation(160.00002f, 138.0f);
s.dispatchTouchEvent(event);
event.setLocation(160.00002f, 131.0f);
s.dispatchTouchEvent(event);
event.setLocation(160.00002f, 129.0f);
s.dispatchTouchEvent(event);
// Up
event.setAction(MotionEvent.ACTION_UP);
event.setLocation(160.00002f, 129.0f);
s.dispatchTouchEvent(event);
}
In this code, I'm using the MotionEvent.obtain method:
public static MotionEvent obtain (long downTime, long eventTime, int
action, float x, float y, float pressure, float size, int metaState,
float xPrecision, float yPrecision, int deviceId, int edgeFlags)
>From the official Android documentation:
http://developer.android.com/reference/android/view/MotionEvent.html#obtain(long,
long, int, float, float, float, float, int, float, float, int, int)
Thanks for your help!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en