public boolean onGenericMotion (MotionEvent event, AndroidInput input) { if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) return false; final int action = event.getAction() & MotionEvent.ACTION_MASK; int x = 0, y = 0; int scrollAmount = 0; long timeStamp = System.nanoTime(); synchronized (input) { switch (action) { case MotionEvent.ACTION_HOVER_MOVE: x = (int)event.getX(); y = (int)event.getY(); if ((x != deltaX) || (y != deltaY)) { // Avoid garbage events postTouchEvent(input, TouchEvent.TOUCH_MOVED, x, y, 0, timeStamp); deltaX = x; deltaY = y; } break; case MotionEvent.ACTION_SCROLL: scrollAmount = (int)-Math.signum(event.getAxisValue(MotionEvent.AXIS_VSCROLL)); postTouchEvent(input, TouchEvent.TOUCH_SCROLLED, 0, 0, scrollAmount, timeStamp); } } Gdx.app.getGraphics().requestRendering(); return true; }
public boolean onGenericMotion (MotionEvent event, AndroidInput input) { if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) == 0) return false; final int action = event.getAction() & MotionEvent.ACTION_MASK; int x = 0, y = 0; int scrollAmount = 0; long timeStamp = System.nanoTime(); synchronized (input) { switch (action) { case MotionEvent.ACTION_HOVER_MOVE: x = (int)event.getX(); y = (int)event.getY(); if ((x != deltaX) || (y != deltaY)) { // Avoid garbage events postTouchEvent(input, TouchEvent.TOUCH_MOVED, x, y, 0, timeStamp); deltaX = x; deltaY = y; } break; case MotionEvent.ACTION_SCROLL: scrollAmount = (int)-Math.signum(event.getAxisValue(MotionEvent.AXIS_VSCROLL)); postTouchEvent(input, TouchEvent.TOUCH_SCROLLED, 0, 0, scrollAmount, timeStamp); } } Gdx.app.getGraphics().requestRendering(); return true; }
@Override public boolean onTouch(View view, MotionEvent event) { if (view != getView()) { return false; } boolean consumed = false; int source = event.getSource(); // logger.log(Level.INFO, "onTouch source: {0}", source); boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN); // logger.log(Level.INFO, "onTouch source: {0}, isTouch: {1}", // new Object[]{source, isTouch}); if (isTouch && touchInput != null) { // send the event to the touch processor consumed = touchInput.onTouch(event); } return consumed; }
@Override public boolean onHover(View view, MotionEvent event) { if (view != getView()) { return false; } boolean consumed = false; int source = event.getSource(); // logger.log(Level.INFO, "onTouch source: {0}", source); boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN); // logger.log(Level.INFO, "onTouch source: {0}, isTouch: {1}", // new Object[]{source, isTouch}); if (isTouch && touchInput != null) { // send the event to the touch processor consumed = ((AndroidTouchInput14)touchInput).onHover(event); } return consumed; }
@Override public boolean onGenericMotion(View view, MotionEvent event) { if (view != getView()) { return false; } boolean consumed = false; int source = event.getSource(); // logger.log(Level.INFO, "onGenericMotion source: {0}", source); boolean isJoystick = ((source & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK); if (isJoystick && joyInput != null) { // logger.log(Level.INFO, "onGenericMotion source: {0}, isJoystick: {1}", // new Object[]{source, isJoystick}); // send the event to the touch processor consumed = consumed || ((AndroidJoyInput14)joyInput).onGenericMotion(event); } return consumed; }
@Override public boolean onGenericMotion (View view, MotionEvent motionEvent) { if((motionEvent.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0) return false; AndroidController controller = controllerMap.get(motionEvent.getDeviceId()); if(controller != null) {
private MotionEvent transformEvent(MotionEvent e, int headerPosition) { if (headerPosition == MATCHED_STICKIED_HEADER) { return e; } long downTime = e.getDownTime(); long eventTime = e.getEventTime(); int action = e.getAction(); int pointerCount = e.getPointerCount(); int[] pointerIds = getPointerIds(e); MotionEvent.PointerCoords[] pointerCoords = getPointerCoords(e); int metaState = e.getMetaState(); float xPrecision = e.getXPrecision(); float yPrecision = e.getYPrecision(); int deviceId = e.getDeviceId(); int edgeFlags = e.getEdgeFlags(); int source = e.getSource(); int flags = e.getFlags(); View headerHolder = getChildAt(headerPosition); for (int i = 0; i < pointerCount;i++) { pointerCoords[i].y -= headerHolder.getTop(); } MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords, metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags); return n; }
public boolean onGenericMotionEvent(MotionEvent event) { if ( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { //handle the event return true; } else { return false; } }
@Override public boolean onGenericMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: {
/** * Determines whether the event is from the given source. * @param source The input source to check against. * @return Whether the event is from the given source. */ public static boolean isFromSource(MotionEvent event, int source) { return (event.getSource() & source) == source; }
/** * Gets the source of the event. * * @return The event source or {@link InputDeviceCompat#SOURCE_UNKNOWN} if unknown. * @deprecated Call {@link MotionEvent#getSource()} directly. This method will be * removed in a future release. */ @Deprecated public static int getSource(MotionEvent event) { return event.getSource(); }
@Override public boolean onTouchEvent(MotionEvent ev) { return ev.getSource() == DSListView.MOTION_EVENT_SOURCE && super.onTouchEvent(ev); }
@Override public boolean onGenericMotionEvent(MotionEvent event) { if (0 != (event.getSource() & InputDevice.SOURCE_CLASS_POINTER)) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f) selectNext() else selectPrev(); return true; } } return super.onGenericMotionEvent(event); }
@Override public boolean onGenericMotionEvent(MotionEvent event) { if (0 != (event.getSource() & InputDevice.SOURCE_CLASS_POINTER)) { switch (event.getAction()) { case MotionEvent.ACTION_SCROLL: if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f) selectNext() else selectPrev(); return true; } } return super.onGenericMotionEvent(event); }
@Override public boolean dispatchGenericMotionEvent(MotionEvent event) { // Check that the event came from a joystick since a generic motion event could be almost anything. if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE && mController instanceof GamepadController) { mGamepadController.dealWithMotionEvent(event); updateFlightData(); return true; } else { return super.dispatchGenericMotionEvent(event); } }
@TargetApi(14) public boolean onInterceptTouchEvent(MotionEvent e) { super.onInterceptTouchEvent(e); if (_shouldCapture) { if (_motionEvents.size() < _maxEvents) { boolean isObscured = (e.getFlags() & MotionEvent.FLAG_WINDOW_IS_OBSCURED) != 0; synchronized (_motionEvents) { _motionEvents.add(new AdUnitMotionEvent(e.getActionMasked(), isObscured, e.getToolType(0), e.getSource(), e.getDeviceId(), e.getX(0), e.getY(0), e.getEventTime(), e.getPressure(0), e.getSize(0))); } } } return false; }
private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis) : event.getHistoricalAxisValue(axis, historyPos); // Ignore axis values that are within the 'flat' region of the joystick axis center. // A joystick at rest does not always report an absolute position of (0,0). if (Math.abs(value) > flat) { return value; } } return 0; }
private static float getCenteredAxis(MotionEvent event, InputDevice device, int axis, int historyPos) { final InputDevice.MotionRange range = device.getMotionRange(axis, event.getSource()); if (range != null) { final float flat = range.getFlat(); final float value = historyPos < 0 ? event.getAxisValue(axis) : event.getHistoricalAxisValue(axis, historyPos); // Ignore axis values that are within the 'flat' region of the joystick axis center. // A joystick at rest does not always report an absolute position of (0,0). if (Math.abs(value) > flat) { return value; } } return 0; }
public void pointerMove(List<Long> x, List<Long> y, final PointerType pointerType, final KeyInputState globalKeyInputState, @Nullable final MotionEvent downEvent) throws AppiumException { int metaState = getMetaState(globalKeyInputState); (new MotionEventBuilder()) .withAction(ACTION_MOVE) .withDownTime(downTime) .withPointerType(pointerType) .withX(x) .withY(y) .withMetaState(metaState) .withSource(downEvent != null ? downEvent.getSource() : 0) .build() .run(uiController); }