You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by da...@apache.org on 2016/01/11 11:03:18 UTC

[2/2] cordova-plugin-splashscreen git commit: CB-9538 Implementing FadeSplashScreen feature for Android

CB-9538 Implementing FadeSplashScreen feature for Android

Refactoring, adds support of seconds for fade duration for backward compatibility
Includes fade duration into overall splashscreen duration to be consistent with iOS
Updated the docs


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/commit/50318213
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/tree/50318213
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/diff/50318213

Branch: refs/heads/master
Commit: 50318213c4a00ff233937f5c9a147e3542848840
Parents: 34bc1db
Author: daserge <v-...@microsoft.com>
Authored: Mon Jan 11 12:49:38 2016 +0300
Committer: daserge <v-...@microsoft.com>
Committed: Mon Jan 11 12:49:38 2016 +0300

----------------------------------------------------------------------
 README.md                     | 20 +++++++++++++++++++-
 src/android/SplashScreen.java | 32 ++++++++++++++++++++++++--------
 2 files changed, 43 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/blob/50318213/README.md
----------------------------------------------------------------------
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`:
     </platform>
 
 
-### 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 `<preference name="SplashScreenDelay" value="3000" />` and `<preference name="FadeSplashScreenDuration" value="1000"/>` defined in `config.xml`:
+
+- 00:00 - splashscreen is shown
+- 00:02 - fading has started
+- 00:03 - splashscreen is hidden
+
+Turning the fading off via `<preference name="FadeSplashScreen" value="false"/>` 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.

http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen/blob/50318213/src/android/SplashScreen.java
----------------------------------------------------------------------
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);
                 }
             }
         });


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org