diff options
| author | 2024-11-07 11:14:26 +0000 | |
|---|---|---|
| committer | 2024-11-11 10:34:50 +0000 | |
| commit | 6ec6fb19e59ac7c893e6308ef32e1803caa2ab7e (patch) | |
| tree | 2e27b0c8a66af029f2e47452bea2be12ff776796 | |
| parent | 95f5091d51a955726e3b18b6ff48f6cf87782bfd (diff) | |
Avoid handling the back key event, when IME is currently hiding
When there was an ongoing hide animation (without predictive back enabled), and another swipe back happened, the second event went to the InputMethodService, where it was consumed.
This was caused by the fact, that the IME is only notified that it will be hidden at the end of the hide animation.
However, the second back event should go to the app.
This CL fixes this behaviour and doesn't dispatch the back key event to the IME, if there is an ongoing hide animation or predictive back animation in progress.
Bug: 375986921
Test: Manual, i.e. verifying that quick double back swipes are handled correctly (including after an interrupted IME hide animation)
Flag: android.view.inputmethod.refactor_insets_controller
Change-Id: Ic22f76b4708c4e5f090824d1d46833a97b19b49f
| -rw-r--r-- | core/java/android/view/ImeFocusController.java | 12 | ||||
| -rw-r--r-- | core/java/android/view/InsetsController.java | 3 |
2 files changed, 14 insertions, 1 deletions
diff --git a/core/java/android/view/ImeFocusController.java b/core/java/android/view/ImeFocusController.java index 97148969e17f..2d2f79d76008 100644 --- a/core/java/android/view/ImeFocusController.java +++ b/core/java/android/view/ImeFocusController.java @@ -23,6 +23,7 @@ import android.annotation.NonNull; import android.annotation.UiThread; import android.util.Log; import android.util.proto.ProtoOutputStream; +import android.view.inputmethod.Flags; import android.view.inputmethod.InputMethodManager; import com.android.internal.inputmethod.InputMethodDebug; @@ -150,6 +151,17 @@ public final class ImeFocusController { if (!mHasImeFocus || isInLocalFocusMode(windowAttribute)) { return InputMethodManager.DISPATCH_NOT_HANDLED; } + if (Flags.refactorInsetsController() && event instanceof KeyEvent keyEvent + && keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK) { + final var insetsController = mViewRootImpl.getInsetsController(); + if (insetsController.getAnimationType(WindowInsets.Type.ime()) + == InsetsController.ANIMATION_TYPE_HIDE + || insetsController.isPredictiveBackImeHideAnimInProgress()) { + // if there is an ongoing hide animation, the back event should not be dispatched + // to the IME. + return InputMethodManager.DISPATCH_NOT_HANDLED; + } + } final InputMethodManager imm = mViewRootImpl.mContext.getSystemService(InputMethodManager.class); if (imm == null) { diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 26ca813a9caa..b0813f3a98f6 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -1910,7 +1910,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation mImeSourceConsumer.onWindowFocusLost(); } - @VisibleForTesting + /** Returns the current {@link AnimationType} of an {@link InsetsType}. */ + @VisibleForTesting(visibility = PACKAGE) public @AnimationType int getAnimationType(@InsetsType int type) { for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { InsetsAnimationControlRunner control = mRunningAnimations.get(i).runner; |