From a495a4e1f5dd4eb304774c448c7c8ba0b150b0b2 Mon Sep 17 00:00:00 2001 From: Nick Chameyev Date: Fri, 14 Apr 2023 16:43:12 +0100 Subject: [PATCH] [Unfold animation] Do not animate first progress value in remote provider Updates unfold remote filter to start animating values only after the first progress event has received. Currently the default value is 1f and when unfolding we might see launcher animating from progress 1f to the current progress and then back to 1f. Bug: 271099882 Test: atest com.android.systemui.unfold.progress.UnfoldRemoteFilterTest Test: manual testing fold/unfold with removed black overlay Test: check that laucher progress perfetto trace doesn't have a jump Change-Id: I4880d19034cdfd91faebf754939d7906c813a315 --- .../unfold/progress/UnfoldRemoteFilterTest.kt | 30 +++++++++++++++---- .../unfold/progress/UnfoldRemoteFilter.kt | 13 +++++++- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/tests/src/com/android/systemui/unfold/progress/UnfoldRemoteFilterTest.kt b/packages/SystemUI/tests/src/com/android/systemui/unfold/progress/UnfoldRemoteFilterTest.kt index f14009aad0337..70eadcee7607e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/unfold/progress/UnfoldRemoteFilterTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/unfold/progress/UnfoldRemoteFilterTest.kt @@ -39,15 +39,35 @@ class UnfoldRemoteFilterTest : SysuiTestCase() { } @Test - fun onTransitionProgress_withInterval_propagated() { - runOnMainThreadWithInterval( - { progressProvider.onTransitionStarted() }, - { progressProvider.onTransitionProgress(0.5f) } - ) + fun onTransitionProgress_firstProgressEvent_propagatedImmediately() { + progressProvider.onTransitionStarted() + progressProvider.onTransitionProgress(0.5f) listener.assertLastProgress(0.5f) } + @Test + fun onTransitionProgress_secondProgressEvent_isNotPropagatedImmediately() = + InstrumentationRegistry.getInstrumentation().runOnMainSync { + progressProvider.onTransitionStarted() + progressProvider.onTransitionProgress(0.5f) + progressProvider.onTransitionProgress(0.8f) + + // 0.8f should be set only later, after the animation + listener.assertLastProgress(0.5f) + } + + @Test + fun onTransitionProgress_severalProgressEventsWithInterval_propagated() { + runOnMainThreadWithInterval( + { progressProvider.onTransitionStarted() }, + { progressProvider.onTransitionProgress(0.5f) }, + { progressProvider.onTransitionProgress(0.8f) } + ) + + listener.assertLastProgress(0.8f) + } + @Test fun onTransitionEnded_propagated() { runOnMainThreadWithInterval( diff --git a/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/UnfoldRemoteFilter.kt b/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/UnfoldRemoteFilter.kt index 30418883eaf82..843cc3b780314 100644 --- a/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/UnfoldRemoteFilter.kt +++ b/packages/SystemUI/unfold/src/com/android/systemui/unfold/progress/UnfoldRemoteFilter.kt @@ -34,6 +34,7 @@ class UnfoldRemoteFilter( } private var inProgress = false + private var receivedProgressEvent = false private var processedProgress: Float = 1.0f set(newProgress) { @@ -54,7 +55,16 @@ class UnfoldRemoteFilter( override fun onTransitionProgress(progress: Float) { logCounter({ "$TAG#plain_remote_progress" }, progress) if (inProgress) { - springAnimation.animateToFinalPosition(progress) + if (receivedProgressEvent) { + // We have received at least one progress event, animate from the previous + // progress to the current + springAnimation.animateToFinalPosition(progress) + } else { + // This is the first progress event after starting the animation, send it + // straightaway and set the spring value without animating it + processedProgress = progress + receivedProgressEvent = true + } } else { Log.e(TAG, "Progress received while not in progress.") } @@ -62,6 +72,7 @@ class UnfoldRemoteFilter( override fun onTransitionFinished() { inProgress = false + receivedProgressEvent = false listener.onTransitionFinished() }