diff --git a/api/current.txt b/api/current.txt index a20a23aab338f..5814247a4ed7b 100644 --- a/api/current.txt +++ b/api/current.txt @@ -44356,6 +44356,7 @@ package android.view.inputmethod { method public int getCursorCapsMode(int); method public android.text.Editable getEditable(); method public android.view.inputmethod.ExtractedText getExtractedText(android.view.inputmethod.ExtractedTextRequest, int); + method public android.os.Handler getHandler(); method public java.lang.CharSequence getSelectedText(int); method public java.lang.CharSequence getTextAfterCursor(int, int); method public java.lang.CharSequence getTextBeforeCursor(int, int); @@ -44519,6 +44520,7 @@ package android.view.inputmethod { method public abstract boolean finishComposingText(); method public abstract int getCursorCapsMode(int); method public abstract android.view.inputmethod.ExtractedText getExtractedText(android.view.inputmethod.ExtractedTextRequest, int); + method public abstract android.os.Handler getHandler(); method public abstract java.lang.CharSequence getSelectedText(int); method public abstract java.lang.CharSequence getTextAfterCursor(int, int); method public abstract java.lang.CharSequence getTextBeforeCursor(int, int); @@ -44550,6 +44552,7 @@ package android.view.inputmethod { method public boolean finishComposingText(); method public int getCursorCapsMode(int); method public android.view.inputmethod.ExtractedText getExtractedText(android.view.inputmethod.ExtractedTextRequest, int); + method public android.os.Handler getHandler(); method public java.lang.CharSequence getSelectedText(int); method public java.lang.CharSequence getTextAfterCursor(int, int); method public java.lang.CharSequence getTextBeforeCursor(int, int); diff --git a/api/system-current.txt b/api/system-current.txt index ed2d7545c283b..989c4e903367d 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -47117,6 +47117,7 @@ package android.view.inputmethod { method public int getCursorCapsMode(int); method public android.text.Editable getEditable(); method public android.view.inputmethod.ExtractedText getExtractedText(android.view.inputmethod.ExtractedTextRequest, int); + method public android.os.Handler getHandler(); method public java.lang.CharSequence getSelectedText(int); method public java.lang.CharSequence getTextAfterCursor(int, int); method public java.lang.CharSequence getTextBeforeCursor(int, int); @@ -47280,6 +47281,7 @@ package android.view.inputmethod { method public abstract boolean finishComposingText(); method public abstract int getCursorCapsMode(int); method public abstract android.view.inputmethod.ExtractedText getExtractedText(android.view.inputmethod.ExtractedTextRequest, int); + method public abstract android.os.Handler getHandler(); method public abstract java.lang.CharSequence getSelectedText(int); method public abstract java.lang.CharSequence getTextAfterCursor(int, int); method public abstract java.lang.CharSequence getTextBeforeCursor(int, int); @@ -47311,6 +47313,7 @@ package android.view.inputmethod { method public boolean finishComposingText(); method public int getCursorCapsMode(int); method public android.view.inputmethod.ExtractedText getExtractedText(android.view.inputmethod.ExtractedTextRequest, int); + method public android.os.Handler getHandler(); method public java.lang.CharSequence getSelectedText(int); method public java.lang.CharSequence getTextAfterCursor(int, int); method public java.lang.CharSequence getTextBeforeCursor(int, int); diff --git a/api/test-current.txt b/api/test-current.txt index 8da6ee30c9686..b1dede5436b3c 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -44373,6 +44373,7 @@ package android.view.inputmethod { method public int getCursorCapsMode(int); method public android.text.Editable getEditable(); method public android.view.inputmethod.ExtractedText getExtractedText(android.view.inputmethod.ExtractedTextRequest, int); + method public android.os.Handler getHandler(); method public java.lang.CharSequence getSelectedText(int); method public java.lang.CharSequence getTextAfterCursor(int, int); method public java.lang.CharSequence getTextBeforeCursor(int, int); @@ -44536,6 +44537,7 @@ package android.view.inputmethod { method public abstract boolean finishComposingText(); method public abstract int getCursorCapsMode(int); method public abstract android.view.inputmethod.ExtractedText getExtractedText(android.view.inputmethod.ExtractedTextRequest, int); + method public abstract android.os.Handler getHandler(); method public abstract java.lang.CharSequence getSelectedText(int); method public abstract java.lang.CharSequence getTextAfterCursor(int, int); method public abstract java.lang.CharSequence getTextBeforeCursor(int, int); @@ -44567,6 +44569,7 @@ package android.view.inputmethod { method public boolean finishComposingText(); method public int getCursorCapsMode(int); method public android.view.inputmethod.ExtractedText getExtractedText(android.view.inputmethod.ExtractedTextRequest, int); + method public android.os.Handler getHandler(); method public java.lang.CharSequence getSelectedText(int); method public java.lang.CharSequence getTextAfterCursor(int, int); method public java.lang.CharSequence getTextBeforeCursor(int, int); diff --git a/core/java/android/view/inputmethod/BaseInputConnection.java b/core/java/android/view/inputmethod/BaseInputConnection.java index a10f792b006bf..6a830f87de1f1 100644 --- a/core/java/android/view/inputmethod/BaseInputConnection.java +++ b/core/java/android/view/inputmethod/BaseInputConnection.java @@ -19,6 +19,7 @@ package android.view.inputmethod; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; +import android.os.Handler; import android.os.SystemClock; import android.text.Editable; import android.text.NoCopySpan; @@ -602,6 +603,10 @@ public class BaseInputConnection implements InputConnection { return false; } + public Handler getHandler() { + return null; + } + /** * The default implementation places the given text into the editable, * replacing any existing composing text. The new text is marked as diff --git a/core/java/android/view/inputmethod/InputConnection.java b/core/java/android/view/inputmethod/InputConnection.java index eb773e23fa623..2a9706dc87d54 100644 --- a/core/java/android/view/inputmethod/InputConnection.java +++ b/core/java/android/view/inputmethod/InputConnection.java @@ -17,6 +17,7 @@ package android.view.inputmethod; import android.os.Bundle; +import android.os.Handler; import android.view.KeyCharacterMap; import android.view.KeyEvent; @@ -786,4 +787,15 @@ public interface InputConnection { * {@link InputMethodManager#updateCursorAnchorInfo(android.view.View, CursorAnchorInfo)}. */ public boolean requestCursorUpdates(int cursorUpdateMode); + + /** + * Called by the {@link InputMethodManager} to enable application developers to specify a + * dedicated {@link Handler} on which incoming IPC method calls from input methods will be + * dispatched. + * + *

Note: This does nothing when called from input methods.

+ * + * @return {@code null} to use the default {@link Handler}. + */ + public Handler getHandler(); } diff --git a/core/java/android/view/inputmethod/InputConnectionWrapper.java b/core/java/android/view/inputmethod/InputConnectionWrapper.java index e5ae42299dbac..65c7654c671b4 100644 --- a/core/java/android/view/inputmethod/InputConnectionWrapper.java +++ b/core/java/android/view/inputmethod/InputConnectionWrapper.java @@ -17,6 +17,7 @@ package android.view.inputmethod; import android.os.Bundle; +import android.os.Handler; import android.view.KeyEvent; /** @@ -133,4 +134,8 @@ public class InputConnectionWrapper implements InputConnection { public boolean requestCursorUpdates(int cursorUpdateMode) { return mTarget.requestCursorUpdates(cursorUpdateMode); } + + public Handler getHandler() { + return mTarget.getHandler(); + } } diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 0ed22994585b9..2de9897904d60 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -1215,7 +1215,7 @@ public final class InputMethodManager { if (mCurrentTextBoxAttribute == null) { controlFlags |= CONTROL_START_INITIAL; } - + // Hook 'em up and let 'er rip. mCurrentTextBoxAttribute = tba; mServedConnecting = false; @@ -1230,7 +1230,9 @@ public final class InputMethodManager { mCursorCandEnd = -1; mCursorRect.setEmpty(); mCursorAnchorInfo = null; - servedContext = new ControlledInputConnectionWrapper(vh.getLooper(), ic, this); + final Handler icHandler = ic.getHandler(); + servedContext = new ControlledInputConnectionWrapper( + icHandler != null ? icHandler.getLooper() : vh.getLooper(), ic, this); } else { servedContext = null; } @@ -1238,7 +1240,7 @@ public final class InputMethodManager { mServedInputConnectionWrapper.deactivate(); } mServedInputConnectionWrapper = servedContext; - + try { if (DEBUG) Log.v(TAG, "START INPUT: " + view + " ic=" + ic + " tba=" + tba + " controlFlags=#" diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index b689564cfe589..496f7eee27f79 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -28,6 +28,7 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.TransitionDrawable; import android.os.Bundle; import android.os.Debug; +import android.os.Handler; import android.os.Parcel; import android.os.Parcelable; import android.os.StrictMode; @@ -5930,6 +5931,11 @@ public abstract class AbsListView extends AdapterView implements Te public boolean requestCursorUpdates(int cursorUpdateMode) { return getTarget().requestCursorUpdates(cursorUpdateMode); } + + @Override + public Handler getHandler() { + return getTarget().getHandler(); + } } /** diff --git a/core/java/com/android/internal/view/InputConnectionWrapper.java b/core/java/com/android/internal/view/InputConnectionWrapper.java index 94790c1585597..fc672454a0a08 100644 --- a/core/java/com/android/internal/view/InputConnectionWrapper.java +++ b/core/java/com/android/internal/view/InputConnectionWrapper.java @@ -17,6 +17,7 @@ package com.android.internal.view; import android.os.Bundle; +import android.os.Handler; import android.os.RemoteException; import android.os.SystemClock; import android.util.Log; @@ -454,4 +455,9 @@ public class InputConnectionWrapper implements InputConnection { } return result; } + + public Handler getHandler() { + // Nothing should happen when called from input method. + return null; + } }