8000 `PythonActivity.java`: my custom changes · hugfro/python-for-android@8d52334 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d52334

Browse files
committed
PythonActivity.java: my custom changes
1 parent 37cb53e commit 8d52334

File tree

1 file changed

+73
-5
lines changed

1 file changed

+73
-5
lines changed

pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonActivity.java

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.io.InputStream;
44
import java.io.FileWriter;
5+
import java.io.BufferedReader;
56
import java.io.File;
7+
import java.io.FileReader;
68
import java.io.IOException;
79
import java.lang.reflect.InvocationTargetException;
810
import java.util.ArrayList;
@@ -19,6 +21,8 @@
1921
import android.content.pm.PackageManager;
2022
import android.graphics.Bitmap;
2123
import android.graphics.BitmapFactory;
24+
import android.graphics.drawable.BitmapDrawable;
25+
import android.graphics.drawable.Drawable;
2226
import android.graphics.Color;
2327
import android.graphics.PixelFormat;
2428
import android.os.AsyncTask;
@@ -39,6 +43,9 @@
3943

4044
import org.renpy.android.ResourceManager;
4145

46+
import org.json.JSONArray;
47+
import org.json.JSONException;
48+
import org.json.JSONObject;
4249

4350
public class PythonActivity extends SDLActivity {
4451
private static final String TAG = "PythonActivity";
@@ -405,7 +412,12 @@ public void run() {
405412
});
406413
}
407414

415+
408416
public void removeLoadingScreen() {
417+
System.out.println("removeCalled");
418+
}
419+
420+
public void removeLoadingScreenMain() {
409421
runOnUiThread(new Runnable() {
410422
public void run() {
411423
View view = mLottieView != null ? mLottieView : mImageView;
@@ -448,7 +460,7 @@ protected void showLoadingScreen(View view) {
448460
}
449461
}
450462

451-
protected void setBackgroundColor(View view) {
463+
protected void setBackgroundColor(View view, String color) {
452464
/*
453465
* Set the presplash loading screen background color
454466
* https://developer.android.com/reference/android/graphics/Color.html
@@ -459,14 +471,39 @@ protected void setBackgroundColor(View view) {
459471
* 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuchsia',
460472
* 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'.
461473
*/
462-
String backgroundColor = resourceManager.getString("presplash_color");
474+
String backgroundColor = color;
463475
if (backgroundColor != null) {
464476
try {
465477
view.setBackgroundColor(Color.parseColor(backgroundColor));
466478
} catch (IllegalArgumentException e) {}
467479
}
468480
}
469481

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+
470507
protected View getLoadingScreen() {
471508
// If we have an mLottieView or mImageView already, then do
472509
// nothing because it will have already been made the content
@@ -495,14 +532,14 @@ protected View getLoadingScreen() {
495532
// (Gives error "The specified child already has a parent.
496533
// You must call removeView() on the child's parent first.")
497534
}
498-
setBackgroundColor(mLottieView);
535+
setBackgroundColor(mLottieView, "#FFFFFF");
499536
return mLottieView;
500537
}
501538
catch (NotFoundException e) {
502539
Log.v("SDL", "couldn't find lottie layout or animation, trying static splash");
503540
}
504541

505-
// no lottie asset, try to load the static image then
542+
// default (sets the bitmap)
506543
int presplashId = this.resourceManager.getIdentifier("presplash", "drawable");
507544
InputStream is = this.getResources().openRawResource(presplashId);
508545
Bitmap bitmap = null;
@@ -514,9 +551,40 @@ protected View getLoadingScreen() {
514551
} catch (IOException e) {};
515552
}
516553

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+
517585
mImageView = new ImageView(this);
518586
mImageView.setImageBitmap(bitmap);
519-
setBackgroundColor(mImageView);
587+
setBackgroundColor(mImageView, color);
520588

521589
mImageView.setLayoutParams(new ViewGroup.LayoutParams(
522590
ViewGroup.LayoutParams.FILL_PARENT,

0 commit comments

Comments
 (0)
0