11package org .learningequality .Kolibri ;
22
33import android .app .Activity ;
4+ import android .os .Build ;
45import android .view .View ;
6+ import android .view .Window ;
7+ import android .view .WindowInsets ;
8+ import android .view .WindowInsetsController ;
59import android .webkit .WebChromeClient ;
610import android .widget .FrameLayout ;
711
@@ -32,15 +36,7 @@ public void onShowCustomView(View view, CustomViewCallback callback) {
3236 customViewCallback = callback ;
3337
3438 // Hide system UI for immersive fullscreen
35- activity
36- .getWindow ()
37- .getDecorView ()
38- .setSystemUiVisibility (
39- View .SYSTEM_UI_FLAG_FULLSCREEN
40- | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
41- | View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY
42- | View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
43- | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN );
39+ hideSystemUI ();
4440
4541 // Add the custom view to the fullscreen container
4642 fullscreenContainer .addView (customView );
@@ -59,12 +55,47 @@ public void onHideCustomView() {
5955 fullscreenContainer .setVisibility (View .GONE );
6056
6157 // Restore system UI
62- activity . getWindow (). getDecorView (). setSystemUiVisibility ( View . SYSTEM_UI_FLAG_VISIBLE );
58+ showSystemUI ( );
6359
6460 // Notify the callback
6561 if (customViewCallback != null ) {
6662 customViewCallback .onCustomViewHidden ();
6763 customViewCallback = null ;
6864 }
6965 }
66+
67+ private void hideSystemUI () {
68+ Window window = activity .getWindow ();
69+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
70+ WindowInsetsController controller = window .getInsetsController ();
71+ if (controller != null ) {
72+ controller .hide (WindowInsets .Type .statusBars () | WindowInsets .Type .navigationBars ());
73+ controller .setSystemBarsBehavior (
74+ WindowInsetsController .BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE );
75+ }
76+ } else {
77+ @ SuppressWarnings ("deprecation" )
78+ int flags =
79+ View .SYSTEM_UI_FLAG_FULLSCREEN
80+ | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
81+ | View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY
82+ | View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
83+ | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN ;
84+ window .getDecorView ().setSystemUiVisibility (flags );
85+ }
86+ }
87+
88+ private void showSystemUI () {
89+ Window window = activity .getWindow ();
90+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
91+ WindowInsetsController controller = window .getInsetsController ();
92+ if (controller != null ) {
93+ controller .show (WindowInsets .Type .statusBars () | WindowInsets .Type .navigationBars ());
94+ }
95+ } else {
96+ @ SuppressWarnings ("deprecation" )
97+ int flags = View .SYSTEM_UI_FLAG_VISIBLE ;
98+ window .getDecorView ().setSystemUiVisibility (flags );
99+ }
100+ }
70101}
0 commit comments