Skip to content

Commit 50a5588

Browse files
Lazzainfil00p
authored andcommitted
CB-12626: Updated Android plugin
This closes #125 Prefer a slightly slower, but bulletproof, way to check for the splashscreen instead of relying on the Cordova preferences. This fixes the splash screen on several phones.
1 parent 833dc7f commit 50a5588

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/android/SplashScreen.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ private View getView() {
7777
}
7878
}
7979

80+
private int getSplashId() {
81+
int drawableId = 0;
82+
String splashResource = preferences.getString("SplashScreen", "screen");
83+
if (splashResource != null) {
84+
drawableId = cordova.getActivity().getResources().getIdentifier(splashResource, "drawable", cordova.getActivity().getClass().getPackage().getName());
85+
if (drawableId == 0) {
86+
drawableId = cordova.getActivity().getResources().getIdentifier(splashResource, "drawable", cordova.getActivity().getPackageName());
87+
}
88+
}
89+
return drawableId;
90+
}
91+
8092
@Override
8193
protected void pluginInitialize() {
8294
if (HAS_BUILT_IN_SPLASH_SCREEN) {
@@ -90,17 +102,7 @@ public void run() {
90102
getView().setVisibility(View.INVISIBLE);
91103
}
92104
});
93-
int drawableId = preferences.getInteger("SplashDrawableId", 0);
94-
if (drawableId == 0) {
95-
String splashResource = preferences.getString("SplashScreen", "screen");
96-
if (splashResource != null) {
97-
drawableId = cordova.getActivity().getResources().getIdentifier(splashResource, "drawable", cordova.getActivity().getClass().getPackage().getName());
98-
if (drawableId == 0) {
99-
drawableId = cordova.getActivity().getResources().getIdentifier(splashResource, "drawable", cordova.getActivity().getPackageName());
100-
}
101-
//preferences.set("SplashDrawableId", drawableId);
102-
}
103-
}
105+
int drawableId = getSplashId();
104106

105107
// Save initial orientation.
106108
orientation = cordova.getActivity().getResources().getConfiguration().orientation;
@@ -205,7 +207,7 @@ public void onConfigurationChanged(Configuration newConfig) {
205207

206208
// Splash drawable may change with orientation, so reload it.
207209
if (splashImageView != null) {
208-
int drawableId = preferences.getInteger("SplashDrawableId", 0);
210+
int drawableId = getSplashId();
209211
if (drawableId != 0) {
210212
splashImageView.setImageDrawable(cordova.getActivity().getResources().getDrawable(drawableId));
211213
}
@@ -263,7 +265,7 @@ public void onAnimationRepeat(Animation animation) {
263265
@SuppressWarnings("deprecation")
264266
private void showSplashScreen(final boolean hideAfterDelay) {
265267
final int splashscreenTime = preferences.getInteger("SplashScreenDelay", DEFAULT_SPLASHSCREEN_DURATION);
266-
final int drawableId = preferences.getInteger("SplashDrawableId", 0);
268+
final int drawableId = getSplashId();
267269

268270
final int fadeSplashScreenDuration = getFadeDuration();
269271
final int effectiveSplashDuration = Math.max(0, splashscreenTime - fadeSplashScreenDuration);

0 commit comments

Comments
 (0)