diff options
| author | 2009-08-06 12:43:01 -0700 | |
|---|---|---|
| committer | 2009-08-06 12:43:01 -0700 | |
| commit | 1e8dfc73fba88766ee3c25ae7b3bb1850319b11d (patch) | |
| tree | db4f22b8fc813077f245711ad1c799542eab1ce5 | |
| parent | 838ffacd2ecf4fbefd8d5a083d91f2949eb47faa (diff) | |
Fix crash when MotionEvent is initialized with more than 2 fingers, and bump
its initial size to allow for up to 5 fingers.
| -rw-r--r-- | core/java/android/view/MotionEvent.java | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index a109db5ce16c..e8bfa6ad40dd 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -185,7 +185,12 @@ public final class MotionEvent implements Parcelable { */ static public final int NUM_SAMPLE_DATA = 4; - static private final int BASE_AVAIL_POINTERS = 2; + /** + * Number of possible pointers. + * @hide + */ + static public final int BASE_AVAIL_POINTERS = 5; + static private final int BASE_AVAIL_SAMPLES = 8; static private final int MAX_RECYCLED = 10; @@ -290,8 +295,19 @@ public final class MotionEvent implements Parcelable { ev.mNumPointers = pointers; ev.mNumSamples = 1; - System.arraycopy(inPointerIds, 0, ev.mPointerIdentifiers, 0, pointers); - System.arraycopy(inData, 0, ev.mDataSamples, 0, pointers * NUM_SAMPLE_DATA); + int[] pointerIdentifiers = ev.mPointerIdentifiers; + if (pointerIdentifiers.length < pointers) { + ev.mPointerIdentifiers = pointerIdentifiers = new int[pointers]; + } + System.arraycopy(inPointerIds, 0, pointerIdentifiers, 0, pointers); + + final int ND = pointers * NUM_SAMPLE_DATA; + float[] dataSamples = ev.mDataSamples; + if (dataSamples.length < ND) { + ev.mDataSamples = dataSamples = new float[ND]; + } + System.arraycopy(inData, 0, dataSamples, 0, ND); + ev.mTimeSamples[0] = eventTime; if (DEBUG_POINTERS) { |