Skip to content Skip to sidebar Skip to footer

Simulate Gestures In Android

How can I simulate gestures programmatically. I get all the points and I would like my app to repeat these drawings. public void onGestureStarted(GestureOverlayView gestureOverlay

Solution 1:

You can use MotionEvent class. Simple use:

MotionEventemulateActionDown= MotionEvent.obtain
(
    // The time (in ms) when the user originally pressed down to start a stream of position events. // This must be obtained from uptimeMillis().
    SystemClock.uptimeMillis(),
    // The the time (in ms) when this specific event was generated. // This must be obtained from uptimeMillis().
    SystemClock.uptimeMillis()+20,
    // The kind of action being performed, such as ACTION_DOWN.
    MotionEvent.ACTION_DOWN, 
    // The X coordinate of this event.1, 
    // The Y coordinate of this event.1, 
    // The state of any meta / modifier keys that were in effect when the event was generated. 0
)

Example shows a simple ACTION_DOWN emulation. Then, you can pass this event to onTouchEvent method of a View:

myView.onTouchEvent(emulateActionDown);

Take a look here: MotionEvent -> obtain

Post a Comment for "Simulate Gestures In Android"