diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-09-18 22:25:52 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-09-18 22:25:52 +0000 |
| commit | 173222142f788988fcaa46a7959752e84cd99759 (patch) | |
| tree | a7467db04630ac9ca614b5bdb7b67eeb8646ea1d /core/java/android | |
| parent | 5ad852100873e1e3223120366b481538f0bcad47 (diff) | |
| parent | 484d4afc92cc1a1d58b601f7ad14d63781231b55 (diff) | |
Merge "Always use Context.getSystemService() to get IMM"
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/text/style/SuggestionSpan.java | 2 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 10 | ||||
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 8 | ||||
| -rw-r--r-- | core/java/android/view/WindowManagerGlobal.java | 2 | ||||
| -rw-r--r-- | core/java/android/view/inputmethod/InputMethodManager.java | 6 | ||||
| -rw-r--r-- | core/java/android/widget/AutoCompleteTextView.java | 4 | ||||
| -rw-r--r-- | core/java/android/widget/DatePickerSpinnerDelegate.java | 2 | ||||
| -rw-r--r-- | core/java/android/widget/Editor.java | 16 | ||||
| -rw-r--r-- | core/java/android/widget/NumberPicker.java | 6 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 26 | ||||
| -rw-r--r-- | core/java/android/widget/TimePickerClockDelegate.java | 2 | ||||
| -rw-r--r-- | core/java/android/widget/TimePickerSpinnerDelegate.java | 2 |
12 files changed, 49 insertions, 37 deletions
diff --git a/core/java/android/text/style/SuggestionSpan.java b/core/java/android/text/style/SuggestionSpan.java index 521044778257..be47320b59bd 100644 --- a/core/java/android/text/style/SuggestionSpan.java +++ b/core/java/android/text/style/SuggestionSpan.java @@ -420,7 +420,7 @@ public class SuggestionSpan extends CharacterStyle implements ParcelableSpan { intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, hashCode()); context.sendBroadcast(intent); } else { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = context.getSystemService(InputMethodManager.class); if (imm != null) { imm.notifySuggestionPicked(this, original, index); } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index c29fbbb2125f..25a6da6859c7 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -7315,7 +7315,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // Here we check whether we still need the default focus highlight, and switch it on/off. switchDefaultFocusHighlight(); - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getContext().getSystemService(InputMethodManager.class); if (!gainFocus) { if (isPressed()) { setPressed(false); @@ -12476,7 +12476,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mPrivateFlags3 &= ~PFLAG3_TEMPORARY_DETACH; onFinishTemporaryDetach(); if (hasWindowFocus() && hasFocus()) { - InputMethodManager.getInstance().focusIn(this); + getContext().getSystemService(InputMethodManager.class).focusIn(this); } notifyEnterOrExitForAutoFillIfNeeded(true); } @@ -12867,7 +12867,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * focus, false otherwise. */ public void onWindowFocusChanged(boolean hasWindowFocus) { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getContext().getSystemService(InputMethodManager.class); if (!hasWindowFocus) { if (isPressed()) { setPressed(false); @@ -17932,7 +17932,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, rebuildOutline(); if (isFocused()) { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getContext().getSystemService(InputMethodManager.class); if (imm != null) { imm.focusIn(this); } @@ -18515,7 +18515,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, onDetachedFromWindow(); onDetachedFromWindowInternal(); - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getContext().getSystemService(InputMethodManager.class); if (imm != null) { imm.onViewDetachedFromWindow(this); } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 16d202b8af1d..2ee7ab939bd9 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -2579,7 +2579,7 @@ public final class ViewRootImpl implements ViewParent, .mayUseInputMethod(mWindowAttributes.flags); if (imTarget != mLastWasImTarget) { mLastWasImTarget = imTarget; - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = mContext.getSystemService(InputMethodManager.class); if (imm != null && imTarget) { imm.onPreWindowFocus(mView, hasWindowFocus); imm.onPostWindowFocus(mView, mView.findFocus(), @@ -2695,7 +2695,7 @@ public final class ViewRootImpl implements ViewParent, mLastWasImTarget = WindowManager.LayoutParams .mayUseInputMethod(mWindowAttributes.flags); - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = mContext.getSystemService(InputMethodManager.class); if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) { imm.onPreWindowFocus(mView, hasWindowFocus); } @@ -4329,7 +4329,7 @@ public final class ViewRootImpl implements ViewParent, enqueueInputEvent(event, null, 0, true); } break; case MSG_CHECK_FOCUS: { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = mContext.getSystemService(InputMethodManager.class); if (imm != null) { imm.checkFocus(); } @@ -4871,7 +4871,7 @@ public final class ViewRootImpl implements ViewParent, @Override protected int onProcess(QueuedInputEvent q) { if (mLastWasImTarget && !isInLocalFocusMode()) { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = mContext.getSystemService(InputMethodManager.class); if (imm != null) { final InputEvent event = q.mEvent; if (DEBUG_IMF) Log.v(mTag, "Sending input event to IME: " + event); diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java index 4ca9a141fd23..e20acf1a0008 100644 --- a/core/java/android/view/WindowManagerGlobal.java +++ b/core/java/android/view/WindowManagerGlobal.java @@ -468,7 +468,7 @@ public final class WindowManagerGlobal { View view = root.getView(); if (view != null) { - InputMethodManager imm = InputMethodManager.getInstance(); + InputMethodManager imm = view.getContext().getSystemService(InputMethodManager.class); if (imm != null) { imm.windowDismissed(mViews.get(index).getWindowToken()); } diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 508509a83f03..02ada94e0225 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -665,10 +665,12 @@ public final class InputMethodManager { } /** - * Private optimization: retrieve the global InputMethodManager instance, - * if it exists. + * Private optimization: retrieve the global InputMethodManager instance, if it exists. * @hide + * @deprecated Use {@link Context#getSystemService(Class)} instead. This method cannot fully + * support multi-display scenario. */ + @Deprecated @UnsupportedAppUsage public static InputMethodManager peekInstance() { return sInstance; diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java index cbd624eec7d6..7d6564fd91fb 100644 --- a/core/java/android/widget/AutoCompleteTextView.java +++ b/core/java/android/widget/AutoCompleteTextView.java @@ -1158,7 +1158,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe * <p>Closes the drop down if present on screen.</p> */ public void dismissDropDown() { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getContext().getSystemService(InputMethodManager.class); if (imm != null) { imm.displayCompletions(this, null); } @@ -1247,7 +1247,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe private void buildImeCompletions() { final ListAdapter adapter = mAdapter; if (adapter != null) { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getContext().getSystemService(InputMethodManager.class); if (imm != null) { final int count = Math.min(adapter.getCount(), 20); CompletionInfo[] completions = new CompletionInfo[count]; diff --git a/core/java/android/widget/DatePickerSpinnerDelegate.java b/core/java/android/widget/DatePickerSpinnerDelegate.java index f88a4e2b414f..5f151105622e 100644 --- a/core/java/android/widget/DatePickerSpinnerDelegate.java +++ b/core/java/android/widget/DatePickerSpinnerDelegate.java @@ -639,7 +639,7 @@ class DatePickerSpinnerDelegate extends AbstractDatePickerDelegate { // changed the value via the IME and there is a next input the IME will // be shown, otherwise the user chose another means of changing the // value and having the IME up makes no sense. - InputMethodManager inputMethodManager = InputMethodManager.peekInstance(); + InputMethodManager inputMethodManager = mContext.getSystemService(InputMethodManager.class); if (inputMethodManager != null) { if (inputMethodManager.isActive(mYearSpinnerInput)) { mYearSpinnerInput.clearFocus(); diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index 442859878598..8dd30f6abe24 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -1539,6 +1539,10 @@ public class Editor { } } + private InputMethodManager getInputMethodManager() { + return mTextView.getContext().getSystemService(InputMethodManager.class); + } + public void beginBatchEdit() { mInBatchEditControllers = true; final InputMethodState ims = mInputMethodState; @@ -1707,7 +1711,7 @@ public class Editor { if (req == null) { return false; } - final InputMethodManager imm = InputMethodManager.peekInstance(); + final InputMethodManager imm = getInputMethodManager(); if (imm == null) { return false; } @@ -1742,7 +1746,7 @@ public class Editor { private void sendUpdateSelection() { if (null != mInputMethodState && mInputMethodState.mBatchEditNesting <= 0) { - final InputMethodManager imm = InputMethodManager.peekInstance(); + final InputMethodManager imm = getInputMethodManager(); if (null != imm) { final int selectionStart = mTextView.getSelectionStart(); final int selectionEnd = mTextView.getSelectionEnd(); @@ -1768,7 +1772,7 @@ public class Editor { final InputMethodState ims = mInputMethodState; if (ims != null && ims.mBatchEditNesting == 0) { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getInputMethodManager(); if (imm != null) { if (imm.isActive(mTextView)) { if (ims.mContentChanged || ims.mSelectionModeChanged) { @@ -2245,7 +2249,7 @@ public class Editor { && mTextView.isTextEditable() && !mTextView.isTextSelectable() && mShowSoftInputOnFocus) { // Show the IME to be able to replace text, except when selecting non editable text. - final InputMethodManager imm = InputMethodManager.peekInstance(); + final InputMethodManager imm = getInputMethodManager(); if (imm != null) { imm.showSoftInput(mTextView, 0, null); } @@ -2255,7 +2259,7 @@ public class Editor { private boolean extractedTextModeWillBeStarted() { if (!(mTextView.isInExtractedMode())) { - final InputMethodManager imm = InputMethodManager.peekInstance(); + final InputMethodManager imm = getInputMethodManager(); return imm != null && imm.isFullscreenMode(); } return false; @@ -4272,7 +4276,7 @@ public class Editor { if (ims == null || ims.mBatchEditNesting > 0) { return; } - final InputMethodManager imm = InputMethodManager.peekInstance(); + final InputMethodManager imm = getInputMethodManager(); if (null == imm) { return; } diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java index b6ed22c293f6..a28cc403ed56 100644 --- a/core/java/android/widget/NumberPicker.java +++ b/core/java/android/widget/NumberPicker.java @@ -1293,7 +1293,8 @@ public class NumberPicker extends LinearLayout { * Shows the soft input for its input text. */ private void showSoftInput() { - InputMethodManager inputMethodManager = InputMethodManager.peekInstance(); + InputMethodManager inputMethodManager = + getContext().getSystemService(InputMethodManager.class); if (inputMethodManager != null) { if (mHasSelectorWheel) { mInputText.setVisibility(View.VISIBLE); @@ -1307,7 +1308,8 @@ public class NumberPicker extends LinearLayout { * Hides the soft input if it is active for the input text. */ private void hideSoftInput() { - InputMethodManager inputMethodManager = InputMethodManager.peekInstance(); + InputMethodManager inputMethodManager = + getContext().getSystemService(InputMethodManager.class); if (inputMethodManager != null && inputMethodManager.isActive(mInputText)) { inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); } diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index a86e6f81f006..dfbaf9ac0901 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -2156,7 +2156,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (!enabled) { // Hide the soft input if the currently active TextView is disabled - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getInputMethodManager(); if (imm != null && imm.isActive(this)) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } @@ -2166,7 +2166,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (enabled) { // Make sure IME is updated with current editor info. - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getInputMethodManager(); if (imm != null) imm.restartInput(this); } @@ -2392,7 +2392,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (mEditor != null) mEditor.mInputType = EditorInfo.TYPE_NULL; } - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getInputMethodManager(); if (imm != null) imm.restartInput(this); } @@ -5769,7 +5769,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener Editable t = mEditableFactory.newEditable(text); text = t; setFilters(t, mFilters); - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getInputMethodManager(); if (imm != null) imm.restartInput(this); } else if (precomputed != null) { if (mTextDir == null) { @@ -6148,7 +6148,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener setTextInternal(removeSuggestionSpans(mText)); } - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getInputMethodManager(); if (imm != null) imm.restartInput(this); } @@ -6436,7 +6436,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return; } else if (actionCode == EditorInfo.IME_ACTION_DONE) { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getInputMethodManager(); if (imm != null && imm.isActive(this)) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } @@ -7902,7 +7902,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (!hasOnClickListeners()) { if (mMovement != null && mText instanceof Editable && mLayout != null && onCheckIsTextEditor()) { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getInputMethodManager(); viewClicked(imm); if (imm != null && getShowSoftInputOnFocus()) { imm.showSoftInput(this, 0); @@ -7956,7 +7956,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener & KeyEvent.FLAG_EDITOR_ACTION) != 0) { // No target for next focus, but make sure the IME // if this came from it. - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getInputMethodManager(); if (imm != null && imm.isActive(this)) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } @@ -10260,7 +10260,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (touchIsFinished && (isTextEditable() || textIsSelectable)) { // Show the IME, except when selecting in read-only text. - final InputMethodManager imm = InputMethodManager.peekInstance(); + final InputMethodManager imm = getInputMethodManager(); viewClicked(imm); if (isTextEditable() && mEditor.mShowSoftInputOnFocus && imm != null) { imm.showSoftInput(this, 0); @@ -11299,7 +11299,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener // Show the IME, except when selecting in read-only text. if ((mMovement != null || onCheckIsTextEditor()) && hasSpannableText() && mLayout != null && (isTextEditable() || isTextSelectable()) && isFocused()) { - final InputMethodManager imm = InputMethodManager.peekInstance(); + final InputMethodManager imm = getInputMethodManager(); viewClicked(imm); if (!isTextSelectable() && mEditor.mShowSoftInputOnFocus && imm != null) { handled |= imm.showSoftInput(this, 0); @@ -11367,13 +11367,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener sendAccessibilityEventUnchecked(event); } + private InputMethodManager getInputMethodManager() { + return getContext().getSystemService(InputMethodManager.class); + } + /** * Returns whether this text view is a current input method target. The * default implementation just checks with {@link InputMethodManager}. * @return True if the TextView is a current input method target; false otherwise. */ public boolean isInputMethodTarget() { - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = getInputMethodManager(); return imm != null && imm.isActive(this); } diff --git a/core/java/android/widget/TimePickerClockDelegate.java b/core/java/android/widget/TimePickerClockDelegate.java index 77670b35a1ea..6a3a8f0821d8 100644 --- a/core/java/android/widget/TimePickerClockDelegate.java +++ b/core/java/android/widget/TimePickerClockDelegate.java @@ -269,7 +269,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate { mRadialTimePickerModeButton.setContentDescription( mTextInputPickerModeEnabledDescription); updateTextInputPicker(); - InputMethodManager imm = InputMethodManager.peekInstance(); + InputMethodManager imm = mContext.getSystemService(InputMethodManager.class); if (imm != null) { imm.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0); } diff --git a/core/java/android/widget/TimePickerSpinnerDelegate.java b/core/java/android/widget/TimePickerSpinnerDelegate.java index cc79b9c85784..83c86d5ce36b 100644 --- a/core/java/android/widget/TimePickerSpinnerDelegate.java +++ b/core/java/android/widget/TimePickerSpinnerDelegate.java @@ -471,7 +471,7 @@ class TimePickerSpinnerDelegate extends TimePicker.AbstractTimePickerDelegate { // changed the value via the IME and there is a next input the IME will // be shown, otherwise the user chose another means of changing the // value and having the IME up makes no sense. - InputMethodManager inputMethodManager = InputMethodManager.peekInstance(); + InputMethodManager inputMethodManager = mContext.getSystemService(InputMethodManager.class); if (inputMethodManager != null) { if (inputMethodManager.isActive(mHourSpinnerInput)) { mHourSpinnerInput.clearFocus(); |
