android.view.MotionEvent.setSource()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(288)

本文整理了Java中android.view.MotionEvent.setSource()方法的一些代码示例,展示了MotionEvent.setSource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MotionEvent.setSource()方法的具体详情如下:
包路径:android.view.MotionEvent
类名称:MotionEvent
方法名:setSource

MotionEvent.setSource介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

MotionEvent me = MotionEvent.obtain(
   downTime, 
   eventTime, 
   action, 
   x, 
   y, 
   metaState
 );
 me.setSource(4098);
 view.dispatchTouchEvent(me);

代码示例来源:origin: stackoverflow.com

MotionEvent event = MotionEvent.obtain(when, when, action, x, y, pressure, DEFAULT_SIZE,DEFAULT_META_STATE, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y, DEFAULT_DEVICE_ID,DEFAULT_EDGE_FLAGS);
event.setSource(inputSource);
InputManager.getInstance().injectInputEvent(event,InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);

代码示例来源:origin: stackoverflow.com

/**
  * Builds a MotionEvent and injects it into the event stream.
  *
  * @param inputSource the InputDevice.SOURCE_* sending the input event
  * @param action the MotionEvent.ACTION_* for the event
  * @param when the value of SystemClock.uptimeMillis() at which the event happened
  * @param x x coordinate of event
  * @param y y coordinate of event
  * @param pressure pressure of event
  */
 private void injectMotionEvent(int inputSource, int action, long when, float x, float y, float pressure) {
   final float DEFAULT_SIZE = 1.0f;
   final int DEFAULT_META_STATE = 0;
   final float DEFAULT_PRECISION_X = 1.0f;
   final float DEFAULT_PRECISION_Y = 1.0f;
   final int DEFAULT_DEVICE_ID = 0;
   final int DEFAULT_EDGE_FLAGS = 0;
   MotionEvent event = MotionEvent.obtain(when, when, action, x, y, pressure, DEFAULT_SIZE,
       DEFAULT_META_STATE, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y, DEFAULT_DEVICE_ID,
       DEFAULT_EDGE_FLAGS);
   event.setSource(inputSource);
   Log.i(TAG, "injectMotionEvent: " + event);
   InputManager.getInstance().injectInputEvent(event,
       InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
 }

代码示例来源:origin: android-notes/androidScreenShareAndControl

private static void injectMotionEvent(InputManager im, Method injectInputEventMethod, int inputSource, int action, long downTime, long eventTime, float x, float y, float pressure) throws InvocationTargetException, IllegalAccessException {
  MotionEvent event = MotionEvent.obtain(downTime, eventTime, action, x, y, pressure, 1.0f, 0, 1.0f, 1.0f, 0, 0);
  event.setSource(inputSource);
  injectInputEventMethod.invoke(im, new Object[]{event, Integer.valueOf(0)});
}

代码示例来源:origin: luili16/UIMocker

private MotionEvent getMotionEvent(long when, int action, float x, float y, float pressure, int inputSource) {
  MotionEvent event = MotionEvent.obtain(when, when, action, x, y, pressure, Config.DEFAULT_SIZE,
      Config.DEFAULT_META_STATE, Config.DEFAULT_PRECISION_X, Config.DEFAULT_PRECISION_Y,
      getInputDeviceId(inputSource), Config.DEFAULT_EDGE_FLAGS);
  event.setSource(inputSource);
  return event;
}

代码示例来源:origin: stackoverflow.com

//=========================================================================
//==                        Utility Methods                             ===
//=========================================================================
/**
 * Helper method injects a click event at a point on the active screen via the UiAutomation object.
 * @param x the x position on the screen to inject the click event
 * @param y the y position on the screen to inject the click event
 * @param automation a UiAutomation object rtreived through the current Instrumentation
 */
static void injectClickEvent(float x, float y, UiAutomation automation){
  //A MotionEvent is a type of InputEvent.  
  //The event time must be the current uptime.
  final long eventTime = SystemClock.uptimeMillis();

  //A typical click event triggered by a user click on the touchscreen creates two MotionEvents,
  //first one with the action KeyEvent.ACTION_DOWN and the 2nd with the action KeyEvent.ACTION_UP
  MotionEvent motionDown = MotionEvent.obtain(eventTime, eventTime, KeyEvent.ACTION_DOWN,
      x,  y, 0); 
  //We must set the source of the MotionEvent or the click doesn't work.
  motionDown.setSource(InputDevice.SOURCE_TOUCHSCREEN);
  automation.injectInputEvent(motionDown, true);
  MotionEvent motionUp = MotionEvent.obtain(eventTime, eventTime, KeyEvent.ACTION_UP,
      x, y, 0);
  motionUp.setSource(InputDevice.SOURCE_TOUCHSCREEN);
  automation.injectInputEvent(motionUp, true);
  //Recycle our events back to the system pool.
  motionUp.recycle();
  motionDown.recycle();
}

代码示例来源:origin: Ramotion/direct-select-android

@SuppressLint("ClickableViewAccessibility")
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        DSListView.this.showListView();
        break;
      case MotionEvent.ACTION_UP:
        DSListView.this.readyToHide = true;
        hideListView();
        break;
    }
    event.offsetLocation(0, selectorTopMargin + topMarginCompensation);
    event.setSource(MOTION_EVENT_SOURCE);
    DSListView.this.listView.onTouchEvent(event);
    return true;
  }
});

代码示例来源:origin: stackoverflow.com

final MotionEvent eventDown = MotionEvent.obtain(downTime,
    eventTime, MotionEvent.ACTION_DOWN, x, y, 0);
eventDown.setSource(InputDevice.SOURCE_TOUCHSCREEN);
final MotionEvent eventUp = MotionEvent.obtain(downTime, eventTime,
    MotionEvent.ACTION_UP, x, y, 0);
eventUp.setSource(InputDevice.SOURCE_TOUCHSCREEN);
Thread task = new Thread(new Runnable() {

代码示例来源:origin: org.seleniumhq.selenium/selenium-android-driver

public void run() {
  float zoom = view.getScale();
  for (MotionEvent event : events) {
   event.setLocation(zoom * event.getX(), zoom * event.getY());
   try {
    event.setSource(InputDevice.SOURCE_CLASS_POINTER);
   } catch (NoSuchMethodError e) {
    throw new WebDriverException("You are using an Android WebDriver APK "
      + "for ICS SDKs or more recent SDK versions. For more info see "
      + "http://code.google.com/p/selenium/wiki/AndroidDriver#Supported_Platforms.", e);
   }
   view.dispatchTouchEvent(event);
   synchronized (syncObject) {
    done = true;
    syncObject.notify();
   }
  }
 }
});

代码示例来源:origin: xiaocong/android-uiautomator-server

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;
}

代码示例来源:origin: quaap/LaunchTime

mLongClickStarted = -1;
if (wasLong) {                        // setSource is a hack to let us know to ignore that cancel.
  ev.setSource(InputDevice.SOURCE_ANY); //returning true means target will get ACTION_CANCEL.
  wasLong = false;
  return true;

相关文章