Example usage for android.view MotionEvent setSource

List of usage examples for android.view MotionEvent setSource

Introduction

In this page you can find the example usage for android.view MotionEvent setSource.

Prototype

@Override
public final void setSource(int source) 

Source Link

Usage

From source file:net.hoodalabs.cordova.plugins.touchevent.HoodalabsTouchEvent.java

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext)
        throws JSONException {

    if ("fireAt".equals(action)) {

        final float x = args.getInt(0);
        final float y = args.getInt(1);

        // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
        final int metaState = 0;

        final long timestamp = SystemClock.uptimeMillis();

        MotionEvent touchStart = MotionEvent.obtain(timestamp, timestamp + 50, MotionEvent.ACTION_DOWN, x, y,
                metaState);/*from   ww w  .  j a va  2s. com*/
        touchStart.setSource(InputDevice.SOURCE_TOUCHSCREEN);

        webView.dispatchTouchEvent(touchStart);

        MotionEvent touchEnd = MotionEvent.obtain(timestamp + 50, timestamp + 100, MotionEvent.ACTION_UP, x, y,
                metaState);
        touchEnd.setSource(InputDevice.SOURCE_TOUCHSCREEN);

        webView.dispatchTouchEvent(touchEnd);

        callbackContext.success(); // Thread-safe.
        return true;
    }

    return false;
}