summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Johannes Gallmann <gallmann@google.com> 2024-04-30 08:45:19 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-04-30 08:45:19 +0000
commit0e54359cc41439adb58602975aa67c0cc9036fc4 (patch)
tree2f81a6b8d4d1751f4b0a488f4735a1e412467aed
parentcf8688f4b145ec4543c9f007efed21f3c023a304 (diff)
parentafe4038596a632be5a292d1328ab59356d5a606d (diff)
Merge "Fix flicker in predictive IME back animation" into main
-rw-r--r--core/java/android/view/InsetsAnimationControlImpl.java8
-rw-r--r--core/java/android/view/InsetsAnimationControlRunner.java9
-rw-r--r--core/java/android/view/InsetsAnimationThreadControlRunner.java7
-rw-r--r--core/java/android/view/InsetsController.java14
-rw-r--r--core/java/android/view/InsetsResizeAnimationRunner.java6
5 files changed, 43 insertions, 1 deletions
diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java
index 85c779bc8c79..6568912a82c0 100644
--- a/core/java/android/view/InsetsAnimationControlImpl.java
+++ b/core/java/android/view/InsetsAnimationControlImpl.java
@@ -95,7 +95,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
private final Matrix mTmpMatrix = new Matrix();
private final InsetsState mInitialInsetsState;
private final @AnimationType int mAnimationType;
- private final @LayoutInsetsDuringAnimation int mLayoutInsetsDuringAnimation;
+ private @LayoutInsetsDuringAnimation int mLayoutInsetsDuringAnimation;
private final @InsetsType int mTypes;
private @InsetsType int mControllingTypes;
private final InsetsAnimationControlCallbacks mController;
@@ -377,6 +377,12 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
}
@Override
+ public void updateLayoutInsetsDuringAnimation(
+ @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation) {
+ mLayoutInsetsDuringAnimation = layoutInsetsDuringAnimation;
+ }
+
+ @Override
public void dumpDebug(ProtoOutputStream proto, long fieldId) {
final long token = proto.start(fieldId);
proto.write(IS_CANCELLED, mCancelled);
diff --git a/core/java/android/view/InsetsAnimationControlRunner.java b/core/java/android/view/InsetsAnimationControlRunner.java
index cf40e7e4d308..8cb8b47dd0ec 100644
--- a/core/java/android/view/InsetsAnimationControlRunner.java
+++ b/core/java/android/view/InsetsAnimationControlRunner.java
@@ -20,6 +20,7 @@ import android.annotation.Nullable;
import android.util.SparseArray;
import android.util.proto.ProtoOutputStream;
import android.view.InsetsController.AnimationType;
+import android.view.InsetsController.LayoutInsetsDuringAnimation;
import android.view.WindowInsets.Type.InsetsType;
import android.view.inputmethod.ImeTracker;
@@ -82,6 +83,14 @@ public interface InsetsAnimationControlRunner {
ImeTracker.Token getStatsToken();
/**
+ * Updates the desired layout insets during the animation.
+ *
+ * @param layoutInsetsDuringAnimation Whether the insets should be shown or hidden
+ */
+ void updateLayoutInsetsDuringAnimation(
+ @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation);
+
+ /**
*
* Export the state of classes that implement this interface into a protocol buffer
* output stream.
diff --git a/core/java/android/view/InsetsAnimationThreadControlRunner.java b/core/java/android/view/InsetsAnimationThreadControlRunner.java
index 92e20e09d8c4..83ff88bdcc1c 100644
--- a/core/java/android/view/InsetsAnimationThreadControlRunner.java
+++ b/core/java/android/view/InsetsAnimationThreadControlRunner.java
@@ -186,4 +186,11 @@ public class InsetsAnimationThreadControlRunner implements InsetsAnimationContro
public int getAnimationType() {
return mControl.getAnimationType();
}
+
+ @Override
+ public void updateLayoutInsetsDuringAnimation(
+ @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation) {
+ InsetsAnimationThread.getHandler().post(
+ () -> mControl.updateLayoutInsetsDuringAnimation(layoutInsetsDuringAnimation));
+ }
}
diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java
index edf850cdff78..c54526747c5c 100644
--- a/core/java/android/view/InsetsController.java
+++ b/core/java/android/view/InsetsController.java
@@ -1031,6 +1031,20 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
@VisibleForTesting(visibility = PACKAGE)
public void setPredictiveBackImeHideAnimInProgress(boolean isInProgress) {
mIsPredictiveBackImeHideAnimInProgress = isInProgress;
+ if (isInProgress) {
+ // The InsetsAnimationControlRunner has layoutInsetsDuringAnimation set to SHOWN during
+ // predictive back. Let's set it to HIDDEN once the predictive back animation enters the
+ // post-commit phase.
+ // That prevents flickers in case the animation is cancelled by an incoming show request
+ // during the hide animation.
+ for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
+ final InsetsAnimationControlRunner runner = mRunningAnimations.get(i).runner;
+ if ((runner.getTypes() & ime()) != 0) {
+ runner.updateLayoutInsetsDuringAnimation(LAYOUT_INSETS_DURING_ANIMATION_HIDDEN);
+ break;
+ }
+ }
+ }
}
boolean isPredictiveBackImeHideAnimInProgress() {
diff --git a/core/java/android/view/InsetsResizeAnimationRunner.java b/core/java/android/view/InsetsResizeAnimationRunner.java
index ebdddd537ae3..6e6222187e49 100644
--- a/core/java/android/view/InsetsResizeAnimationRunner.java
+++ b/core/java/android/view/InsetsResizeAnimationRunner.java
@@ -34,6 +34,7 @@ import android.graphics.Insets;
import android.graphics.Rect;
import android.util.SparseArray;
import android.util.proto.ProtoOutputStream;
+import android.view.InsetsController.LayoutInsetsDuringAnimation;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsAnimation.Bounds;
import android.view.animation.Interpolator;
@@ -242,4 +243,9 @@ public class InsetsResizeAnimationRunner implements InsetsAnimationControlRunner
@Override
public void onCancelled(WindowInsetsAnimationController controller) {
}
+
+ @Override
+ public void updateLayoutInsetsDuringAnimation(
+ @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation) {
+ }
}