From f016c44adcaec087b0f0f8558205fcb6454e42e9 Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Mon, 11 Jul 2022 07:12:13 -0700 Subject: [PATCH] Pause the AllSetActivity background animation more reliably. - Pause the animation when the alpha <= 0.1f, rather than 0f - Pause the animation when the AllSetActivity pauses - Do not vibrate if the AllSetActivity is not resumed Bug: 236924895 Test: manually launched AllSetActivity and swiped up at various speeds Change-Id: I1019f680730cfc72e9ad305d7ae09cff8a1637be (cherry picked from commit 5f6b07d31c6994595248c1d12c630f1a3650c9a2) --- .../quickstep/interaction/AllSetActivity.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java index 5680170a8f..47bb3cfb16 100644 --- a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java +++ b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java @@ -82,6 +82,8 @@ public class AllSetActivity extends Activity { private static final int MAX_SWIPE_DURATION = 350; + private static final float ANIMATION_PAUSE_ALPHA_THRESHOLD = 0.1f; + private TISBindHelper mTISBindHelper; private TISBinder mBinder; @@ -144,6 +146,10 @@ public class AllSetActivity extends Activity { } private void runOnUiHelperThread(Runnable runnable) { + if (!isResumed() + || getContentViewAlphaForSwipeProgress() <= ANIMATION_PAUSE_ALPHA_THRESHOLD) { + return; + } Executors.UI_HELPER_EXECUTOR.execute(runnable); } @@ -192,6 +198,7 @@ public class AllSetActivity extends Activity { @Override protected void onResume() { super.onResume(); + maybeResumeOrPauseBackgroundAnimation(); if (mBinder != null) { mBinder.getTaskbarManager().setSetupUIVisible(true); mBinder.setSwipeUpProxy(this::createSwipeUpProxy); @@ -210,6 +217,7 @@ public class AllSetActivity extends Activity { protected void onPause() { super.onPause(); clearBinderOverride(); + maybeResumeOrPauseBackgroundAnimation(); if (mSwipeProgress.value >= 1) { finishAndRemoveTask(); } @@ -244,10 +252,25 @@ public class AllSetActivity extends Activity { return mSwipeProgress; } + private float getContentViewAlphaForSwipeProgress() { + return Utilities.mapBoundToRange( + mSwipeProgress.value, 0, HINT_BOTTOM_FACTOR, 1, 0, LINEAR); + } + + private void maybeResumeOrPauseBackgroundAnimation() { + boolean shouldPlayAnimation = + getContentViewAlphaForSwipeProgress() > ANIMATION_PAUSE_ALPHA_THRESHOLD + && isResumed(); + if (mAnimatedBackground.isAnimating() && !shouldPlayAnimation) { + mAnimatedBackground.pauseAnimation(); + } else if (!mAnimatedBackground.isAnimating() && shouldPlayAnimation) { + mAnimatedBackground.resumeAnimation(); + } + } + private void onSwipeProgressUpdate() { mBackground.setProgress(mSwipeProgress.value); - float alpha = Utilities.mapBoundToRange( - mSwipeProgress.value, 0, HINT_BOTTOM_FACTOR, 1, 0, LINEAR); + float alpha = getContentViewAlphaForSwipeProgress(); mContentView.setAlpha(alpha); mContentView.setTranslationY((alpha - 1) * mSwipeUpShift); @@ -259,12 +282,7 @@ public class AllSetActivity extends Activity { mLauncherStartAnim.setPlayFraction(Utilities.mapBoundToRange( mSwipeProgress.value, 0, 1, 0, 1, FAST_OUT_SLOW_IN)); } - - if (alpha == 0f) { - mAnimatedBackground.pauseAnimation(); - } else if (!mAnimatedBackground.isAnimating()) { - mAnimatedBackground.resumeAnimation(); - } + maybeResumeOrPauseBackgroundAnimation(); } /**