diff options
| author | 2011-12-03 17:35:19 -0800 | |
|---|---|---|
| committer | 2011-12-03 17:35:19 -0800 | |
| commit | f3a0a60917af4e11122fb8f10ebae08bfb395e81 (patch) | |
| tree | 696ed277fa6c93aa553002d960513b103a4347f7 | |
| parent | f1195be710e72b3f8016c149b104d732dd20a531 (diff) | |
| parent | 92cc2d8dc35f2bdd1bb95ab24787066371064899 (diff) | |
Merge "Remove type tests when recycling input events."
| -rwxr-xr-x | core/java/android/view/InputEvent.java | 15 | ||||
| -rw-r--r-- | core/java/android/view/InputEventReceiver.java | 12 | ||||
| -rwxr-xr-x | core/java/android/view/KeyEvent.java | 7 | ||||
| -rw-r--r-- | core/java/android/view/MotionEvent.java | 1 | ||||
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 8 |
5 files changed, 26 insertions, 17 deletions
diff --git a/core/java/android/view/InputEvent.java b/core/java/android/view/InputEvent.java index c42bbdcadf04..56024369d823 100755 --- a/core/java/android/view/InputEvent.java +++ b/core/java/android/view/InputEvent.java @@ -112,6 +112,21 @@ public abstract class InputEvent implements Parcelable { } /** + * Conditionally recycled the event if it is appropriate to do so after + * dispatching the event to an application. + * + * If the event is a {@link MotionEvent} then it is recycled. + * + * If the event is a {@link KeyEvent} then it is NOT recycled, because applications + * expect key events to be immutable so once the event has been dispatched to + * the application we can no longer recycle it. + * @hide + */ + public void recycleIfNeededAfterDispatch() { + recycle(); + } + + /** * Reinitializes the event on reuse (after recycling). * @hide */ diff --git a/core/java/android/view/InputEventReceiver.java b/core/java/android/view/InputEventReceiver.java index abb52810c446..764d8dcaba2a 100644 --- a/core/java/android/view/InputEventReceiver.java +++ b/core/java/android/view/InputEventReceiver.java @@ -124,7 +124,7 @@ public abstract class InputEventReceiver { nativeFinishInputEvent(mReceiverPtr, handled); } } - recycleInputEvent(event); + event.recycleIfNeededAfterDispatch(); } // Called from native code. @@ -134,16 +134,6 @@ public abstract class InputEventReceiver { onInputEvent(event); } - private static void recycleInputEvent(InputEvent event) { - if (event instanceof MotionEvent) { - // Event though key events are also recyclable, we only recycle motion events. - // Historically, key events were not recyclable and applications expect - // them to be immutable. We only ever recycle key events behind the - // scenes where an application never sees them (so, not here). - event.recycle(); - } - } - public static interface Factory { public InputEventReceiver createInputEventReceiver( InputChannel inputChannel, Looper looper); diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java index 9a46aab76922..104ed6ac6829 100755 --- a/core/java/android/view/KeyEvent.java +++ b/core/java/android/view/KeyEvent.java @@ -1596,6 +1596,7 @@ public class KeyEvent extends InputEvent implements Parcelable { * * @hide */ + @Override public final void recycle() { super.recycle(); mCharacters = null; @@ -1609,6 +1610,12 @@ public class KeyEvent extends InputEvent implements Parcelable { } } + /** @hide */ + @Override + public final void recycleIfNeededAfterDispatch() { + // Do nothing. + } + /** * Create a new key event that is the same as the given one, but whose * event time and repeat count are replaced with the given value. diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index e49193e2c69c..92e8f4e14b88 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -1642,6 +1642,7 @@ public final class MotionEvent extends InputEvent implements Parcelable { * Recycle the MotionEvent, to be re-used by a later caller. After calling * this function you must not ever touch the event again. */ + @Override public final void recycle() { super.recycle(); diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index f23c3127e3a9..95c473cde284 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -3848,12 +3848,8 @@ public final class ViewRootImpl extends Handler implements ViewParent, if (q.mReceiver != null) { q.mReceiver.finishInputEvent(q.mEvent, handled); - } else if (q.mEvent instanceof MotionEvent) { - // Event though key events are also recyclable, we only recycle motion events. - // Historically, key events were not recyclable and applications expect - // them to be immutable. We only ever recycle key events behind the - // scenes where an application never sees them (so, not here). - q.mEvent.recycle(); + } else { + q.mEvent.recycleIfNeededAfterDispatch(); } recycleQueuedInputEvent(q); |