@@ -43,6 +43,7 @@ Licensed to the Apache Software Foundation (ASF) under one
4343import androidx .fragment .app .Fragment ;
4444
4545import org .apache .cordova .BuildConfig ;
46+ import org .apache .cordova .Config ;
4647import org .apache .cordova .ConfigXmlParser ;
4748import org .apache .cordova .CordovaInterfaceImpl ;
4849import org .apache .cordova .CordovaPreferences ;
@@ -109,6 +110,9 @@ public CordovaWebView getAppView() {
109110 // when another application (activity) is started.
110111 protected boolean keepRunning = true ;
111112
113+ // Flag to keep immersive mode if set to fullscreen
114+ protected boolean immersiveMode ;
115+
112116 // Read from config.xml:
113117 protected CordovaPreferences preferences ;
114118 protected String launchUrl ;
@@ -170,14 +174,17 @@ public void onCreate(Bundle savedInstanceState) {
170174 getActivity ().getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN ,
171175 WindowManager .LayoutParams .FLAG_FULLSCREEN );
172176 } else if (preferences .getBoolean ("Fullscreen" , false )) {
173- getActivity ().getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN ,
174- WindowManager .LayoutParams .FLAG_FULLSCREEN );
177+ if (!preferences .getBoolean ("FullscreenNotImmersive" , false )) {
178+ immersiveMode = true ;
179+ } else {
180+ getActivity ().getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN ,
181+ WindowManager .LayoutParams .FLAG_FULLSCREEN );
182+ }
175183 } else {
176184 getActivity ().getWindow ().setFlags (WindowManager .LayoutParams .FLAG_FORCE_NOT_FULLSCREEN ,
177185 WindowManager .LayoutParams .FLAG_FORCE_NOT_FULLSCREEN );
178186 }
179187
180-
181188 super .onCreate (savedInstanceState );
182189
183190 cordovaInterface = makeCordovaInterface ();
@@ -219,7 +226,7 @@ protected void loadConfig() {
219226 preferences .setPreferencesBundle (getActivity ().getIntent ().getExtras ());
220227 launchUrl = parser .getLaunchUrl ();
221228 pluginEntries = parser .getPluginEntries ();
222- // Config.parser = parser;
229+ // Config.parser = parser;
223230 }
224231
225232 //Suppressing warnings in AndroidStudio
@@ -234,9 +241,14 @@ protected void createViews() {
234241 setContentView (appView .getView ());
235242
236243 if (preferences .contains ("BackgroundColor" )) {
237- int backgroundColor = preferences .getInteger ("BackgroundColor" , Color .BLACK );
238- // Background of activity:
239- appView .getView ().setBackgroundColor (backgroundColor );
244+ try {
245+ int backgroundColor = preferences .getInteger ("BackgroundColor" , Color .BLACK );
246+ // Background of activity:
247+ appView .getView ().setBackgroundColor (backgroundColor );
248+ }
249+ catch (NumberFormatException e ){
250+ e .printStackTrace ();
251+ }
240252 }
241253
242254 appView .getView ().requestFocusFromTouch ();
@@ -284,11 +296,21 @@ public void onPause() {
284296 super .onPause ();
285297 LOG .d (TAG , "Paused the activity." );
286298
287- if (this .appView == null ) {
288- return ;
299+ if (this .appView != null ) {
300+ // CB-9382 If there is an activity that started for result and main activity is waiting for callback
301+ // result, we shoudn't stop WebView Javascript timers, as activity for result might be using them
302+ boolean keepRunning = this .keepRunning ;// || this.cordovaInterface.activityResultCallback != null;
303+ this .appView .handlePause (keepRunning );
289304 }
305+ }
290306
291- this .appView .handlePause (this .keepRunning );
307+ /**
308+ * Called when the activity receives a new intent
309+ */
310+ public void onNewIntent (Intent intent ) {
311+ //Forward to plugins
312+ if (this .appView != null )
313+ this .appView .onNewIntent (intent );
292314 }
293315
294316 /**
@@ -302,9 +324,11 @@ public void onResume() {
302324 if (this .appView == null ) {
303325 return ;
304326 }
305- // Force window to have focus, so application always
306- // receive user input. Workaround for some devices (Samsung Galaxy Note 3 at least)
307- this .getActivity ().getWindow ().getDecorView ().requestFocus ();
327+ if (!getActivity ().getWindow ().getDecorView ().hasFocus ()) {
328+ // Force window to have focus, so application always
329+ // receive user input. Workaround for some devices (Samsung Galaxy Note 3 at least)
330+ getActivity ().getWindow ().getDecorView ().requestFocus ();
331+ }
308332
309333 this .appView .handleResume (this .keepRunning );
310334 }
@@ -352,6 +376,22 @@ public void onDestroy() {
352376 }
353377 }
354378
379+ /**
380+ * Called when view focus is changed
381+ */
382+ public void onWindowFocusChanged (boolean hasFocus ) {
383+ if (hasFocus && immersiveMode ) {
384+ final int uiOptions = View .SYSTEM_UI_FLAG_LAYOUT_STABLE
385+ | View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
386+ | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
387+ | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
388+ | View .SYSTEM_UI_FLAG_FULLSCREEN
389+ | View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY ;
390+
391+ getActivity ().getWindow ().getDecorView ().setSystemUiVisibility (uiOptions );
392+ }
393+ }
394+
355395 @ Override
356396 public void startActivityForResult (Intent intent , int requestCode ) {
357397 // Capture requestCode here so that it is captured in the setActivityResultCallback() case.
0 commit comments