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
This commit is contained in:
daserge 2016-01-11 12:49:38 +03:00
parent 34bc1dbf16
commit 50318213c4
2 changed files with 43 additions and 9 deletions

View File

@ -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.

View File

@ -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);
}
}
});