@Override public boolean onGenericMotion(View v, MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE) { List<MotionRange> motionRanges = event.getDevice().getMotionRanges(); for(MotionRange mr : motionRanges){ int axis = mr.getAxis(); if(event.getAxisValue(axis) > 0.5 || event.getAxisValue(axis) < -0.5){ Log.i(TAG, "Axis found: " + MotionEvent.axisToString(axis)); this.mAxisName = MotionEvent.axisToString(axis); mValueTextView.setText(mAxisName); } } }else{ Log.i(TAG, "Not a joystick event."); } return true; }
mLastInputDevice = event.getDevice();
mLastInputDevice = event.getDevice();
InputDevice mInputDevice = event.getDevice();
public void dealWithMotionEvent(MotionEvent event){ //Log.i(LOG_TAG, "Input device: " + event.getDevice().getName()); /*if axis has a range of 1 (0 -> 1) instead of 2 (-1 -> 0) do not invert axis value, this is necessary for analog R1 (Brake) or analog R2 (Gas) shoulder buttons on PS3 controller*/ if (event != null) { if (event.getDevice() != null) { InputDevice device = event.getDevice(); mRightAnalogYAxisInvertFactor = (device.getMotionRange(mRightAnalogYAxis).getRange() == 1) ? 1 : -1; mLeftAnalogYAxisInvertFactor = (device.getMotionRange(mLeftAnalogYAxis).getRange() == 1) ? 1 : -1; } else { Log.w(LOG_TAG, "event.getDevice() == null! => event.getClass(): " + event.getClass()); } // default axis are set to work with PS3 controller mControls.setRightAnalogX((float) event.getAxisValue(mRightAnalogXAxis)); mControls.setRightAnalogY((float) (event.getAxisValue(mRightAnalogYAxis)) * mRightAnalogYAxisInvertFactor); mControls.setLeftAnalogX((float) event.getAxisValue(mLeftAnalogXAxis)); mControls.setLeftAnalogY((float) (event.getAxisValue(mLeftAnalogYAxis)) * mLeftAnalogYAxisInvertFactor); mSplit_axis_yaw_right = (float) event.getAxisValue(mSplitAxisYawRightAxis); mSplit_axis_yaw_left = (float) event.getAxisValue(mSplitAxisYawLeftAxis); } }
return false; InputDevice input = event.getDevice();
mInputDevice = event.getDevice();
public static boolean processJoystickInput(MotionEvent event, int historyPos) { InputDevice mInputDevice = event.getDevice();
return true; InputDevice input = event.getDevice(); List<InputDevice.MotionRange> motions = input.getMotionRanges();