diff options
| author | Jeff Brown <jeffbrown@google.com> | 2011-02-19 01:08:02 -0800 |
|---|---|---|
| committer | Jeff Brown <jeffbrown@google.com> | 2011-02-19 05:23:10 -0800 |
| commit | 6f2fba428ca5e77a26d991ad728e346cc47609ee (patch) | |
| tree | 5dd07c24bd9b474ccfbcba4f63e078598fbd2b50 /core/java/android/view/InputDevice.java | |
| parent | b1bdb64d641ac63097619e5ef08d5a25bfdc61bb (diff) | |
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
Diffstat (limited to 'core/java/android/view/InputDevice.java')
| -rwxr-xr-x | core/java/android/view/InputDevice.java | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java index 7abbce6269c5..def1161d05b4 100755 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -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() { |
