Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae7ee3f3 authored by wilsonshih's avatar wilsonshih Committed by Vadim Caen
Browse files

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
parent 56f65c3b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1655,6 +1655,9 @@ package android {
    field public static final int windowShowAnimation = 16842934; // 0x10100b6
    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 public static final int windowSplashScreenBackground = 16844332; // 0x101062c
    field public static final int windowSplashscreenContent = 16844132; // 0x1010564
    field @Deprecated public static final int windowSwipeToDismiss = 16843763; // 0x10103f3
    field public static final int windowTitleBackgroundStyle = 16842844; // 0x101005c
+4 −0
Original line number Diff line number Diff line
@@ -2729,6 +2729,10 @@ package android.window {
    field public static final int FEATURE_WINDOW_TOKENS = 2; // 0x2
  }

  public final class SplashScreenView extends android.widget.FrameLayout {
    method public boolean isIconAnimating();
  }

  public final class StartingWindowInfo implements android.os.Parcelable {
    ctor public StartingWindowInfo();
    method public int describeContents();
+80 −0
Original line number Diff line number Diff line
@@ -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;
@@ -124,6 +134,14 @@ public final class SplashScreenView extends FrameLayout {
            return this;
        }

        /**
         * Set the animation duration if icon is animatable.
         */
        public Builder setAnimationDuration(int duration) {
            mIconAnimationDuration = duration;
            return this;
        }

        /**
         * Create SplashScreenWindowView object from materials.
         */
@@ -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;
+12 −0
Original line number Diff line number Diff line
@@ -2262,6 +2262,18 @@
            -->
            <enum name="always" value="3" />
        </attr>
        <!-- The background color for the splash screen, if not specify then system will
             calculate from windowBackground. -->
        <attr name="windowSplashScreenBackground" format="color"/>
        <!-- Replace an icon in the center of the starting window, if the object is animated
             and drawable(e.g. AnimationDrawable, AnimatedVectorDrawable), then it will also
             play the animation while showing the starting window. -->
        <attr name="windowSplashScreenAnimatedIcon" format="reference"/>
        <!-- The duration, in milliseconds, of the window splash screen icon animation duration
             when playing the splash screen starting window. The maximum animation duration should
             be limited below 1000ms. -->
        <attr name="windowSplashScreenAnimationDuration" format="integer"/>
    </declare-styleable>
    <!-- The set of attributes that describe a AlertDialog's theme. -->
+3 −0
Original line number Diff line number Diff line
@@ -3066,6 +3066,9 @@
    <public name="edgeEffectType" />
    <public name="knownCerts" />
    <public name="windowBackgroundBlurRadius"/>
    <public name="windowSplashScreenBackground"/>
    <public name="windowSplashScreenAnimatedIcon"/>
    <public name="windowSplashScreenAnimationDuration"/>
  </public-group>

  <public-group type="drawable" first-id="0x010800b5">
Loading