public boolean onGenericMotion(MotionEvent event) { boolean consumed = false; event.getDeviceId(); event.getSource(); AndroidJoystick joystick = joystickIndex.get(event.getDeviceId()); if (joystick != null) { for (int androidAxis: joystick.getAndroidAxes()) {
@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) { synchronized(eventQueue) {
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; }
@Test public void testWriteToParcel() { Parcel parcel = Parcel.obtain(); motionEvent2.writeToParcel(parcel, Parcelable.PARCELABLE_WRITE_RETURN_VALUE); parcel.setDataPosition(0); MotionEvent motionEvent = MotionEvent.CREATOR.createFromParcel(parcel); assertThat(motionEvent).rawY().isWithin(TOLERANCE).of(motionEvent2.getRawY()); assertThat(motionEvent).rawX().isWithin(TOLERANCE).of(motionEvent2.getRawX()); assertThat(motionEvent).y().isWithin(TOLERANCE).of(motionEvent2.getY()); assertThat(motionEvent).x().isWithin(TOLERANCE).of(motionEvent2.getX()); assertThat(motionEvent).hasAction(motionEvent2.getAction()); assertThat(motionEvent).hasDownTime(motionEvent2.getDownTime()); assertThat(motionEvent).hasEventTime(motionEvent2.getEventTime()); assertThat(motionEvent).hasEdgeFlags(motionEvent2.getEdgeFlags()); assertThat(motionEvent).hasDeviceId(motionEvent2.getDeviceId()); }
check("action()").that(actual().getAction()).isEqualTo(other.getAction()); check("buttonState()").that(actual().getButtonState()).isEqualTo(other.getButtonState()); check("deviceId()").that(actual().getDeviceId()).isEqualTo(other.getDeviceId()); check("getFlags()").that(actual().getFlags()).isEqualTo(other.getFlags()); check("getEdgeFlags()").that(actual().getEdgeFlags()).isEqualTo(other.getEdgeFlags());
@Override public void onGenericMotionEvent(MotionEvent event) { // detect new devices int id = event.getDeviceId(); long[] timeArray = mDevices.get(id); if (null == timeArray) { notifyListeners(ON_DEVICE_ADDED, id); timeArray = new long[1]; mDevices.put(id, timeArray); } long time = SystemClock.elapsedRealtime(); timeArray[0] = time; }
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getDeviceId()) { case MotionEvent.ACTION_DOWN: return true; case MotionEvent.ACTION_CANCEL: break; case MotionEvent.ACTION_UP: if (mIsCanClick) { startAnimation(); } else { Log.e("TEST", mIsCanClick + " "); } break; } return super.onTouchEvent(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; }
@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.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK) && event.getAction() == MotionEvent.ACTION_MOVE) { // Update device state for visualization and logging. InputDeviceState state = getInputDeviceState(event.getDeviceId()); if (state != null && state.onJoystickMotion(event)) { mSummaryAdapter.show(state); } } return super.dispatchGenericMotionEvent(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.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK) && event.getAction() == MotionEvent.ACTION_MOVE) { // Update device state for visualization and logging. InputDeviceState state = getInputDeviceState(event.getDeviceId()); if (state != null && state.onJoystickMotion(event)) { mSummaryAdapter.show(state); } } return super.dispatchGenericMotionEvent(event); }
@Override public boolean handleMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) { int actionPointerIndex = event.getActionIndex(); int action = event.getActionMasked(); switch(action) { case MotionEvent.ACTION_MOVE: SDLJoystick joystick = getJoystick(event.getDeviceId()); if ( joystick != null ) { for (int i = 0; i < joystick.axes.size(); i++) { InputDevice.MotionRange range = joystick.axes.get(i); /* Normalize the value to -1...1 */ float value = ( event.getAxisValue( range.getAxis(), actionPointerIndex) - range.getMin() ) / range.getRange() * 2.0f - 1.0f; SDLControllerManager.onNativeJoy(joystick.device_id, i, value ); } for (int i = 0; i < joystick.hats.size(); i+=2) { int hatX = Math.round(event.getAxisValue( joystick.hats.get(i).getAxis(), actionPointerIndex ) ); int hatY = Math.round(event.getAxisValue( joystick.hats.get(i+1).getAxis(), actionPointerIndex ) ); SDLControllerManager.onNativeHat(joystick.device_id, i/2, hatX, hatY ); } } break; default: break; } } return true; }
@Override public boolean onGenericMotionEvent(MotionEvent event) { mInputManager.onGenericMotionEvent(event); // Check that the event came from a joystick or gamepad since a generic // motion event could be almost anything. API level 18 adds the useful // event.isFromSource() helper function. int eventSource = event.getSource(); if ((((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) || ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) && event.getAction() == MotionEvent.ACTION_MOVE) { int id = event.getDeviceId(); if (-1 != id) { Ship curShip = getShipForId(id); if (curShip.onGenericMotionEvent(event)) { return true; } } } return super.onGenericMotionEvent(event); }
ev.getEventTime(), ev.getAction(), newPoint.x, newPoint.y, ev.getPressure(), ev.getSize(), ev.getMetaState(), ev.getXPrecision(), ev.getYPrecision(), ev.getDeviceId(), ev.getEdgeFlags()); } else { coor, ev.getMetaState(), ev.getButtonState(), ev.getXPrecision(), ev.getYPrecision(), ev.getDeviceId(), ev.getEdgeFlags(), ev.getSource(), ev.getFlags());
MotionEvent evt = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event .getAction(), coords[0], coords[1], event.getPressure(), event.getSize(), event .getMetaState(), event.getXPrecision(), event.getYPrecision(), event.getDeviceId(), event.getEdgeFlags()); return super.dispatchTouchEvent(evt);
MotionEvent evt = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event .getAction(), coords[0], coords[1], event.getPressure(), event.getSize(), event .getMetaState(), event.getXPrecision(), event.getYPrecision(), event.getDeviceId(), event.getEdgeFlags()); return super.dispatchTouchEvent(evt);
MotionEvent evt = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event .getAction(), coords[0], coords[1], event.getPressure(), event.getSize(), event .getMetaState(), event.getXPrecision(), event.getYPrecision(), event.getDeviceId(), event.getEdgeFlags()); return super.dispatchTouchEvent(evt);
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; }
float xPrecision = e.getXPrecision(); float yPrecision = e.getYPrecision(); int deviceId = e.getDeviceId(); int edgeFlags = e.getEdgeFlags(); int source = e.getSource();
if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) { mLastInputDevice = event.getDevice();
if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) { mLastInputDevice = event.getDevice();