From 4748ce9e02047d3ee6962a6e9cfed6729f0ddd45 Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Mon, 14 Mar 2022 17:48:09 +0800 Subject: [PATCH] Deprecating windowSplashScreenAnimationDuration attr. In previous CL(5e0c72a2c593de712debf7294e39fb36553a2b30) we provide a way to read the animation duration from AVD and AnimationDrawable, which should be enough to deprecate this attribute since the naming could confusing developers. The attribute was used to cut off the animation if the icon is animatable, but since the animation can be stop when removing the splash screen view from window, the attribute is useless so framework won't read it anymore. The attribute was also be the return value from SplashScreenView#getIconAnimationDuration, however, since this API was designed to let developer decide when to cut off the animation if the app want to handle OnExitAnimationListener#onSplashScreenExit, developer can pre-decide the duration in the app without set this attribute. Bug: 211707095 Test: atest SplashscreenTests StartingSurfaceDrawerTests Change-Id: Ib3a0b4314bd15158c392e56c0e125a33c753e716 --- core/api/current.txt | 2 +- .../java/android/window/SplashScreenView.java | 25 ++++++++----------- core/res/res/values/attrs.xml | 4 ++- .../SplashscreenContentDrawer.java | 20 ++++----------- .../SplashscreenIconDrawableFactory.java | 23 ++++++----------- 5 files changed, 26 insertions(+), 48 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 1391408a7a729..934b5d0f85f20 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -1756,7 +1756,7 @@ package android { field public static final int windowShowWallpaper = 16843410; // 0x1010292 field public static final int windowSoftInputMode = 16843307; // 0x101022b field public static final int windowSplashScreenAnimatedIcon = 16844333; // 0x101062d - field public static final int windowSplashScreenAnimationDuration = 16844334; // 0x101062e + field @Deprecated public static final int windowSplashScreenAnimationDuration = 16844334; // 0x101062e field public static final int windowSplashScreenBackground = 16844332; // 0x101062c field public static final int windowSplashScreenBehavior; field public static final int windowSplashScreenBrandingImage = 16844335; // 0x101062f diff --git a/core/java/android/window/SplashScreenView.java b/core/java/android/window/SplashScreenView.java index 10d7ecab4ffa9..19ee1d0461849 100644 --- a/core/java/android/window/SplashScreenView.java +++ b/core/java/android/window/SplashScreenView.java @@ -232,14 +232,6 @@ public final class SplashScreenView extends FrameLayout { return this; } - /** - * Set the animation duration if icon is animatable. - */ - public Builder setAnimationDurationMillis(long duration) { - mIconAnimationDuration = Duration.ofMillis(duration); - return this; - } - /** * Set the Runnable that can receive the task which should be executed on UI thread. * @param uiThreadInitTask @@ -294,8 +286,7 @@ public final class SplashScreenView extends FrameLayout { } else { view.mIconView = createSurfaceView(view); } - view.initIconAnimation(mIconDrawable, - mIconAnimationDuration != null ? mIconAnimationDuration.toMillis() : 0); + view.initIconAnimation(mIconDrawable); view.mIconAnimationStart = mIconAnimationStart; view.mIconAnimationDuration = mIconAnimationDuration; } else if (mIconSize != 0) { @@ -463,6 +454,11 @@ public final class SplashScreenView extends FrameLayout { /** * Returns the duration of the icon animation if icon is animatable. * + * Note the return value can be null or 0 if the + * {@link android.R.attr#windowSplashScreenAnimatedIcon} is not + * {@link android.graphics.drawable.AnimationDrawable} or + * {@link android.graphics.drawable.AnimatedVectorDrawable}. + * * @see android.R.attr#windowSplashScreenAnimatedIcon * @see android.R.attr#windowSplashScreenAnimationDuration */ @@ -497,12 +493,12 @@ public final class SplashScreenView extends FrameLayout { mSurfaceView.setChildSurfacePackage(mSurfacePackage); } - void initIconAnimation(Drawable iconDrawable, long duration) { + void initIconAnimation(Drawable iconDrawable) { if (!(iconDrawable instanceof IconAnimateListener)) { return; } IconAnimateListener aniDrawable = (IconAnimateListener) iconDrawable; - aniDrawable.prepareAnimate(duration, this::animationStartCallback); + aniDrawable.prepareAnimate(this::animationStartCallback); aniDrawable.setAnimationJankMonitoring(new AnimatorListenerAdapter() { @Override public void onAnimationCancel(Animator animation) { @@ -524,7 +520,7 @@ public final class SplashScreenView extends FrameLayout { private void animationStartCallback(long animDuration) { mIconAnimationStart = Instant.now(); - if (animDuration > 0) { + if (animDuration >= 0) { mIconAnimationDuration = Duration.ofMillis(animDuration); } } @@ -695,10 +691,9 @@ public final class SplashScreenView extends FrameLayout { public interface IconAnimateListener { /** * 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. */ - void prepareAnimate(long duration, LongConsumer startListener); + void prepareAnimate(LongConsumer startListener); /** * Stop animation. diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index da5f8998d1565..b156b6bc7a9d7 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2322,7 +2322,9 @@ + be limited below 1000ms. + @deprecated Not used by framework starting from API level 33. The system estimates the + duration of the vector animation automatically. -->