From d6d217cb4ab3f60f46b626720da0531fc2cce2df Mon Sep 17 00:00:00 2001 From: xster Date: Tue, 15 Aug 2017 11:01:12 -0700 Subject: [PATCH] Add an explicit user configurable check for whether to keep showing the splash screen. (flutter/engine#3976) --- .../flutter/app/FlutterActivityDelegate.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java index 35fc8e92f8..697480ad4e 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java @@ -7,6 +7,7 @@ package io.flutter.app; 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; @@ -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); @@ -293,6 +294,9 @@ public final class FlutterActivityDelegate * 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; @@ -326,12 +330,23 @@ public final class FlutterActivityDelegate 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. *