From 5e0c72a2c593de712debf7294e39fb36553a2b30 Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Tue, 8 Feb 2022 10:06:28 +0800 Subject: Estimate animation duration for AVD and AnimationDrawable For Android S, we use the API windowSplashScreenAnimationDuration to know the duration of the animatable icon would be, however, developers can be confused to thought that this API is used to declare the duration of splash screen. To get the real duration of the animatable icon, if it is an AVD or AnimationDrawable, try to get the animation duration from it. Test: atest StartingSurfaceDrawerTests SplashscreenTests Bug: 211707095 Change-Id: Ia3f8c5cd50bab164360e07d9ced87ff7f4321e96 --- core/java/android/window/SplashScreenView.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'core/java/android/window/SplashScreenView.java') diff --git a/core/java/android/window/SplashScreenView.java b/core/java/android/window/SplashScreenView.java index 34a34180b227..232248b6fab3 100644 --- a/core/java/android/window/SplashScreenView.java +++ b/core/java/android/window/SplashScreenView.java @@ -65,6 +65,7 @@ import com.android.internal.util.ContrastColorUtil; import java.time.Duration; import java.time.Instant; import java.util.function.Consumer; +import java.util.function.LongConsumer; /** *

The view which allows an activity to customize its splash screen exit animation.

@@ -234,7 +235,7 @@ public final class SplashScreenView extends FrameLayout { /** * Set the animation duration if icon is animatable. */ - public Builder setAnimationDurationMillis(int duration) { + public Builder setAnimationDurationMillis(long duration) { mIconAnimationDuration = Duration.ofMillis(duration); return this; } @@ -521,8 +522,11 @@ public final class SplashScreenView extends FrameLayout { }); } - private void animationStartCallback() { + private void animationStartCallback(long animDuration) { mIconAnimationStart = Instant.now(); + if (animDuration > 0) { + mIconAnimationDuration = Duration.ofMillis(animDuration); + } } /** @@ -693,9 +697,8 @@ public final class SplashScreenView extends FrameLayout { * Prepare the animation if this drawable also be animatable. * @param duration The animation duration. * @param startListener The callback listener used to receive the start of the animation. - * @return true if this drawable object can also be animated and it can be played now. */ - boolean prepareAnimate(long duration, Runnable startListener); + void prepareAnimate(long duration, LongConsumer startListener); /** * Stop animation. -- cgit v1.2.3