Skip to content

Commit dd60471

Browse files
committed
sets visibility on resume, so navigation bar does not remain visible
when changing orientation.
1 parent f177f76 commit dd60471

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

core/src/processing/core/PApplet.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import android.graphics.*;
4141
import android.net.Uri;
4242
import android.opengl.GLSurfaceView;
43-
import android.os.Build;
4443
import android.os.Bundle;
4544
import android.os.Handler;
4645
import android.text.format.Time;
@@ -490,21 +489,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
490489
throw new RuntimeException(message);
491490
}
492491

493-
if (fullScreen) {
494-
int visibility;
495-
if (SDK < 19) {
496-
// Pre-4.4
497-
visibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
498-
} else {
499-
// 4.4 and higher. Equivalent to:
500-
// View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
501-
// View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
502-
// View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
503-
// so this line can be build with SDK < 4.4
504-
visibility = 256 | 512 | 1024 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | 4 | 2048 | 4096;
505-
}
506-
surfaceView.setSystemUiVisibility(visibility);
507-
}
492+
setFullScreenVisibility();
508493

509494
// Getting the display metrics only after setting fullscreen mode
510495
DisplayMetrics dm = new DisplayMetrics();
@@ -639,17 +624,42 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
639624
return rootView;
640625
}
641626

642-
643627
@Override
644628
public void onConfigurationChanged(Configuration newConfig) {
645629
if (DEBUG) System.out.println("configuration changed: " + newConfig);
646630
super.onConfigurationChanged(newConfig);
647631
}
648632

649633

634+
private void setFullScreenVisibility() {
635+
if (fullScreen) {
636+
int visibility;
637+
if (SDK < 19) {
638+
// Pre-4.4
639+
visibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
640+
} else {
641+
// 4.4 and higher. Integer instead of constants defined in View so it can
642+
// build with SDK < 4.4
643+
visibility = 256 | // View.SYSTEM_UI_FLAG_LAYOUT_STABLE
644+
512 | // View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
645+
1024 | // View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
646+
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
647+
4 | // View.SYSTEM_UI_FLAG_FULLSCREEN
648+
4096; // View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
649+
// However, this visibility does not fix a bug where the navigation area
650+
// turns black after resuming the app:
651+
// https://code.google.com/p/android/issues/detail?id=170752
652+
653+
visibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | 4096;
654+
}
655+
surfaceView.setSystemUiVisibility(visibility);
656+
}
657+
}
658+
650659
@Override
651660
public void onResume() {
652661
super.onResume();
662+
setFullScreenVisibility();
653663

654664
// TODO need to bring back app state here!
655665
// surfaceView.onResume();
@@ -665,6 +675,7 @@ public void onResume() {
665675
@Override
666676
public void onPause() {
667677
super.onPause();
678+
setFullScreenVisibility();
668679

669680
// TODO need to save all application state here!
670681
// System.out.println("PApplet.onPause() called");
@@ -4596,7 +4607,7 @@ public boolean saveJSONObject(JSONObject json, String filename, String options)
45964607
return json.save(saveFile(filename), options);
45974608
}
45984609

4599-
4610+
46004611
/**
46014612
* @webref input:files
46024613
* @param input String to parse as a JSONArray

0 commit comments

Comments
 (0)