diff options
| author | Michael Wright <michaelwr@google.com> | 2013-04-23 03:51:53 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2013-04-23 03:51:53 -0700 |
| commit | 585000515faacc02736f920425ae6c323223ee58 (patch) | |
| tree | 6b2b89811e3be94f0fdb1bb5d652d07faee68236 /core/java/android/view/ViewRootImpl.java | |
| parent | 7bf02d1255e86becb225ba70ca3ea8b2af90c166 (diff) | |
| parent | 5fe6e4c4c9de523fa9e74902473996ce5ee8b298 (diff) | |
am 5fe6e4c4: Merge "Rewrite input handling for native applications" into jb-mr2-dev
* commit '5fe6e4c4c9de523fa9e74902473996ce5ee8b298':
Rewrite input handling for native applications
Diffstat (limited to 'core/java/android/view/ViewRootImpl.java')
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index f03c07751d19..7ecb52ed0c52 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -597,12 +597,11 @@ public final class ViewRootImpl implements ViewParent, } if (mInputChannel != null) { if (mInputQueueCallback != null) { - mInputQueue = new InputQueue(mInputChannel); + mInputQueue = new InputQueue(); mInputQueueCallback.onInputQueueCreated(mInputQueue); - } else { - mInputEventReceiver = new WindowInputEventReceiver(mInputChannel, - Looper.myLooper()); } + mInputEventReceiver = new WindowInputEventReceiver(mInputChannel, + Looper.myLooper()); } view.assignParent(this); @@ -2822,9 +2821,11 @@ public final class ViewRootImpl implements ViewParent, if (mInputQueueCallback != null && mInputQueue != null) { mInputQueueCallback.onInputQueueDestroyed(mInputQueue); + mInputQueue.dispose(); mInputQueueCallback = null; mInputQueue = null; - } else if (mInputEventReceiver != null) { + } + if (mInputEventReceiver != null) { mInputEventReceiver.dispose(); mInputEventReceiver = null; } @@ -3347,6 +3348,15 @@ public final class ViewRootImpl implements ViewParent, if ((q.mFlags & QueuedInputEvent.FLAG_FINISHED) != 0) { forward(q); } else if (mView == null || !mAdded) { + Slog.w(TAG, "Dropping event due to root view being removed: " + q.mEvent); + finish(q, false); + } else if (!mAttachInfo.mHasWindowFocus && + !q.mEvent.isFromSource(InputDevice.SOURCE_CLASS_POINTER) && + !isTerminalInputEvent(q.mEvent)) { + // If this is a focused event and the window doesn't currently have input focus, + // then drop this event. This could be an event that came back from the previous + // stage but the window has lost focus in the meantime. + Slog.w(TAG, "Dropping event due to no window focus: " + q.mEvent); finish(q, false); } else { apply(q, onProcess(q)); @@ -3547,15 +3557,30 @@ public final class ViewRootImpl implements ViewParent, * Delivers pre-ime input events to a native activity. * Does not support pointer events. */ - final class NativePreImeInputStage extends AsyncInputStage { + final class NativePreImeInputStage extends AsyncInputStage + implements InputQueue.FinishedInputEventCallback { public NativePreImeInputStage(InputStage next, String traceCounter) { super(next, traceCounter); } @Override protected int onProcess(QueuedInputEvent q) { + if (mInputQueue != null && q.mEvent instanceof KeyEvent) { + mInputQueue.sendInputEvent(q.mEvent, q, true, this); + return DEFER; + } return FORWARD; } + + @Override + public void onFinishedInputEvent(Object token, boolean handled) { + QueuedInputEvent q = (QueuedInputEvent)token; + if (handled) { + finish(q, true); + return; + } + forward(q); + } } /** @@ -3621,16 +3646,6 @@ public final class ViewRootImpl implements ViewParent, finish(q, true); return; } - - // If the window doesn't currently have input focus, then drop - // this event. This could be an event that came back from the - // IME dispatch but the window has lost focus in the meantime. - if (!mAttachInfo.mHasWindowFocus && !isTerminalInputEvent(q.mEvent)) { - Slog.w(TAG, "Dropping event due to no window focus: " + q.mEvent); - finish(q, false); - return; - } - forward(q); } } @@ -3702,15 +3717,30 @@ public final class ViewRootImpl implements ViewParent, /** * Delivers post-ime input events to a native activity. */ - final class NativePostImeInputStage extends AsyncInputStage { + final class NativePostImeInputStage extends AsyncInputStage + implements InputQueue.FinishedInputEventCallback { public NativePostImeInputStage(InputStage next, String traceCounter) { super(next, traceCounter); } @Override protected int onProcess(QueuedInputEvent q) { + if (mInputQueue != null) { + mInputQueue.sendInputEvent(q.mEvent, q, false, this); + return DEFER; + } return FORWARD; } + + @Override + public void onFinishedInputEvent(Object token, boolean handled) { + QueuedInputEvent q = (QueuedInputEvent)token; + if (handled) { + finish(q, true); + return; + } + forward(q); + } } /** |
