@@ -61,6 +61,7 @@ public class PythonActivity extends Activity {
6161 private ResourceManager resourceManager = null ;
6262 private Bundle mMetaData = null ;
6363 private PowerManager .WakeLock mWakeLock = null ;
64+ private int mPresplashColor = Color .BLACK ;
6465
6566 public String getAppRoot () {
6667 String app_root = getFilesDir ().getAbsolutePath () + "/app" ;
@@ -96,6 +97,25 @@ protected void onCreate(Bundle savedInstanceState) {
9697 resourceManager = new ResourceManager (this );
9798 super .onCreate (savedInstanceState );
9899
100+ /*
101+ * Try to parse background color for use in layout, webview, and presplash image
102+ * https://developer.android.com/reference/android/graphics/Color.html
103+ * Parse the color string, and return the corresponding color-int.
104+ * If the string cannot be parsed, throws an IllegalArgumentException exception.
105+ * Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
106+ * 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow',
107+ * 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuchsia',
108+ * 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'.
109+ */
110+ String backgroundColor = resourceManager .getString ("presplash_color" );
111+ if (backgroundColor != null ) {
112+ try {
113+ this .mPresplashColor = Color .parseColor (backgroundColor );
114+ } catch (IllegalArgumentException e ) {
115+ Log .e (TAG , "Invalid color string for presplash_color: " + backgroundColor );
116+ }
117+ }
118+
99119 this .mActivity = this ;
100120 this .showLoadingScreen ();
101121 new UnpackFilesTask ().execute (getAppRoot ());
@@ -158,6 +178,7 @@ public void onClick(DialogInterface dialog,int id) {
158178 String app_root_dir = getAppRoot ();
159179
160180 mWebView = new WebView (PythonActivity .mActivity );
181+ mWebView .setBackgroundColor (mPresplashColor );
161182 mWebView .getSettings ().setJavaScriptEnabled (true );
162183 mWebView .getSettings ().setDomStorageEnabled (true );
163184 mWebView .loadUrl ("file:///android_asset/_load.html" );
@@ -183,6 +204,7 @@ public void onPageFinished(WebView view, String url) {
183204 }
184205 });
185206 mLayout = new AbsoluteLayout (PythonActivity .mActivity );
207+ mLayout .setBackgroundColor (mPresplashColor );
186208 mLayout .addView (mWebView );
187209
188210 setContentView (mLayout );
@@ -333,23 +355,7 @@ protected void showLoadingScreen() {
333355
334356 mImageView = new ImageView (this );
335357 mImageView .setImageBitmap (bitmap );
336-
337- /*
338- * Set the presplash loading screen background color
339- * https://developer.android.com/reference/android/graphics/Color.html
340- * Parse the color string, and return the corresponding color-int.
341- * If the string cannot be parsed, throws an IllegalArgumentException exception.
342- * Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
343- * 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow',
344- * 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuchsia',
345- * 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'.
346- */
347- String backgroundColor = resourceManager .getString ("presplash_color" );
348- if (backgroundColor != null ) {
349- try {
350- mImageView .setBackgroundColor (Color .parseColor (backgroundColor ));
351- } catch (IllegalArgumentException e ) {}
352- }
358+ mImageView .setBackgroundColor (mPresplashColor );
353359 mImageView .setLayoutParams (new ViewGroup .LayoutParams (
354360 ViewGroup .LayoutParams .FILL_PARENT ,
355361 ViewGroup .LayoutParams .FILL_PARENT ));
0 commit comments