diff options
Diffstat (limited to 'core/java/android')
5 files changed, 68 insertions, 5 deletions
diff --git a/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java b/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java index df8cf9a8164f..e10f2184508b 100644 --- a/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java +++ b/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java @@ -47,6 +47,7 @@ class IInputMethodSessionWrapper extends IInputMethodSession.Stub private static final int DO_APP_PRIVATE_COMMAND = 100; private static final int DO_TOGGLE_SOFT_INPUT = 105; private static final int DO_FINISH_SESSION = 110; + private static final int DO_VIEW_CLICKED = 115; HandlerCaller mCaller; InputMethodSession mInputMethodSession; @@ -133,6 +134,10 @@ class IInputMethodSessionWrapper extends IInputMethodSession.Stub mInputMethodSession = null; return; } + case DO_VIEW_CLICKED: { + mInputMethodSession.viewClicked(msg.arg1 == 1); + return; + } } Log.w(TAG, "Unhandled message code: " + msg.what); } @@ -167,7 +172,11 @@ class IInputMethodSessionWrapper extends IInputMethodSession.Stub oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd)); } - + + public void viewClicked(boolean focusChanged) { + mCaller.executeOrSendMessage(mCaller.obtainMessageI(DO_VIEW_CLICKED, focusChanged ? 1 : 0)); + } + public void updateCursor(Rect newCursor) { mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_UPDATE_CURSOR, newCursor)); diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index feb246ed7125..9481a880fb08 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -488,7 +488,15 @@ public class InputMethodService extends AbstractInputMethodService { InputMethodService.this.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd, candidatesStart, candidatesEnd); } - + + @Override + public void viewClicked(boolean focusChanged) { + if (!isEnabled()) { + return; + } + InputMethodService.this.onViewClicked(focusChanged); + } + /** * Call {@link InputMethodService#onUpdateCursor * InputMethodService.onUpdateCursor()}. @@ -1609,6 +1617,16 @@ public class InputMethodService extends AbstractInputMethodService { } /** + * Called when the user tapped or clicked a text view. + * IMEs can't rely on this method being called because this was not part of the original IME + * protocol, so applications with custom text editing written before this method appeared will + * not call to inform the IME of this interaction. + * @param focusChanged true if the user changed the focused view by this click. + */ + public void onViewClicked(boolean focusChanged) { + } + + /** * Called when the application has reported a new location of its text * cursor. This is only called if explicitly requested by the input method. * The default implementation does nothing. diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 47f5e4c4f9cb..a1a7281c7710 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -1126,7 +1126,7 @@ public final class InputMethodManager { if (mServedView == mNextServedView && !mNextServedNeedsStart) { return; } - + InputConnection ic = null; synchronized (mH) { if (mServedView == mNextServedView && !mNextServedNeedsStart) { @@ -1242,6 +1242,27 @@ public final class InputMethodManager { } /** + * Notify the event when the user tapped or clicked the text view. + */ + public void viewClicked(View view) { + final boolean focusChanged = mServedView != mNextServedView; + checkFocus(); + synchronized (mH) { + if ((mServedView != view && (mServedView == null + || !mServedView.checkInputConnectionProxy(view))) + || mCurrentTextBoxAttribute == null || mCurMethod == null) { + return; + } + try { + if (DEBUG) Log.v(TAG, "onViewClicked: " + focusChanged); + mCurMethod.viewClicked(focusChanged); + } catch (RemoteException e) { + Log.w(TAG, "IME died: " + mCurId, e); + } + } + } + + /** * Returns true if the current input method wants to watch the location * of the input editor's cursor in its window. */ diff --git a/core/java/android/view/inputmethod/InputMethodSession.java b/core/java/android/view/inputmethod/InputMethodSession.java index bb03afad56ae..ea6f5ee4a976 100644 --- a/core/java/android/view/inputmethod/InputMethodSession.java +++ b/core/java/android/view/inputmethod/InputMethodSession.java @@ -63,6 +63,15 @@ public interface InputMethodSession { int candidatesStart, int candidatesEnd); /** + * This method is called when the user tapped a text view. + * IMEs can't rely on this method being called because this was not part of the original IME + * protocol, so applications with custom text editing written before this method appeared will + * not call to inform the IME of this interaction. + * @param focusChanged true if the user changed the focused view by this click. + */ + public void viewClicked(boolean focusChanged); + + /** * This method is called when cursor location of the target input field * has changed within its window. This is not normally called, but will * only be reported if requested by the input method. diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 85e7eecfdd82..2f9bd69ec8e4 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -4948,7 +4948,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (mMovement != null && mText instanceof Editable && mLayout != null && onCheckIsTextEditor()) { InputMethodManager imm = InputMethodManager.peekInstance(); - if (imm != null) imm.showSoftInput(this, 0); + if (imm != null) { + imm.viewClicked(this); + imm.showSoftInput(this, 0); + } } } } @@ -7398,8 +7401,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if ((isTextEditable() || mTextIsSelectable) && touchIsFinished) { // Show the IME, except when selecting in read-only text. + final InputMethodManager imm = InputMethodManager.peekInstance(); + if (imm != null) { + imm.viewClicked(this); + } if (!mTextIsSelectable) { - final InputMethodManager imm = InputMethodManager.peekInstance(); handled |= imm != null && imm.showSoftInput(this, 0); } |
