Java Code Examples for android.view.MotionEvent#setSource()

The following examples show how to use android.view.MotionEvent#setSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InjectionManager.java    From android-inputinjector with GNU General Public License v2.0 7 votes vote down vote up
public void injectTouchEventRelease(int x, int y)
{
	MotionEvent me = MotionEvent.obtain(
			SystemClock.uptimeMillis(),
			SystemClock.uptimeMillis()+10,
			MotionEvent.ACTION_UP,
			x,
			y,
			0
			);
	
	if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) < android.os.Build.VERSION_CODES.JELLY_BEAN)
		;
	else
		me.setSource(InputDevice.SOURCE_TOUCHSCREEN);
	
	injectEvent(me, INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT);
	me.recycle();
}
 
Example 2
Source File: SmoothRefreshLayout.java    From SmoothRefreshLayout with MIT License 6 votes vote down vote up
protected void sendCancelEvent(MotionEvent event) {
    if (mHasSendCancelEvent || (event == null && mLastMoveEvent == null)) {
        return;
    }
    if (sDebug) {
        Log.d(TAG, "sendCancelEvent()");
    }
    final MotionEvent last = event == null ? mLastMoveEvent : event;
    final long now = SystemClock.uptimeMillis();
    final MotionEvent ev =
            MotionEvent.obtain(
                    now, now, MotionEvent.ACTION_CANCEL, last.getX(), last.getY(), 0);
    ev.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    mHasSendCancelEvent = true;
    mHasSendDownEvent = false;
    super.dispatchTouchEvent(ev);
    ev.recycle();
}
 
Example 3
Source File: MDAbsView.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onEyeHitIn(MDHitEvent hitEvent) {
    super.onEyeHitIn(hitEvent);

    MDHitPoint point = hitEvent.getHitPoint();
    if (point == null || mAttachedView == null) {
        return;
    }
    int action = mTouchStatus == TouchStatus.NOP ? MotionEvent.ACTION_HOVER_ENTER : MotionEvent.ACTION_HOVER_MOVE;
    float x = mAttachedView.getLeft() + mAttachedView.getWidth() * point.getU();
    float y = mAttachedView.getTop() + mAttachedView.getHeight() * point.getV();

    MotionEvent motionEvent = MotionEvent.obtain(hitEvent.getTimestamp(), System.currentTimeMillis(), action, x, y, 0);
    motionEvent.setSource(InputDevice.SOURCE_CLASS_POINTER);
    mAttachedView.dispatchGenericMotionEvent(motionEvent);
    motionEvent.recycle();
    mTouchStatus = TouchStatus.DOWN;

    invalidate();
}
 
Example 4
Source File: HJInput.java    From HJMirror with MIT License 6 votes vote down vote up
public boolean sendMotionEvent(int inputSource, int action, float x, float y) {
    if (mInputManager == null || mInjectInputEventMethod == null) {
        return false;
    }
    try {
        long when = SystemClock.uptimeMillis();
        MotionEvent event = MotionEvent.obtain(when, when, action, x, y, 1.0f, 1.0f,
                0, 1.0f, 1.0f, 0, 0);
        event.setSource(inputSource);
        mInjectInputEventMethod.invoke(mInputManager, event, 0);
        event.recycle();
        return true;
    } catch (Exception e) {
        HJLog.e(e);
    }
    return false;
}
 
Example 5
Source File: InjectionManager.java    From android-inputinjector with GNU General Public License v2.0 6 votes vote down vote up
public void injectTouchEventDown(int x, int y)
{
	MotionEvent me = MotionEvent.obtain(
			SystemClock.uptimeMillis(),
			SystemClock.uptimeMillis()+10,
			MotionEvent.ACTION_DOWN,
			x,
			y,
			0
			);
	
	if(Integer.valueOf(android.os.Build.VERSION.SDK_INT) < android.os.Build.VERSION_CODES.JELLY_BEAN)
		;
	else
		me.setSource(InputDevice.SOURCE_TOUCHSCREEN);
	
	injectEvent(me, INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT);
	me.recycle();
}
 
Example 6
Source File: ContentViewGestureHandler.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Resets gesture handlers state; called on didStartLoading().
 * Note that this does NOT clear the pending motion events queue;
 * it gets cleared in hasTouchEventHandlers() called from WebKit
 * FrameLoader::transitionToCommitted iff the page ever had touch handlers.
 */
void resetGestureHandlers() {
    MotionEvent me = obtainActionCancelMotionEvent();
    me.setSource(InputDevice.SOURCE_CLASS_POINTER);
    mGestureDetector.onTouchEvent(me);
    mZoomManager.processTouchEvent(me);
    me.recycle();
    mLongPressDetector.cancelLongPress();
}
 
Example 7
Source File: MDAbsView.java    From MD360Player4Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onEyeHitOut(long timestamp) {
    super.onEyeHitOut(timestamp);
    if (mTouchStatus == TouchStatus.DOWN){
        MotionEvent motionEvent = MotionEvent.obtain(timestamp, System.currentTimeMillis(), MotionEvent.ACTION_HOVER_EXIT, 0, 0, 0);
        motionEvent.setSource(InputDevice.SOURCE_CLASS_POINTER);
        mAttachedView.dispatchGenericMotionEvent(motionEvent);
        motionEvent.recycle();
    }
    mTouchStatus = TouchStatus.NOP;

    invalidate();
}
 
Example 8
Source File: MDAbsView.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEyeHitOut(long timestamp) {
    super.onEyeHitOut(timestamp);
    if (mTouchStatus == TouchStatus.DOWN){
        MotionEvent motionEvent = MotionEvent.obtain(timestamp, System.currentTimeMillis(), MotionEvent.ACTION_HOVER_EXIT, 0, 0, 0);
        motionEvent.setSource(InputDevice.SOURCE_CLASS_POINTER);
        mAttachedView.dispatchGenericMotionEvent(motionEvent);
        motionEvent.recycle();
    }
    mTouchStatus = TouchStatus.NOP;

    invalidate();
}
 
Example 9
Source File: InteractionController.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private boolean touchMove(int x, int y) {
	final long eventTime = SystemClock.uptimeMillis();
	MotionEvent event = MotionEvent.obtain(mDownTime, eventTime,
			MotionEvent.ACTION_MOVE, x, y, 1.0f, 1.0f, 0, 1.0f, 1.0f,
			eventId, 0);

	event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
	return injectEventSync(event);
}
 
Example 10
Source File: InteractionController.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private boolean touchDown(int x, int y) {
	mDownTime = SystemClock.uptimeMillis();
	MotionEvent event = MotionEvent.obtain(mDownTime, mDownTime,
			MotionEvent.ACTION_DOWN, x, y, 1.0f, 1.0f, 0, 1.0f, 1.0f,
			eventId, 0);
	event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
	return injectEventSync(event);
}
 
Example 11
Source File: AutomatorServiceImpl.java    From android-uiautomator-server with MIT License 5 votes vote down vote up
public boolean injectInputEvent(int action, float x, float y, int metaState) {
    MotionEvent e = MotionEvent.obtain(SystemClock.uptimeMillis(),
            SystemClock.uptimeMillis(),
            action, x, y, metaState);
    e.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    boolean b = uiAutomation.injectInputEvent(e, true);
    e.recycle();
    return b;
}
 
Example 12
Source File: MyInteractionController.java    From PUMA with Apache License 2.0 5 votes vote down vote up
private boolean touchMove(int x, int y) {
	if (DEBUG) {
		Log.d(LOG_TAG, "touchMove (" + x + ", " + y + ")");
	}
	final long eventTime = SystemClock.uptimeMillis();
	MotionEvent event = MotionEvent.obtain(mDownTime, eventTime, MotionEvent.ACTION_MOVE, x, y, 1);
	event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
	return injectEventSync(event);
}
 
Example 13
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
/**
 * Dispatch a pointer event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    try {
        WindowManagerGlobal.getWindowManagerService().injectInputAfterTransactionsApplied(event,
                InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
    } catch (RemoteException e) {
    }
}
 
Example 14
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a pointer event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
Example 15
Source File: Instrumentation.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a pointer event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
Example 16
Source File: Instrumentation.java    From droidel with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a pointer event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
Example 17
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a trackball event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the trackball action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendTrackballEventSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
        event.setSource(InputDevice.SOURCE_TRACKBALL);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
Example 18
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a trackball event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the trackball action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendTrackballEventSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
        event.setSource(InputDevice.SOURCE_TRACKBALL);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
Example 19
Source File: Instrumentation.java    From AndroidComponentPlugin with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a pointer event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the pointer action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendPointerSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) {
        event.setSource(InputDevice.SOURCE_TOUCHSCREEN);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
 
Example 20
Source File: Instrumentation.java    From droidel with Apache License 2.0 3 votes vote down vote up
/**
 * Dispatch a trackball event. Finished at some point after the recipient has
 * returned from its event processing, though it may <em>not</em> have
 * completely finished reacting from the event -- for example, if it needs
 * to update its display as a result, it may still be in the process of
 * doing that.
 * 
 * @param event A motion event describing the trackball action.  (As noted in 
 * {@link MotionEvent#obtain(long, long, int, float, float, int)}, be sure to use 
 * {@link SystemClock#uptimeMillis()} as the timebase.
 */
public void sendTrackballEventSync(MotionEvent event) {
    validateNotAppThread();
    if ((event.getSource() & InputDevice.SOURCE_CLASS_TRACKBALL) == 0) {
        event.setSource(InputDevice.SOURCE_TRACKBALL);
    }
    InputManager.getInstance().injectInputEvent(event,
            InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}