Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b463b88 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add @hide IMM#hideSoftInputFromView as an optimization" into main

parents 556f80dc 2a757ef4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -782,6 +782,7 @@ public interface ImeTracker {
        private boolean shouldMonitorLatency(@SoftInputShowHideReason int reason) {
            return reason == SoftInputShowHideReason.SHOW_SOFT_INPUT
                    || reason == SoftInputShowHideReason.HIDE_SOFT_INPUT
                    || reason == SoftInputShowHideReason.HIDE_SOFT_INPUT_FROM_VIEW
                    || reason == SoftInputShowHideReason.SHOW_SOFT_INPUT_BY_INSETS_API
                    || reason == SoftInputShowHideReason.HIDE_SOFT_INPUT_BY_INSETS_API
                    || reason == SoftInputShowHideReason.SHOW_SOFT_INPUT_FROM_IME
+34 −0
Original line number Diff line number Diff line
@@ -2279,6 +2279,40 @@ public final class InputMethodManager {
        }
    }

    /**
     * Synonym for {@link #hideSoftInputFromWindow(IBinder, int)} but takes a {@link View} as a
     * parameter to be a counterpart of {@link #showSoftInput(View, int)}.
     *
     * @param view {@link View} to be used to conditionally issue hide request when and only when
     *             this {@link View} is serving as an IME target.
     * @hide
     */
    public boolean hideSoftInputFromView(@NonNull View view, @HideFlags int flags) {
        final var reason = SoftInputShowHideReason.HIDE_SOFT_INPUT_FROM_VIEW;
        final ImeTracker.Token statsToken = ImeTracker.forLogging().onRequestHide(
                null /* component */, Process.myUid(),
                ImeTracker.ORIGIN_CLIENT_HIDE_SOFT_INPUT, reason);
        ImeTracker.forLatency().onRequestHide(statsToken, ImeTracker.ORIGIN_CLIENT_HIDE_SOFT_INPUT,
                reason, ActivityThread::currentApplication);
        ImeTracing.getInstance().triggerClientDump("InputMethodManager#hideSoftInputFromView",
                this, null /* icProto */);
        synchronized (mH) {
            if (!hasServedByInputMethodLocked(view)) {
                ImeTracker.forLogging().onFailed(statsToken, ImeTracker.PHASE_CLIENT_VIEW_SERVED);
                ImeTracker.forLatency().onShowFailed(
                        statsToken, ImeTracker.PHASE_CLIENT_VIEW_SERVED,
                        ActivityThread::currentApplication);
                Log.w(TAG, "Ignoring hideSoftInputFromView() as view=" + view + " is not served.");
                return false;
            }

            ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_CLIENT_VIEW_SERVED);

            return IInputMethodManagerGlobalInvoker.hideSoftInput(mClient, view.getWindowToken(),
                    statsToken, flags, null, reason);
        }
    }

    /**
     * Start stylus handwriting session.
     *
+6 −6
Original line number Diff line number Diff line
@@ -640,15 +640,15 @@ class DatePickerSpinnerDelegate extends AbstractDatePickerDelegate {
        // value and having the IME up makes no sense.
        InputMethodManager inputMethodManager = mContext.getSystemService(InputMethodManager.class);
        if (inputMethodManager != null) {
            if (inputMethodManager.isActive(mYearSpinnerInput)) {
            if (mYearSpinnerInput.hasFocus()) {
                inputMethodManager.hideSoftInputFromView(mYearSpinnerInput, 0);
                mYearSpinnerInput.clearFocus();
                inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
            } else if (inputMethodManager.isActive(mMonthSpinnerInput)) {
            } else if (mMonthSpinnerInput.hasFocus()) {
                inputMethodManager.hideSoftInputFromView(mMonthSpinnerInput, 0);
                mMonthSpinnerInput.clearFocus();
                inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
            } else if (inputMethodManager.isActive(mDaySpinnerInput)) {
            } else if (mDaySpinnerInput.hasFocus()) {
                inputMethodManager.hideSoftInputFromView(mDaySpinnerInput, 0);
                mDaySpinnerInput.clearFocus();
                inputMethodManager.hideSoftInputFromWindow(mDelegator.getWindowToken(), 0);
            }
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -1328,8 +1328,8 @@ public class NumberPicker extends LinearLayout {
    private void hideSoftInput() {
        InputMethodManager inputMethodManager =
                getContext().getSystemService(InputMethodManager.class);
        if (inputMethodManager != null && inputMethodManager.isActive(mInputText)) {
            inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
        if (inputMethodManager != null) {
            inputMethodManager.hideSoftInputFromView(mInputText, 0);
        }
        if (mHasSelectorWheel) {
            mInputText.setVisibility(View.INVISIBLE);
+6 −6
Original line number Diff line number Diff line
@@ -2447,8 +2447,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        if (!enabled) {
            // Hide the soft input if the currently active TextView is disabled
            InputMethodManager imm = getInputMethodManager();
            if (imm != null && imm.isActive(this)) {
                imm.hideSoftInputFromWindow(getWindowToken(), 0);
            if (imm != null) {
                imm.hideSoftInputFromView(this, 0);
            }
        }
@@ -8058,8 +8058,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            } else if (actionCode == EditorInfo.IME_ACTION_DONE) {
                InputMethodManager imm = getInputMethodManager();
                if (imm != null && imm.isActive(this)) {
                    imm.hideSoftInputFromWindow(getWindowToken(), 0);
                if (imm != null) {
                    imm.hideSoftInputFromView(this, 0);
                }
                return;
            }
@@ -9722,8 +9722,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                                // No target for next focus, but make sure the IME
                                // if this came from it.
                                InputMethodManager imm = getInputMethodManager();
                                if (imm != null && imm.isActive(this)) {
                                    imm.hideSoftInputFromWindow(getWindowToken(), 0);
                                if (imm != null) {
                                    imm.hideSoftInputFromView(this, 0);
                                }
                            }
                        }
Loading