diff options
| author | 2021-11-12 14:41:02 +0800 | |
|---|---|---|
| committer | 2022-01-03 20:44:01 +0800 | |
| commit | bf666289d7f669d54ea617f9c74838b3ca7c18f2 (patch) | |
| tree | a593194921118046afb4f11fbfbb6556e56af757 | |
| parent | 6a4c2b653e10381356c2e2b326a93974a647f178 (diff) | |
Public API set and get splashscreen style
Allow developer to control the splash screen style when the option is
used for cold or warm launch an activity.
Bug: 203497083
Test: atest SplashscreenTests#testLaunchFromLauncherWithEmptyIconOptions
Test: atest SplashscreenTests#testLaunchAppWithIconOptions
Change-Id: I9c4ccca2470df5dbac96da2d4a96b616b6670688
| -rw-r--r-- | core/api/current.txt | 3 | ||||
| -rw-r--r-- | core/java/android/app/ActivityOptions.java | 25 | ||||
| -rw-r--r-- | core/java/android/window/SplashScreen.java | 9 |
3 files changed, 24 insertions, 13 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 98d3a91c9944..e035ca60cc14 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -4464,6 +4464,7 @@ package android.app { method public android.app.ActivityOptions setLaunchDisplayId(int); method public android.app.ActivityOptions setLockTaskEnabled(boolean); method public void setPendingIntentBackgroundActivityLaunchAllowed(boolean); + method @NonNull public android.app.ActivityOptions setSplashScreenStyle(int); method public android.os.Bundle toBundle(); method public void update(android.app.ActivityOptions); field public static final String EXTRA_USAGE_TIME_REPORT = "android.activity.usage_time"; @@ -57667,6 +57668,8 @@ package android.window { method public void clearOnExitAnimationListener(); method public void setOnExitAnimationListener(@NonNull android.window.SplashScreen.OnExitAnimationListener); method public void setSplashScreenTheme(@StyleRes int); + field public static final int SPLASH_SCREEN_STYLE_EMPTY = 0; // 0x0 + field public static final int SPLASH_SCREEN_STYLE_ICON = 1; // 0x1 } public static interface SplashScreen.OnExitAnimationListener { diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java index f7d5e52e3675..5e5649f4eadf 100644 --- a/core/java/android/app/ActivityOptions.java +++ b/core/java/android/app/ActivityOptions.java @@ -337,7 +337,7 @@ public class ActivityOptions extends ComponentOptions { private static final String KEY_LAUNCHED_FROM_BUBBLE = "android.activity.launchTypeBubble"; - /** See {@link #setSplashscreenStyle(int)}. */ + /** See {@link #setSplashScreenStyle(int)}. */ private static final String KEY_SPLASH_SCREEN_STYLE = "android.activity.splashScreenStyle"; @@ -1393,20 +1393,27 @@ public class ActivityOptions extends ComponentOptions { } /** - * Sets the preferred splash screen style. + * Gets the style can be used for cold-launching an activity. + * @see #setSplashScreenStyle(int) * @hide */ - public void setSplashscreenStyle(@SplashScreen.SplashScreenStyle int style) { - mSplashScreenStyle = style; + public @SplashScreen.SplashScreenStyle int getSplashScreenStyle() { + return mSplashScreenStyle; } /** - * Gets the preferred splash screen style from caller - * @hide + * Sets the preferred splash screen style of the opening activities. This only applies if the + * Activity or Process is not yet created. + * @param style Can be either {@link SplashScreen#SPLASH_SCREEN_STYLE_ICON} or + * {@link SplashScreen#SPLASH_SCREEN_STYLE_EMPTY} */ - @SplashScreen.SplashScreenStyle - public int getSplashScreenStyle() { - return mSplashScreenStyle; + @NonNull + public ActivityOptions setSplashScreenStyle(@SplashScreen.SplashScreenStyle int style) { + if (style == SplashScreen.SPLASH_SCREEN_STYLE_ICON + || style == SplashScreen.SPLASH_SCREEN_STYLE_EMPTY) { + mSplashScreenStyle = style; + } + return this; } /** diff --git a/core/java/android/window/SplashScreen.java b/core/java/android/window/SplashScreen.java index 090dbff488e9..3f65f475fbd5 100644 --- a/core/java/android/window/SplashScreen.java +++ b/core/java/android/window/SplashScreen.java @@ -22,6 +22,7 @@ import android.annotation.StyleRes; import android.annotation.SuppressLint; import android.annotation.UiThread; import android.app.Activity; +import android.app.ActivityOptions; import android.app.ActivityThread; import android.app.AppGlobals; import android.content.Context; @@ -48,13 +49,13 @@ public interface SplashScreen { */ int SPLASH_SCREEN_STYLE_UNDEFINED = -1; /** - * Force splash screen to be empty. - * @hide + * Flag to be used with {@link ActivityOptions#setSplashScreenStyle}, to avoid showing the + * splash screen icon of the launched activity */ int SPLASH_SCREEN_STYLE_EMPTY = 0; /** - * Force splash screen to show icon. - * @hide + * Flag to be used with {@link ActivityOptions#setSplashScreenStyle}, to show the splash screen + * icon of the launched activity. */ int SPLASH_SCREEN_STYLE_ICON = 1; |