2727import android .graphics .Rect ;
2828import android .graphics .drawable .Drawable ;
2929import android .net .Uri ;
30+ import android .os .Build ;
3031import android .os .Bundle ;
3132import android .os .Handler ;
3233import android .os .Looper ;
5455import androidx .appcompat .widget .Toolbar ;
5556import androidx .coordinatorlayout .widget .CoordinatorLayout ;
5657import androidx .core .content .ContextCompat ;
57- import androidx .core .view .WindowCompat ;
58- import androidx .core .view .WindowInsetsCompat ;
59- import androidx .core .view .WindowInsetsControllerCompat ;
6058import androidx .preference .PreferenceManager ;
6159
6260import com .google .android .exoplayer2 .PlaybackException ;
@@ -1961,17 +1959,15 @@ private void showSystemUi() {
19611959 return ;
19621960 }
19631961
1964- final var window = activity .getWindow ();
1965- final var windowInsetsController = WindowCompat .getInsetsController (window ,
1966- window .getDecorView ());
1967-
1968- WindowCompat .setDecorFitsSystemWindows (window , true );
1969- windowInsetsController .setSystemBarsBehavior (WindowInsetsControllerCompat
1970- .BEHAVIOR_SHOW_BARS_BY_TOUCH );
1971- windowInsetsController .show (WindowInsetsCompat .Type .systemBars ());
1972-
1973- window .setStatusBarColor (ThemeHelper .resolveColorFromAttr (requireContext (),
1974- android .R .attr .colorPrimary ));
1962+ // Prevent jumping of the player on devices with cutout
1963+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
1964+ activity .getWindow ().getAttributes ().layoutInDisplayCutoutMode =
1965+ WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT ;
1966+ }
1967+ activity .getWindow ().getDecorView ().setSystemUiVisibility (0 );
1968+ activity .getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
1969+ activity .getWindow ().setStatusBarColor (ThemeHelper .resolveColorFromAttr (
1970+ requireContext (), android .R .attr .colorPrimary ));
19751971 }
19761972
19771973 private void hideSystemUi () {
@@ -1983,19 +1979,30 @@ private void hideSystemUi() {
19831979 return ;
19841980 }
19851981
1986- final var window = activity .getWindow ();
1987- final var windowInsetsController = WindowCompat .getInsetsController (window ,
1988- window .getDecorView ());
1982+ // Prevent jumping of the player on devices with cutout
1983+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
1984+ activity .getWindow ().getAttributes ().layoutInDisplayCutoutMode =
1985+ WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES ;
1986+ }
1987+ int visibility = View .SYSTEM_UI_FLAG_LAYOUT_STABLE
1988+ | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1989+ | View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1990+ | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
1991+ | View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY ;
19891992
1990- WindowCompat .setDecorFitsSystemWindows (window , false );
1991- windowInsetsController .setSystemBarsBehavior (WindowInsetsControllerCompat
1992- .BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE );
1993- windowInsetsController .hide (WindowInsetsCompat .Type .systemBars ());
1993+ // In multiWindow mode status bar is not transparent for devices with cutout
1994+ // if I include this flag. So without it is better in this case
1995+ final boolean isInMultiWindow = DeviceUtils .isInMultiWindow (activity );
1996+ if (!isInMultiWindow ) {
1997+ visibility |= View .SYSTEM_UI_FLAG_FULLSCREEN ;
1998+ }
1999+ activity .getWindow ().getDecorView ().setSystemUiVisibility (visibility );
19942000
1995- if (DeviceUtils . isInMultiWindow ( activity ) || isFullscreen ()) {
1996- window .setStatusBarColor (Color .TRANSPARENT );
1997- window .setNavigationBarColor (Color .TRANSPARENT );
2001+ if (isInMultiWindow || isFullscreen ()) {
2002+ activity . getWindow () .setStatusBarColor (Color .TRANSPARENT );
2003+ activity . getWindow () .setNavigationBarColor (Color .TRANSPARENT );
19982004 }
2005+ activity .getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
19992006 }
20002007
20012008 // Listener implementation
0 commit comments