android.view.MotionEvent#setSource ( )源码实例Demo

下面列出了android.view.MotionEvent#setSource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android-inputinjector   文件: InjectionManager.java
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();
}
 
源代码2 项目: android-inputinjector   文件: InjectionManager.java
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();
}
 
源代码3 项目: HJMirror   文件: HJInput.java
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;
}
 
@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();
}
 
源代码5 项目: SmoothRefreshLayout   文件: SmoothRefreshLayout.java
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();
}
 
源代码6 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * 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) {
    }
}
 
源代码7 项目: PUMA   文件: MyInteractionController.java
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);
}
 
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;
}
 
/**
 * 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();
}
 
源代码10 项目: JsDroidCmd   文件: InteractionController.java
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);
}
 
源代码11 项目: JsDroidCmd   文件: InteractionController.java
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);
}
 
@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();
}
 
源代码13 项目: MD360Player4Android   文件: MDAbsView.java
@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();
}
 
源代码14 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * 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);
}
 
源代码15 项目: droidel   文件: Instrumentation.java
/**
 * 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);
}
 
源代码16 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * 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);
}
 
源代码17 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * 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);
}
 
源代码18 项目: AndroidComponentPlugin   文件: Instrumentation.java
/**
 * 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);
}
 
源代码19 项目: android_9.0.0_r45   文件: Instrumentation.java
/**
 * 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);
}
 
源代码20 项目: droidel   文件: Instrumentation.java
/**
 * 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);
}