Compare commits

...

9 Commits

Author SHA1 Message Date
Jan Piotrowski
480780768e
add android support for splash screen theme and background color. 2018-09-24 23:50:06 +02:00
filmaj
3bd0f289d7 Merge branch 'master' into 4.0.x 2017-04-27 13:05:10 -07:00
Steve Gill
7045e6c260 CB-12519 Updated version and RELEASENOTES.md for release 4.0.2 2017-03-02 16:47:18 -08:00
daserge
3409a86c0b CB-12353 Corrected merges usage in plugin.xml 2017-03-02 16:47:18 -08:00
Nikita Matrosov
2e1a6d5d22 CB-12369: Add plugin typings from DefinitelyTyped
This closes #123
2017-03-02 16:47:18 -08:00
Alexander Sorokin
5172dbbf23 CB-12363 Added build badges for iOS 9.3 and 10.0 2017-03-02 16:47:18 -08:00
Alexander Sorokin
4ba6c91959 CB-12230 Removed Windows 8.1 build badges 2017-03-02 16:47:18 -08:00
Shazron Abdullah
361b8f15c9 CB-12224 Incremented plugin version. 2017-03-02 16:47:18 -08:00
Shazron Abdullah
5aebc9c085 CB-12236 - Fixed RELEASENOTES for cordova-plugin-splashscreen 2016-12-12 11:23:28 -08:00

View File

@ -19,18 +19,22 @@
package org.apache.cordova.splashscreen;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AlphaAnimation;
@ -90,6 +94,35 @@ public class SplashScreen extends CordovaPlugin {
getView().setVisibility(View.INVISIBLE);
}
});
// Save theme id if specified
int themeId = preferences.getInteger( "SplashScreenThemeId", 0 );
if ( themeId == 0 ) {
String theme = preferences.getString( "SplashScreenTheme", null );
if ( theme != null ) {
Activity activity = cordova.getActivity();
Resources resources = activity.getResources();
themeId = resources.getIdentifier(
theme, "style", activity.getPackageName() );
if (themeId == 0) {
themeId = resources.getIdentifier(
theme, "style", "android" );
}
}
if ( themeId == 0 ) {
themeId = android.R.style.Theme_Translucent_NoTitleBar;
}
preferences.set( "SplashScreenThemeId", themeId );
}
int drawableId = preferences.getInteger("SplashDrawableId", 0);
if (drawableId == 0) {
String splashResource = preferences.getString("SplashScreen", "screen");
@ -122,6 +155,13 @@ public class SplashScreen extends CordovaPlugin {
return preferences.getBoolean("SplashMaintainAspectRatio", false);
}
private boolean isActivityFullScreen() {
int flags = cordova.getActivity().getWindow().getAttributes().flags;
int fullScreenFlag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
return (( flags & fullScreenFlag ) == fullScreenFlag );
}
private int getFadeDuration () {
int fadeSplashScreenDuration = preferences.getBoolean("FadeSplashScreen", true) ?
preferences.getInteger("FadeSplashScreenDuration", DEFAULT_FADE_DURATION) : 0;
@ -263,13 +303,41 @@ public class SplashScreen extends CordovaPlugin {
@SuppressWarnings("deprecation")
private void showSplashScreen(final boolean hideAfterDelay) {
final int splashscreenTime = preferences.getInteger("SplashScreenDelay", DEFAULT_SPLASHSCREEN_DURATION);
final int themeId = preferences.getInteger( "SplashScreenThemeId", 0 );
final int drawableId = preferences.getInteger("SplashDrawableId", 0);
final int fadeSplashScreenDuration = getFadeDuration();
final int effectiveSplashDuration = Math.max(0, splashscreenTime - fadeSplashScreenDuration);
final int backgroundColor;
if ( preferences.contains( "SplashScreenBackgroundColor" ) ) {
backgroundColor = preferences.getInteger(
"SplashScreenBackgroundColor", 0 );
}
else {
// TODO: Use the background color of the webView's parent instead of using the preference.
backgroundColor = preferences.getInteger(
"backgroundColor", Color.BLACK );
}
final ImageView.ScaleType scaleType;
if (isMaintainAspectRatio()) {
// CENTER_CROP scale mode is equivalent to CSS "background-size:cover"
scaleType = ImageView.ScaleType.CENTER_CROP;
}
else {
// FIT_XY scales image non-uniformly to fit into image view.
scaleType = ImageView.ScaleType.FIT_XY;
}
lastHideAfterDelay = hideAfterDelay;
// Prevent to show the splash dialog if the activity is in the process of finishing
if (cordova.getActivity().isFinishing()) {
return;
}
// If the splash dialog is showing don't try to show it again
if (splashDialog != null && splashDialog.isShowing()) {
return;
@ -287,32 +355,26 @@ public class SplashScreen extends CordovaPlugin {
// Use an ImageView to render the image because of its flexible scaling options.
splashImageView = new ImageView(context);
splashImageView.setImageResource(drawableId);
LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
splashImageView.setLayoutParams(layoutParams);
splashImageView.setLayoutParams(
new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT ) );
splashImageView.setMinimumHeight(display.getHeight());
splashImageView.setMinimumWidth(display.getWidth());
// TODO: Use the background color of the webView's parent instead of using the preference.
splashImageView.setBackgroundColor(preferences.getInteger("backgroundColor", Color.BLACK));
if (isMaintainAspectRatio()) {
// CENTER_CROP scale mode is equivalent to CSS "background-size:cover"
splashImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
else {
// FIT_XY scales image non-uniformly to fit into image view.
splashImageView.setScaleType(ImageView.ScaleType.FIT_XY);
}
splashImageView.setBackgroundColor( backgroundColor );
splashImageView.setScaleType( scaleType );
// Create and show the dialog
splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
splashDialog = new Dialog( context, themeId );
// check to see if the splash screen should be full screen
if ((cordova.getActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
== WindowManager.LayoutParams.FLAG_FULLSCREEN) {
splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
if ( isActivityFullScreen() ) {
splashDialog.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN );
}
splashDialog.setContentView(splashImageView);
splashDialog.setCancelable(false);
splashDialog.show();