1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package io.flutter.embedding.android; 6 7 import android.annotation.SuppressLint; 8 import android.content.Context; 9 import android.os.Bundle; 10 import android.support.annotation.NonNull; 11 import android.support.annotation.Nullable; 12 import android.view.View; 13 14 /** 15 * Splash screen configuration for a given Flutter experience. 16 * <p> 17 * Implementations provide a visual representation of a splash screen in 18 * {@link #createSplashView(Context, Bundle)}, and implement a transition from the 19 * splash UI to Flutter's UI in {@link #transitionToFlutter(Runnable)}. 20 */ 21 public interface SplashScreen { 22 /** 23 * Creates a {@code View} to be displayed as a splash screen before 24 * Flutter renders its first frame. 25 * <p> 26 * This method can be called at any time, and may be called multiple times depending on Android 27 * configuration changes that require recreation of a view hierarchy. Implementers that provide 28 * a stateful splash view, such as one with animations, should take care to migrate that 29 * animation state from the previously returned splash view to the newly created splash view. 30 */ 31 @Nullable createSplashView(@onNull Context context, @Nullable Bundle savedInstanceState)32 View createSplashView(@NonNull Context context, @Nullable Bundle savedInstanceState); 33 34 /** 35 * Invoked by Flutter when Flutter has rendered its first frame, and would like 36 * the {@code splashView} to disappear. 37 * <p> 38 * The provided {@code onTransitionComplete} callback must be invoked when 39 * the splash {@code View} has finished transitioning itself away. The splash 40 * {@code View} will be removed and destroyed when the callback is invoked. 41 */ transitionToFlutter(@onNull Runnable onTransitionComplete)42 void transitionToFlutter(@NonNull Runnable onTransitionComplete); 43 44 /** 45 * Returns {@code true} if the splash {@code View} built by this {@code SplashScreen} 46 * remembers its transition progress across configuration changes by saving that progress to 47 * {@code View} state. Returns {@code false} otherwise. 48 * <p> 49 * The typical return value for this method is {@code false}. When the return value is 50 * {@code false}, the following can happen: 51 * <ol> 52 * <li>Splash {@code View} begins transitioning to the Flutter UI. 53 * <li>A configuration change occurs, like an orientation change, and the {@code Activity} 54 * is re-created, along with the {@code View} hierarchy. 55 * <li>The remainder of the splash transition is skipped and the Flutter UI is displayed. 56 * </ol> 57 * In the vast majority of cases, skipping a little bit of the splash transition should be 58 * acceptable. Most users will never experience such a situation, and those that do are 59 * unlikely to notice the visual artifact. However, a workaround is available for those 60 * developers who need it. 61 * <p> 62 * Returning {@code true} from this method will cause the given splash {@code View} to be 63 * displayed in the {@code View} hierarchy, even if Flutter has already rendered its first 64 * frame. It is then the responsibility of the splash {@code View} to remember its previous 65 * transition progress, restart any animations, and then trigger its completion callback 66 * when appropriate. It is also the responsibility of the splash {@code View} to immediately 67 * invoke the completion callback if it has already completed its transition. By meeting 68 * these requirements, and returning {@code true} from this method, the splash screen 69 * experience will be completely seamless, including configuration changes. 70 */ 71 // We suppress NewApi because the CI linter thinks that "default" methods are unsupported. 72 @SuppressLint("NewApi") doesSplashViewRememberItsTransition()73 default boolean doesSplashViewRememberItsTransition() { 74 return false; 75 } 76 77 /** 78 * Returns whatever state is necessary to restore a splash {@code View} after destruction 79 * and recreation, e.g., orientation change. 80 */ 81 // We suppress NewApi because the CI linter thinks that "default" methods are unsupported. 82 @SuppressLint("NewApi") 83 @Nullable saveSplashScreenState()84 default Bundle saveSplashScreenState() { 85 return null; 86 } 87 } 88