Java Code Examples for android.view.InputDevice.MotionRange#getAxis()

The following examples show how to use android.view.InputDevice.MotionRange#getAxis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AxisMappingDialogPreference.java    From crazyflie-android-client with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: AndroidJoystickJoyInput14.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected JoystickAxis addAxis(MotionRange motionRange) {

            String name = MotionEvent.axisToString(motionRange.getAxis());

            String original = MotionEvent.axisToString(motionRange.getAxis());
            if (motionRange.getAxis() == MotionEvent.AXIS_X) {
                original = JoystickAxis.X_AXIS;
            } else if (motionRange.getAxis() == MotionEvent.AXIS_Y) {
                original = JoystickAxis.Y_AXIS;
            } else if (motionRange.getAxis() == MotionEvent.AXIS_Z) {
                original = JoystickAxis.Z_AXIS;
            } else if (motionRange.getAxis() == MotionEvent.AXIS_RZ) {
                original = JoystickAxis.Z_ROTATION;
            } else if (motionRange.getAxis() == MotionEvent.AXIS_HAT_X) {
                original = JoystickAxis.POV_X;
            } else if (motionRange.getAxis() == MotionEvent.AXIS_HAT_Y) {
                original = JoystickAxis.POV_Y;
            }
            String logicalId = JoystickCompatibilityMappings.remapComponent( getName(), original );
            if( logicalId == null ? original != null : !logicalId.equals(original) ) {
                logger.log(Level.FINE, "Remapped: {0} to: {1}",
                        new Object[]{original, logicalId});
            }

            JoystickAxis axis = new DefaultJoystickAxis(getInputManager(),
                                                this,
                                                getAxisCount(),
                                                name,
                                                logicalId,
                                                true,
                                                true,
                                                motionRange.getFlat());

            if (motionRange.getAxis() == MotionEvent.AXIS_X) {
                xAxis = axis;
            }
            if (motionRange.getAxis() == MotionEvent.AXIS_Y) {
                yAxis = axis;
            }
            if (motionRange.getAxis() == MotionEvent.AXIS_HAT_X) {
                povX = axis;
            }
            if (motionRange.getAxis() == MotionEvent.AXIS_HAT_Y) {
                povY = axis;
            }

            addAxis(axis);
            axisIndex.put(motionRange.getAxis(), axis);
            return axis;
        }