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

Commit a601341f authored by Andy Wickham's avatar Andy Wickham
Browse files

Add a WindowInsetsAnimationCallback to listen to IME changes.

This handles cases that were previously ignored, such as dismissing
the IME with the back key/gesture.

Removed extraneous manual state updates that were used for specific
cases previously. The only remaining state updates are from our
controlled IME animation in KeyboardInsetsHandler, as that correctly
handles the case where you start closing the IME but end up keeping
it open (or vice versa).

Bug: 277738379
Fix: 320659754
Test: Manually go through various IME transitions on Launcher,
open and close apps, lock/unlock, etc to verify keyboard state
is correctly updated. And verify b/320659754 steps do not repro.
Flag: NA

Change-Id: I4787afbb37eed815b909a0215d8afeb3894ab985
parent b4422352
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
package com.android.launcher3;

import static com.android.launcher3.logging.KeyboardStateManager.KeyboardState.SHOW;

import android.content.Context;
import android.graphics.Rect;
import android.text.TextUtils;
@@ -93,7 +91,6 @@ public class ExtendedEditText extends EditText {
     * @return true if the keyboard is shown correctly and focus is given to this view.
     */
    public boolean showKeyboard() {
        onKeyboardShown();
        return requestFocus() && showSoftInputInternal();
    }

@@ -120,11 +117,6 @@ public class ExtendedEditText extends EditText {
        }
    }

    protected void onKeyboardShown() {
        ActivityContext.lookupContext(getContext()).getStatsLogManager()
                .keyboardStateManager().setKeyboardState(SHOW);
    }

    private boolean showSoftInputInternal() {
        boolean result = false;
        InputMethodManager imm = getContext().getSystemService(InputMethodManager.class);
+24 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.launcher3;
import static android.app.PendingIntent.FLAG_IMMUTABLE;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
import static android.content.pm.ActivityInfo.CONFIG_UI_MODE;
import static android.view.WindowInsetsAnimation.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE;
import static android.view.accessibility.AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;

import static com.android.app.animation.Interpolators.EMPHASIZED;
@@ -67,6 +68,8 @@ import static com.android.launcher3.Utilities.postAsyncCallback;
import static com.android.launcher3.config.FeatureFlags.ENABLE_SMARTSPACE_REMOVAL;
import static com.android.launcher3.config.FeatureFlags.FOLDABLE_SINGLE_PAGE;
import static com.android.launcher3.config.FeatureFlags.MULTI_SELECT_EDIT_MODE;
import static com.android.launcher3.logging.KeyboardStateManager.KeyboardState.HIDE;
import static com.android.launcher3.logging.KeyboardStateManager.KeyboardState.SHOW;
import static com.android.launcher3.logging.StatsLogManager.EventEnum;
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND;
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME;
@@ -139,6 +142,8 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.WindowInsets;
import android.view.WindowInsetsAnimation;
import android.view.WindowManager.LayoutParams;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.OvershootInterpolator;
@@ -1084,6 +1089,25 @@ public class Launcher extends StatefulActivity<LauncherState>

        DiscoveryBounce.showForHomeIfNeeded(this);
        mAppWidgetHolder.setActivityResumed(true);

        // Listen for IME changes to keep state up to date.
        getRootView().setWindowInsetsAnimationCallback(
                new WindowInsetsAnimation.Callback(DISPATCH_MODE_CONTINUE_ON_SUBTREE) {
                    @Override
                    public WindowInsets onProgress(WindowInsets windowInsets,
                            List<WindowInsetsAnimation> windowInsetsAnimations) {
                        return windowInsets;
                    }

                    @Override
                    public void onEnd(WindowInsetsAnimation animation) {
                        WindowInsets insets = getRootView().getRootWindowInsets();
                        boolean isImeVisible =
                                insets != null && insets.isVisible(WindowInsets.Type.ime());
                        getStatsLogManager().keyboardStateManager().setKeyboardState(
                                isImeVisible ? SHOW : HIDE);
                    }
                });
    }

    private void logStopAndResume(boolean isResume) {
+1 −5
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import static android.window.SplashScreen.SPLASH_SCREEN_STYLE_SOLID_COLOR;

import static com.android.launcher3.LauncherSettings.Animation.DEFAULT_NO_ICON;
import static com.android.launcher3.Utilities.allowBGLaunch;
import static com.android.launcher3.logging.KeyboardStateManager.KeyboardState.HIDE;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_KEYBOARD_CLOSED;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_APP_LAUNCH_PENDING_INTENT;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_APP_LAUNCH_TAP;
@@ -280,12 +279,9 @@ public interface ActivityContext {
            if (wic != null) {
                // Only hide the keyboard if it is actually showing.
                if (isImeShown) {
                    StatsLogManager slm = getStatsLogManager();
                    slm.keyboardStateManager().setKeyboardState(HIDE);

                    // this method cannot be called cross threads
                    wic.hide(WindowInsets.Type.ime());
                    slm.logger().log(LAUNCHER_ALLAPPS_KEYBOARD_CLOSED);
                    getStatsLogManager().logger().log(LAUNCHER_ALLAPPS_KEYBOARD_CLOSED);
                }

                // If the WindowInsetsController is not null, we end here regardless of whether we