summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorwilsonshih <wilsonshih@google.com>2020-10-30 17:00:11 +0800
committerVadim Caen <caen@google.com>2021-02-15 15:22:03 +0100
commitae7ee3f3ef81ff730cfa99344d9983f2e5148537 (patch)
tree9c1100a34e77f63ac5156a01d284d944d64a3db7 /core/java
parent56f65c3bb7d52422dc33108268207954d34633cb (diff)
Provide new APIs for customize splash screen window.(3/N)
Create new APIs for developer to customize starting window - windowSplashScreenBackground: specify the background color - windowSplashScreenAnimatedIcon: replace center icon on starting window, and it can be animatable. - windowSplashScreenAnimationDuration: the animation duration if the replace icon is animatable, it cannot exceed max_starting_window_intro_icon_anim_duration. Support ADV to replace the icon on starting window. Ref doc: go/improved_app_launch_animations Bug: 73289295 Test: build/flash Test: check splash screen starting window. Test: atest StartingSurfaceDrawerTests SplashscreenTests Test: atest ShellTaskOrganizerTests Change-Id: Id3de3e9b57d769f096baf43713c1e3c327ecfdc8
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/window/SplashScreenView.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/core/java/android/window/SplashScreenView.java b/core/java/android/window/SplashScreenView.java
index b8d3fc2eda05..3d3d3468c6da 100644
--- a/core/java/android/window/SplashScreenView.java
+++ b/core/java/android/window/SplashScreenView.java
@@ -17,14 +17,18 @@ package android.window;
import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
+import android.animation.Animator;
+import android.animation.ValueAnimator;
import android.annotation.ColorInt;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.TestApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
+import android.graphics.drawable.Animatable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
@@ -65,6 +69,11 @@ public final class SplashScreenView extends FrameLayout {
private int mInitBackgroundColor;
private View mIconView;
private Bitmap mParceledBitmap;
+
+ private Animatable mAnimatableIcon;
+ private ValueAnimator mAnimator;
+ private Runnable mAnimationFinishListener;
+
// cache original window and status
private Window mWindow;
private boolean mDrawBarBackground;
@@ -81,6 +90,7 @@ public final class SplashScreenView extends FrameLayout {
private @ColorInt int mBackgroundColor;
private Bitmap mParceledBitmap;
private Drawable mIconDrawable;
+ private int mIconAnimationDuration;
public Builder(@NonNull Context context) {
mContext = context;
@@ -125,6 +135,14 @@ public final class SplashScreenView extends FrameLayout {
}
/**
+ * Set the animation duration if icon is animatable.
+ */
+ public Builder setAnimationDuration(int duration) {
+ mIconAnimationDuration = duration;
+ return this;
+ }
+
+ /**
* Create SplashScreenWindowView object from materials.
*/
public SplashScreenView build() {
@@ -142,6 +160,7 @@ public final class SplashScreenView extends FrameLayout {
}
if (mIconDrawable != null) {
view.mIconView.setBackground(mIconDrawable);
+ view.initIconAnimation(mIconDrawable, mIconAnimationDuration);
}
if (mParceledBitmap != null) {
view.mParceledBitmap = mParceledBitmap;
@@ -180,6 +199,66 @@ public final class SplashScreenView extends FrameLayout {
return !mNotCopyable;
}
+ void initIconAnimation(Drawable iconDrawable, int duration) {
+ if (iconDrawable instanceof Animatable) {
+ mAnimatableIcon = (Animatable) iconDrawable;
+ mAnimator = ValueAnimator.ofInt(0, 1);
+ mAnimator.setDuration(duration);
+
+ mAnimator.addListener(new Animator.AnimatorListener() {
+ @Override
+ public void onAnimationStart(Animator animation) {
+ mAnimatableIcon.start();
+ }
+
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ mAnimatableIcon.stop();
+ onIconAnimationFinish();
+ }
+
+ @Override
+ public void onAnimationCancel(Animator animation) {
+ mAnimatableIcon.stop();
+ onIconAnimationFinish();
+ }
+
+ @Override
+ public void onAnimationRepeat(Animator animation) {
+ // do not repeat
+ mAnimatableIcon.stop();
+ }
+ });
+ }
+ }
+
+ private void onIconAnimationFinish() {
+ if (mAnimationFinishListener != null) {
+ mAnimationFinishListener.run();
+ mAnimationFinishListener = null;
+ }
+ }
+
+ /**
+ * @hide
+ */
+ @TestApi
+ public boolean isIconAnimating() {
+ return mAnimatableIcon != null && mAnimator.isRunning();
+ }
+
+ /**
+ * @hide
+ */
+ public void startIntroAnimation(Runnable finishListener) {
+ if (mAnimatableIcon != null) {
+ mAnimationFinishListener = finishListener;
+ mAnimator.start();
+ } else if (finishListener != null) {
+ finishListener.run();
+ }
+ }
+
/**
* <p>Remove this view and release its resource. </p>
* <p><strong>Do not</strong> invoke this method from a drawing method
@@ -244,6 +323,7 @@ public final class SplashScreenView extends FrameLayout {
/**
* Get the view containing the Splash Screen icon and its background.
+ * @see android.R.attr#windowSplashScreenAnimatedIcon
*/
public @Nullable View getIconView() {
return mIconView;