Merge "[Unfold animation] Do not animate first progress value in remote provider" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
50ab78c234
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user