From 56fab8b2f130ecf231d95ff5fb0a7a3e0b74a7dd Mon Sep 17 00:00:00 2001 From: Philipp Grosswiler Date: Thu, 6 Aug 2015 16:29:41 +0700 Subject: [PATCH 1/3] Added support for FadeSplashScreen. --- src/android/SplashScreen.java | 37 ++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/android/SplashScreen.java b/src/android/SplashScreen.java index 75ad724c..af89da20 100644 --- a/src/android/SplashScreen.java +++ b/src/android/SplashScreen.java @@ -30,6 +30,8 @@ Licensed to the Apache Software Foundation (ASF) under one import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; +import android.view.animation.Animation; +import android.view.animation.AlphaAnimation; import android.widget.ImageView; import android.widget.LinearLayout; @@ -194,9 +196,38 @@ private void removeSplashScreen() { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { if (splashDialog != null && splashDialog.isShowing()) { - splashDialog.dismiss(); - splashDialog = null; - splashImageView = null; + if (preferences.getBoolean("FadeSplashScreen", true)) { + final int splashscreenDuration = preferences.getInteger("FadeSplashScreenDuration", 2) * 1000; + + AlphaAnimation fadeOut = new AlphaAnimation(1, 0); + fadeOut.setDuration(splashscreenDuration); + + splashImageView.setAnimation(fadeOut); + splashImageView.startAnimation(fadeOut); + + fadeOut.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + } + + @Override + public void onAnimationEnd(Animation animation) { + if (splashDialog != null && splashDialog.isShowing()) { + splashDialog.dismiss(); + splashDialog = null; + splashImageView = null; + } + } + + @Override + public void onAnimationRepeat(Animation animation) { + } + }); + } else { + splashDialog.dismiss(); + splashDialog = null; + splashImageView = null; + } } } }); From 386f0d9b74083fdf4464791d48a5af638b78572e Mon Sep 17 00:00:00 2001 From: Philipp Grosswiler Date: Fri, 7 Aug 2015 09:23:11 +0700 Subject: [PATCH 2/3] Added DecelerateInterpolator for smoother fading experience. --- src/android/SplashScreen.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/android/SplashScreen.java b/src/android/SplashScreen.java index af89da20..691935a9 100644 --- a/src/android/SplashScreen.java +++ b/src/android/SplashScreen.java @@ -32,6 +32,7 @@ Licensed to the Apache Software Foundation (ASF) under one import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.AlphaAnimation; +import android.view.animation.DecelerateInterpolator; import android.widget.ImageView; import android.widget.LinearLayout; @@ -200,6 +201,7 @@ public void run() { final int splashscreenDuration = preferences.getInteger("FadeSplashScreenDuration", 2) * 1000; AlphaAnimation fadeOut = new AlphaAnimation(1, 0); + fadeOut.setInterpolator(new DecelerateInterpolator()); //add this fadeOut.setDuration(splashscreenDuration); splashImageView.setAnimation(fadeOut); From 4f104c2460dbc177aade15958fd91de1968543f0 Mon Sep 17 00:00:00 2001 From: Philipp Grosswiler Date: Fri, 7 Aug 2015 22:31:16 +0700 Subject: [PATCH 3/3] Fixed reading preference as Float instead of Integer (thanks to spiritax for pointing this out). --- src/android/SplashScreen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/SplashScreen.java b/src/android/SplashScreen.java index 691935a9..e3444a52 100644 --- a/src/android/SplashScreen.java +++ b/src/android/SplashScreen.java @@ -198,7 +198,7 @@ private void removeSplashScreen() { public void run() { if (splashDialog != null && splashDialog.isShowing()) { if (preferences.getBoolean("FadeSplashScreen", true)) { - final int splashscreenDuration = preferences.getInteger("FadeSplashScreenDuration", 2) * 1000; + final int splashscreenDuration = (int)(preferences.getDouble("FadeSplashScreenDuration", 2) * 1000); AlphaAnimation fadeOut = new AlphaAnimation(1, 0); fadeOut.setInterpolator(new DecelerateInterpolator()); //add this