diff options
author | Jeff Brown <jeffbrown@google.com> | 2011-03-08 15:13:06 -0800 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2011-03-09 18:30:28 -0800 |
commit | efd3266b719eed5f1b217021c0a9e76e4b274b06 (patch) | |
tree | f76032f2a0bdfdc9910860063455116a9c792687 /core | |
parent | 9e8e40cb5f8aeb0702002eee60d1ce394bf699ee (diff) | |
download | frameworks_base-efd3266b719eed5f1b217021c0a9e76e4b274b06.zip frameworks_base-efd3266b719eed5f1b217021c0a9e76e4b274b06.tar.gz frameworks_base-efd3266b719eed5f1b217021c0a9e76e4b274b06.tar.bz2 |
Input improvements and bug fixes.
Associate each motion axis with the source from which it comes.
It is possible for multiple sources of the same device to define
the same axis. This fixes new API that was introduced in MR1.
(Bug: 4066146)
Fixed a bug that might cause a segfault when using a trackball.
Only fade out the mouse pointer when touching the touch screen,
ignore other touch pads.
Changed the plural "sources" to "source" in several places in
the InputReader where we intend to refer to a particular source
rather than to a combination of sources.
Improved the batching code to support batching events from different
sources of the same device in parallel. (Bug: 3391564)
Change-Id: I0189e18e464338f126f7bf94370b928e1b1695f2
Diffstat (limited to 'core')
-rwxr-xr-x | core/java/android/view/InputDevice.java | 114 |
1 files changed, 83 insertions, 31 deletions
diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java index def1161..98d4eb9 100755 --- a/core/java/android/view/InputDevice.java +++ b/core/java/android/view/InputDevice.java @@ -20,7 +20,9 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.RemoteException; import android.os.ServiceManager; -import android.util.SparseArray; + +import java.util.ArrayList; +import java.util.List; /** * Describes the capabilities of a particular input device. @@ -43,8 +45,7 @@ public final class InputDevice implements Parcelable { private int mSources; private int mKeyboardType; - private final SparseArray<MotionRange> mMotionRanges = new SparseArray<MotionRange>(); - private int[] mMotionAxes; + private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>(); /** * A mask for input source classes. @@ -354,6 +355,11 @@ public final class InputDevice implements Parcelable { /** * Gets information about the range of values for a particular {@link MotionEvent} axis. + * If the device supports multiple sources, the same axis may have different meanings + * for each source. Returns information about the first axis found for any source. + * To obtain information about the axis for a specific source, use + * {@link #getMotionRange(int, int)}. + * * @param axis The axis constant. * @return The range of values, or null if the requested axis is not * supported by the device. @@ -363,30 +369,55 @@ public final class InputDevice implements Parcelable { * @see #getSupportedAxes() */ public MotionRange getMotionRange(int axis) { - return mMotionRanges.get(axis); + final int numRanges = mMotionRanges.size(); + for (int i = 0; i < numRanges; i++) { + final MotionRange range = mMotionRanges.get(i); + if (range.mAxis == axis) { + return range; + } + } + return null; } /** - * Gets the axis ids of all motion axes supported by this device. - * @return The axis ids of all motion axes supported by this device. + * Gets information about the range of values for a particular {@link MotionEvent} axis + * used by a particular source on the device. + * If the device supports multiple sources, the same axis may have different meanings + * for each source. + * + * @param axis The axis constant. + * @param source The source for which to return information. + * @return The range of values, or null if the requested axis is not + * supported by the 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); - } + * @see MotionEvent#AXIS_X + * @see MotionEvent#AXIS_Y + * @see #getSupportedAxes() + */ + public MotionRange getMotionRange(int axis, int source) { + final int numRanges = mMotionRanges.size(); + for (int i = 0; i < numRanges; i++) { + final MotionRange range = mMotionRanges.get(i); + if (range.mAxis == axis && range.mSource == source) { + return range; } - return mMotionAxes; } + return null; } - private void addMotionRange(int axis, float min, float max, float flat, float fuzz) { - mMotionRanges.append(axis, new MotionRange(min, max, flat, fuzz)); + /** + * Gets the ranges for all axes supported by the device. + * @return The motion ranges for the device. + * + * @see #getMotionRange(int, int) + */ + public List<MotionRange> getMotionRanges() { + return mMotionRanges; + } + + private void addMotionRange(int axis, int source, + float min, float max, float flat, float fuzz) { + mMotionRanges.add(new MotionRange(axis, source, min, max, flat, fuzz)); } /** @@ -395,12 +426,16 @@ public final class InputDevice implements Parcelable { * @see InputDevice#getMotionRange(int) */ public static final class MotionRange { + private int mAxis; + private int mSource; private float mMin; private float mMax; private float mFlat; private float mFuzz; - private MotionRange(float min, float max, float flat, float fuzz) { + private MotionRange(int axis, int source, float min, float max, float flat, float fuzz) { + mAxis = axis; + mSource = source; mMin = min; mMax = max; mFlat = flat; @@ -408,6 +443,22 @@ public final class InputDevice implements Parcelable { } /** + * Gets the axis id. + * @return The axis id. + */ + public int getAxis() { + return mAxis; + } + + /** + * Gets the source for which the axis is defined. + * @return The source. + */ + public int getSource() { + return mSource; + } + + /** * Gets the inclusive minimum value for the axis. * @return The inclusive minimum value. */ @@ -480,7 +531,8 @@ public final class InputDevice implements Parcelable { if (axis < 0) { break; } - addMotionRange(axis, in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat()); + addMotionRange(axis, in.readInt(), + in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat()); } } @@ -491,11 +543,11 @@ public final class InputDevice implements Parcelable { out.writeInt(mSources); out.writeInt(mKeyboardType); - final int numAxes = mMotionRanges.size(); - for (int i = 0; i < numAxes; i++) { - int axis = mMotionRanges.keyAt(i); - MotionRange range = mMotionRanges.valueAt(i); - out.writeInt(axis); + final int numRanges = mMotionRanges.size(); + for (int i = 0; i < numRanges; i++) { + MotionRange range = mMotionRanges.get(i); + out.writeInt(range.mAxis); + out.writeInt(range.mSource); out.writeFloat(range.mMin); out.writeFloat(range.mMax); out.writeFloat(range.mFlat); @@ -528,7 +580,7 @@ public final class InputDevice implements Parcelable { } description.append("\n"); - description.append(" Sources: ").append(Integer.toHexString(mSources)).append(" ("); + description.append(" Sources: 0x").append(Integer.toHexString(mSources)).append(" ("); appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard"); appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad"); appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHSCREEN, "touchscreen"); @@ -541,10 +593,10 @@ public final class InputDevice implements Parcelable { final int numAxes = mMotionRanges.size(); for (int i = 0; i < numAxes; i++) { - int axis = mMotionRanges.keyAt(i); - MotionRange range = mMotionRanges.valueAt(i); - description.append(" ").append(MotionEvent.axisToString(axis)); - description.append(": min=").append(range.mMin); + MotionRange range = mMotionRanges.get(i); + description.append(" ").append(MotionEvent.axisToString(range.mAxis)); + description.append(": source=0x").append(Integer.toHexString(range.mSource)); + description.append(" min=").append(range.mMin); description.append(" max=").append(range.mMax); description.append(" flat=").append(range.mFlat); description.append(" fuzz=").append(range.mFuzz); |