diff --git a/README.md b/README.md index 63ee109..9e6a435 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ You can use the following preferences in your `config.xml`: -### iOS Quirks +### Android and iOS Quirks - `FadeSplashScreen` (boolean, defaults to `true`): Set to `false` to prevent the splash screen from fading in and out when its display @@ -106,6 +106,24 @@ You can use the following preferences in your `config.xml`: Note also that this value used to be seconds, and not milliseconds, so values less than 30 will still be treated as seconds. ( Consider this a deprecated patch that will disapear in some future version. ) +_Note_: `FadeSplashScreenDuration` is included into `SplashScreenDelay`, for example if you have `` and `` defined in `config.xml`: + +- 00:00 - splashscreen is shown +- 00:02 - fading has started +- 00:03 - splashscreen is hidden + +Turning the fading off via `` technically means fading duration to be `0` so that in this example the overall splash delay will still be 3 seconds. + +_Note_: This only applies to the app startup - you need to take the fading timeout into account when manually showing/hiding the splashscreen in the code: + +```javascript +navigator.splashscreen.show(); +window.setTimeout(function () { + navigator.splashscreen.hide(); +}, splashDuration - fadeDuration); +``` + +### iOS Quirks - `ShowSplashScreenSpinner` (boolean, defaults to `true`): Set to `false` to hide the splash-screen spinner. diff --git a/src/android/SplashScreen.java b/src/android/SplashScreen.java index aa35b2d..7f91147 100644 --- a/src/android/SplashScreen.java +++ b/src/android/SplashScreen.java @@ -47,6 +47,7 @@ public class SplashScreen extends CordovaPlugin { // Cordova 3.x.x has a copy of this plugin bundled with it (SplashScreenInternal.java). // Enable functionality only if running on 4.x.x. private static final boolean HAS_BUILT_IN_SPLASH_SCREEN = Integer.valueOf(CordovaWebView.CORDOVA_VERSION.split("\\.")[0]) < 4; + private static final int DEFAULT_SPLASHSCREEN_DURATION = 3000; private static Dialog splashDialog; private static ProgressDialog spinnerDialog; private static boolean firstShow = true; @@ -107,6 +108,19 @@ public class SplashScreen extends CordovaPlugin { return preferences.getBoolean("SplashMaintainAspectRatio", false); } + private int getFadeDuration () { + int fadeSplashScreenDuration = preferences.getBoolean("FadeSplashScreen", true) == true ? + preferences.getInteger("FadeSplashScreenDuration", DEFAULT_SPLASHSCREEN_DURATION) : 0; + + if (fadeSplashScreenDuration < 30) { + // [CB-9750] This value used to be in decimal seconds, so we will assume that if someone specifies 10 + // they mean 10 seconds, and not the meaningless 10ms + fadeSplashScreenDuration *= 1000; + } + + return fadeSplashScreenDuration; + } + @Override public void onPause(boolean multitasking) { if (HAS_BUILT_IN_SPLASH_SCREEN) { @@ -200,12 +214,11 @@ public class SplashScreen extends CordovaPlugin { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { if (splashDialog != null && splashDialog.isShowing()) { - if (preferences.getBoolean("FadeSplashScreen", true)) { - final int splashscreenDuration = (int)(preferences.getDouble("FadeSplashScreenDuration", 2) * 1000); - + final int fadeSplashScreenDuration = getFadeDuration(); + if (fadeSplashScreenDuration > 0) { AlphaAnimation fadeOut = new AlphaAnimation(1, 0); - fadeOut.setInterpolator(new DecelerateInterpolator()); //add this - fadeOut.setDuration(splashscreenDuration); + fadeOut.setInterpolator(new DecelerateInterpolator()); + fadeOut.setDuration(fadeSplashScreenDuration); splashImageView.setAnimation(fadeOut); splashImageView.startAnimation(fadeOut); @@ -243,14 +256,17 @@ public class SplashScreen extends CordovaPlugin { */ @SuppressWarnings("deprecation") private void showSplashScreen(final boolean hideAfterDelay) { - final int splashscreenTime = preferences.getInteger("SplashScreenDelay", 3000); + final int splashscreenTime = preferences.getInteger("SplashScreenDelay", DEFAULT_SPLASHSCREEN_DURATION); final int drawableId = preferences.getInteger("SplashDrawableId", 0); + final int fadeSplashScreenDuration = getFadeDuration(); + final int effectiveSplashDuration = splashscreenTime - fadeSplashScreenDuration; + // If the splash dialog is showing don't try to show it again if (splashDialog != null && splashDialog.isShowing()) { return; } - if (drawableId == 0 || (splashscreenTime <= 0 && hideAfterDelay)) { + if (drawableId == 0 || (effectiveSplashDuration <= 0 && hideAfterDelay)) { return; } @@ -300,7 +316,7 @@ public class SplashScreen extends CordovaPlugin { public void run() { removeSplashScreen(); } - }, splashscreenTime); + }, effectiveSplashDuration); } } });