Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f2fba42 authored by Jeff Brown's avatar Jeff Brown
Browse files

Add new axes for joysticks and mouse wheels.

Added API on InputDevice to query the set of axes available.
Added API on KeyEvent and MotionEvent to convert keycodes and axes
to symbolic name strings for diagnostic purposes.
Added API on KeyEvent to query if a given key code is a gamepad button.
Added a new "axis" element to key layout files to specify the
mapping between raw absolute axis values and motion axis ids.
Expanded the axis bitfield to 64bits to allow for future growth.
Modified the Makefile for keyboard prebuilts to run the keymap
validation tool during the build.
Added layouts for two game controllers.
Added default actions for game pad button keys.
Added more tests.
Fixed a bunch of bugs.

Change-Id: I73f9166c3b3c5bcf4970845b58088ad467525525
parent b1bdb64d
Loading
Loading
Loading
Loading
+362 −0
Original line number Diff line number Diff line
@@ -210656,6 +210656,17 @@
 visibility="public"
>
</method>
<method name="getMotionAxes"
 return="int[]"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getMotionRange"
 return="android.view.InputDevice.MotionRange"
 abstract="false"
@@ -212226,6 +212237,19 @@
 visibility="public"
>
</method>
<method name="isGamepadButton"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="keyCode" type="int">
</parameter>
</method>
<method name="isLongPress"
 return="boolean"
 abstract="false"
@@ -212338,6 +212362,32 @@
 visibility="public"
>
</method>
<method name="keyCodeFromString"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="symbolicName" type="java.lang.String">
</parameter>
</method>
<method name="keyCodeToString"
 return="java.lang.String"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="keyCode" type="int">
</parameter>
</method>
<method name="metaStateHasModifiers"
 return="boolean"
 abstract="false"
@@ -216602,6 +216652,32 @@
<parameter name="metaState" type="int">
</parameter>
</method>
<method name="axisFromString"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="symbolicName" type="java.lang.String">
</parameter>
</method>
<method name="axisToString"
 return="java.lang.String"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="axis" type="int">
</parameter>
</method>
<method name="findPointerIndex"
 return="int"
 abstract="false"
@@ -217841,6 +217917,226 @@
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_1"
 type="int"
 transient="false"
 volatile="false"
 value="32"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_10"
 type="int"
 transient="false"
 volatile="false"
 value="41"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_11"
 type="int"
 transient="false"
 volatile="false"
 value="42"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_12"
 type="int"
 transient="false"
 volatile="false"
 value="43"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_13"
 type="int"
 transient="false"
 volatile="false"
 value="44"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_14"
 type="int"
 transient="false"
 volatile="false"
 value="45"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_15"
 type="int"
 transient="false"
 volatile="false"
 value="46"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_16"
 type="int"
 transient="false"
 volatile="false"
 value="47"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_2"
 type="int"
 transient="false"
 volatile="false"
 value="33"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_3"
 type="int"
 transient="false"
 volatile="false"
 value="34"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_4"
 type="int"
 transient="false"
 volatile="false"
 value="35"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_5"
 type="int"
 transient="false"
 volatile="false"
 value="36"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_6"
 type="int"
 transient="false"
 volatile="false"
 value="37"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_7"
 type="int"
 transient="false"
 volatile="false"
 value="38"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_8"
 type="int"
 transient="false"
 volatile="false"
 value="39"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_GENERIC_9"
 type="int"
 transient="false"
 volatile="false"
 value="40"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_HAT_X"
 type="int"
 transient="false"
 volatile="false"
 value="15"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_HAT_Y"
 type="int"
 transient="false"
 volatile="false"
 value="16"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_HSCROLL"
 type="int"
 transient="false"
 volatile="false"
 value="10"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_LTRIGGER"
 type="int"
 transient="false"
 volatile="false"
 value="17"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_ORIENTATION"
 type="int"
 transient="false"
@@ -217863,6 +218159,50 @@
 visibility="public"
>
</field>
<field name="AXIS_RTRIGGER"
 type="int"
 transient="false"
 volatile="false"
 value="18"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_RX"
 type="int"
 transient="false"
 volatile="false"
 value="12"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_RY"
 type="int"
 transient="false"
 volatile="false"
 value="13"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_RZ"
 type="int"
 transient="false"
 volatile="false"
 value="14"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_SIZE"
 type="int"
 transient="false"
@@ -217918,6 +218258,17 @@
 visibility="public"
>
</field>
<field name="AXIS_VSCROLL"
 type="int"
 transient="false"
 volatile="false"
 value="9"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="AXIS_X"
 type="int"
 transient="false"
@@ -217940,6 +218291,17 @@
 visibility="public"
>
</field>
<field name="AXIS_Z"
 type="int"
 transient="false"
 volatile="false"
 value="11"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="CREATOR"
 type="android.os.Parcelable.Creator"
 transient="false"
+31 −7
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public final class InputDevice implements Parcelable {
    private int mKeyboardType;

    private final SparseArray<MotionRange> mMotionRanges = new SparseArray<MotionRange>();
    private int[] mMotionAxes;

    /**
     * A mask for input source classes.
@@ -359,12 +360,31 @@ public final class InputDevice implements Parcelable {
     *
     * @see MotionEvent#AXIS_X
     * @see MotionEvent#AXIS_Y
     * @see #getSupportedAxes()
     */
    public MotionRange getMotionRange(int axis) {
        return mMotionRanges.get(axis);
    }

    // Called by native code.
    /**
     * Gets the axis ids of all motion axes supported by this device.
     * @return The axis ids of all motion axes supported by this device.
     *
     * @see #getMotionRange(int)
     */
    public int[] getMotionAxes() {
        synchronized (this) {
            if (mMotionAxes == null) {
                final int count = mMotionRanges.size();
                mMotionAxes = new int[count];
                for (int i = 0; i < count; i++) {
                    mMotionAxes[i] = mMotionRanges.keyAt(i);
                }
            }
            return mMotionAxes;
        }
    }

    private void addMotionRange(int axis, float min, float max, float flat, float fuzz) {
        mMotionRanges.append(axis, new MotionRange(min, max, flat, fuzz));
    }
@@ -388,33 +408,35 @@ public final class InputDevice implements Parcelable {
        }

        /**
         * Gets the minimum value for the axis.
         * @return The (inclusive) minimum value.
         * Gets the inclusive minimum value for the axis.
         * @return The inclusive minimum value.
         */
        public float getMin() {
            return mMin;
        }

        /**
         * Gets the maximum value for the axis.
         * @return The (inclusive) maximum value.
         * Gets the inclusive maximum value for the axis.
         * @return The inclusive maximum value.
         */
        public float getMax() {
            return mMax;
        }

        /**
         * Gets the range of the axis (difference between maximum and minimum plus one).
         * Gets the range of the axis (difference between maximum and minimum).
         * @return The range of values.
         */
        public float getRange() {
            return mMax - mMin + 1;
            return mMax - mMin;
        }

        /**
         * Gets the extent of the center flat position with respect to this axis.
         * <p>
         * For example, a flat value of 8 means that the center position is between -8 and +8.
         * This value is mainly useful for calibrating self-centering devices.
         * </p>
         * @return The extent of the center flat position.
         */
        public float getFlat() {
@@ -423,8 +445,10 @@ public final class InputDevice implements Parcelable {

        /**
         * Gets the error tolerance for input device measurements with respect to this axis.
         * <p>
         * For example, a value of 2 indicates that the measured value may be up to +/- 2 units
         * away from the actual value due to noise and device sensitivity limitations.
         * </p>
         * @return The error tolerance.
         */
        public float getFuzz() {
+267 −230

File changed.

Preview size limit exceeded, changes collapsed.

+557 −96

File changed.

Preview size limit exceeded, changes collapsed.

+10 −3
Original line number Diff line number Diff line
@@ -2496,7 +2496,6 @@ public final class ViewRoot extends Handler implements ViewParent,

        // Deliver the event to the view.
        if (mView.dispatchGenericMotionEvent(event)) {
            ensureTouchMode(false);
            if (isJoystick) {
                updateJoystickDirection(event, false);
            }
@@ -2525,8 +2524,16 @@ public final class ViewRoot extends Handler implements ViewParent,
        final int metaState = event.getMetaState();
        final int deviceId = event.getDeviceId();
        final int source = event.getSource();
        final int xDirection = joystickAxisValueToDirection(event.getX());
        final int yDirection = joystickAxisValueToDirection(event.getY());

        int xDirection = joystickAxisValueToDirection(event.getAxisValue(MotionEvent.AXIS_HAT_X));
        if (xDirection == 0) {
            xDirection = joystickAxisValueToDirection(event.getX());
        }

        int yDirection = joystickAxisValueToDirection(event.getAxisValue(MotionEvent.AXIS_HAT_Y));
        if (yDirection == 0) {
            yDirection = joystickAxisValueToDirection(event.getY());
        }

        if (xDirection != mLastJoystickXDirection) {
            if (mLastJoystickXKeyCode != 0) {
Loading