Skip to content

Commit

Permalink
Add an explicit user configurable check for whether to keep showing t…
Browse files Browse the repository at this point in the history
…he splash screen. (flutter#3976)
  • Loading branch information
xster authored Aug 15, 2017
1 parent 07bc550 commit 08eb723
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions shell/platform/android/io/flutter/app/FlutterActivityDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
Expand Down Expand Up @@ -58,7 +59,7 @@ public final class FlutterActivityDelegate
implements FlutterActivityEvents,
FlutterView.Provider,
PluginRegistry {
private static final String LAUNCH_DRAWABLE_META_DATA_KEY = "io.flutter.app.LaunchScreen";
private static final String SPLASH_SCREEN_META_DATA_KEY = "io.flutter.app.android.SplashScreenUntilFirstFrame";
private static final String TAG = "FlutterActivityDelegate";
private static final LayoutParams matchParent =
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
Expand Down Expand Up @@ -293,6 +294,9 @@ private boolean loadIntent(Intent intent) {
* Returns null if no {@code windowBackground} is set for the activity.
*/
private View createLaunchView() {
if (!showSplashScreenUntilFirstFrame()) {
return null;
}
final Drawable launchScreenDrawable = getLaunchScreenDrawableFromActivityTheme();
if (launchScreenDrawable == null) {
return null;
Expand Down Expand Up @@ -326,12 +330,23 @@ private Drawable getLaunchScreenDrawableFromActivityTheme() {
try {
return activity.getResources().getDrawable(typedValue.resourceId);
} catch (NotFoundException e) {
Log.e(TAG, "Referenced launch screen drawable resource '"
+ LAUNCH_DRAWABLE_META_DATA_KEY + "' does not exist");
Log.e(TAG, "Referenced launch screen windowBackground resource does not exist");
return null;
}
}

private Boolean showSplashScreenUntilFirstFrame() {
try {
ActivityInfo activityInfo = activity.getPackageManager().getActivityInfo(
activity.getComponentName(),
PackageManager.GET_META_DATA|PackageManager.GET_ACTIVITIES);
Bundle metadata = activityInfo.metaData;
return metadata != null && metadata.getBoolean(SPLASH_SCREEN_META_DATA_KEY);
} catch (NameNotFoundException e) {
return false;
}
}

/**
* Sets the root content view of the activity.
*
Expand Down

0 comments on commit 08eb723

Please sign in to comment.