2
2
3
3
import java .io .InputStream ;
4
4
import java .io .FileWriter ;
5
+ import java .io .BufferedReader ;
5
6
import java .io .File ;
7
+ import java .io .FileReader ;
6
8
import java .io .IOException ;
7
9
import java .lang .reflect .InvocationTargetException ;
8
10
import java .util .ArrayList ;
19
21
import android .content .pm .PackageManager ;
20
22
import android .graphics .Bitmap ;
21
23
import android .graphics .BitmapFactory ;
24
+ import android .graphics .drawable .BitmapDrawable ;
25
+ import android .graphics .drawable .Drawable ;
22
26
import android .graphics .Color ;
23
27
import android .graphics .PixelFormat ;
24
28
import android .os .AsyncTask ;
39
43
40
44
import org.renpy .android .ResourceManager ;
41
45
46
+ import org .json .JSONArray ;
47
+ import org .json .JSONException ;
48
+ import org .json .JSONObject ;
42
49
43
50
public class PythonActivity extends SDLActivity {
44
51
private static final String TAG = "PythonActivity" ;
@@ -405,7 +412,12 @@ public void run() {
405
412
});
406
413
}
407
414
415
+
408
416
public void removeLoadingScreen () {
417
+ System .out .println ("removeCalled" );
418
+ }
419
+
420
+ public void removeLoadingScreenMain () {
409
421
runOnUiThread (new Runnable () {
410
422
public void run () {
411
423
View view = mLottieView != null ? mLottieView : mImageView ;
@@ -448,7 +460,7 @@ protected void showLoadingScreen(View view) {
448
460
}
449
461
}
450
462
451
- protected void setBackgroundColor (View view ) {
463
+ protected void setBackgroundColor (View view , String color ) {
452
464
/*
453
465
* Set the presplash loading screen background color
454
466
* https://developer.android.com/reference/android/graphics/Color.html
@@ -459,14 +471,39 @@ protected void setBackgroundColor(View view) {
459
471
* 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuchsia',
460
472
* 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'.
461
473
*/
462
- String backgroundColor = resourceManager . getString ( "presplash_color" );
474
+ String backgroundColor = color ;
463
475
if (backgroundColor != null ) {
464
476
try {
465
477
view .setBackgroundColor (Color .parseColor (backgroundColor ));
466
478
} catch (IllegalArgumentException e ) {}
467
479
}
468
480
}
469
481
482
+
483
+ public static String readFileToString (String fileName ) {
484
+ StringBuilder stringBuilder = new StringBuilder ();
485
+
486
+ try {
487
+ BufferedReader bufferedReader = new BufferedReader (new FileReader (fileName ));
488
+ String line ;
489
+
490
+ while ((line = bufferedReader .readLine ()) != null ) {
491
+ stringBuilder .append (line ).append ("\n " );
492
+ }
493
+
494
+ bufferedReader .close ();
495
+ } catch (IOException e ) {
496
+ e .printStackTrace ();
497
+ }
498
+
499
+ return stringBuilder .toString ();
500
+ }
501
+
502
+ public static boolean isFileExists (String filePath ) {
503
+ File file = new File (filePath );
504
+ return file .exists ();
505
+ }
506
+
470
507
protected View getLoadingScreen () {
471
508
// If we have an mLottieView or mImageView already, then do
472
509
// nothing because it will have already been made the content
@@ -495,14 +532,14 @@ protected View getLoadingScreen() {
495
532
// (Gives error "The specified child already has a parent.
496
533
// You must call removeView() on the child's parent first.")
497
534
}
498
- setBackgroundColor (mLottieView );
535
+ setBackgroundColor (mLottieView , "#FFFFFF" );
499
536
return mLottieView ;
500
537
}
501
538
catch (NotFoundException e ) {
502
539
Log .v ("SDL" , "couldn't find lottie layout or animation, trying static splash" );
503
540
}
504
541
505
- // no lottie asset, try to load the static image then
542
+ // default (sets the bitmap)
506
543
int presplashId = this .resourceManager .getIdentifier ("presplash" , "drawable" );
507
544
InputStream is = this .getResources ().openRawResource (presplashId );
508
545
Bitmap bitmap = null ;
@@ -514,9 +551,40 @@ protected View getLoadingScreen() {
514
551
} catch (IOException e ) {};
515
552
}
516
553
554
+ String app_root = getFilesDir ().getAbsolutePath ();
555
+ String filePath = app_root + "/app/settings.json" ;
556
+ String color = resourceManager .getString ("presplash_color" );
557
+
558
+ if (isFileExists (filePath )) {
559
+
560
+ try {
561
+ JSONObject jsonObject = new JSONObject (readFileToString (filePath ));
562
+
563
+ if (jsonObject .has ("dark_mode" )) {
564
+ boolean darkMode = jsonObject .getBoolean ("dark_mode" );
565
+ if (darkMode ) {
566
+ bitmap = BitmapFactory .decodeFile (app_root + "/app/splash_dark.png" );
567
+ color = "#212121" ;
568
+ } else {
569
+ bitmap = BitmapFactory .decodeFile (app_root + "/app/splash_light.png&qu
A93C
ot; );
570
+ color = "#FAFAFA" ;
571
+ }
572
+ }
573
+ } catch (JSONException e ) {
574
+ e .printStackTrace ();
575
+ }
576
+
577
+ } else {
578
+ System .out .println ("[python]: Inital run??" );
579
+ }
580
+
581
+ window = mActivity .getWindow ();
582
+ window .setNavigationBarColor (Color .parseColor (color ));
583
+ window .setStatusBarColor (Color .parseColor (color ));
584
+
517
585
mImageView = new ImageView (this );
518
586
mImageView .setImageBitmap (bitmap );
519
- setBackgroundColor (mImageView );
587
+ setBackgroundColor (mImageView , color );
520
588
521
589
mImageView .setLayoutParams (new ViewGroup .LayoutParams (
522
590
ViewGroup .LayoutParams .FILL_PARENT ,
0 commit comments