2727import android .graphics .Rect ;
2828import android .graphics .drawable .Drawable ;
2929import android .net .Uri ;
30- import android .os .Build ;
3130import android .os .Bundle ;
3231import android .os .Handler ;
3332import android .os .Looper ;
5554import androidx .appcompat .widget .Toolbar ;
5655import androidx .coordinatorlayout .widget .CoordinatorLayout ;
5756import androidx .core .content .ContextCompat ;
57+ import androidx .core .view .WindowCompat ;
58+ import androidx .core .view .WindowInsetsCompat ;
59+ import androidx .core .view .WindowInsetsControllerCompat ;
5860import androidx .preference .PreferenceManager ;
5961
6062import com .google .android .exoplayer2 .PlaybackException ;
@@ -1962,15 +1964,17 @@ private void showSystemUi() {
19621964 return ;
19631965 }
19641966
1965- // Prevent jumping of the player on devices with cutout
1966- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
1967- activity .getWindow ().getAttributes ().layoutInDisplayCutoutMode =
1968- WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT ;
1969- }
1970- activity .getWindow ().getDecorView ().setSystemUiVisibility (0 );
1971- activity .getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
1972- activity .getWindow ().setStatusBarColor (ThemeHelper .resolveColorFromAttr (
1973- requireContext (), android .R .attr .colorPrimary ));
1967+ final var window = activity .getWindow ();
1968+ final var windowInsetsController = WindowCompat .getInsetsController (window ,
1969+ window .getDecorView ());
1970+
1971+ WindowCompat .setDecorFitsSystemWindows (window , true );
1972+ windowInsetsController .setSystemBarsBehavior (WindowInsetsControllerCompat
1973+ .BEHAVIOR_SHOW_BARS_BY_TOUCH );
1974+ windowInsetsController .show (WindowInsetsCompat .Type .systemBars ());
1975+
1976+ window .setStatusBarColor (ThemeHelper .resolveColorFromAttr (requireContext (),
1977+ android .R .attr .colorPrimary ));
19741978 }
19751979
19761980 private void hideSystemUi () {
@@ -1982,30 +1986,19 @@ private void hideSystemUi() {
19821986 return ;
19831987 }
19841988
1985- // Prevent jumping of the player on devices with cutout
1986- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
1987- activity .getWindow ().getAttributes ().layoutInDisplayCutoutMode =
1988- WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES ;
1989- }
1990- int visibility = View .SYSTEM_UI_FLAG_LAYOUT_STABLE
1991- | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1992- | View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1993- | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
1994- | View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY ;
1989+ final var window = activity .getWindow ();
1990+ final var windowInsetsController = WindowCompat .getInsetsController (window ,
1991+ window .getDecorView ());
19951992
1996- // In multiWindow mode status bar is not transparent for devices with cutout
1997- // if I include this flag. So without it is better in this case
1998- final boolean isInMultiWindow = DeviceUtils .isInMultiWindow (activity );
1999- if (!isInMultiWindow ) {
2000- visibility |= View .SYSTEM_UI_FLAG_FULLSCREEN ;
2001- }
2002- activity .getWindow ().getDecorView ().setSystemUiVisibility (visibility );
1993+ WindowCompat .setDecorFitsSystemWindows (window , false );
1994+ windowInsetsController .setSystemBarsBehavior (WindowInsetsControllerCompat
1995+ .BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE );
1996+ windowInsetsController .hide (WindowInsetsCompat .Type .systemBars ());
20031997
2004- if (isInMultiWindow || isFullscreen ()) {
2005- activity . getWindow () .setStatusBarColor (Color .TRANSPARENT );
2006- activity . getWindow () .setNavigationBarColor (Color .TRANSPARENT );
1998+ if (DeviceUtils . isInMultiWindow ( activity ) || isFullscreen ()) {
1999+ window .setStatusBarColor (Color .TRANSPARENT );
2000+ window .setNavigationBarColor (Color .TRANSPARENT );
20072001 }
2008- activity .getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
20092002 }
20102003
20112004 // Listener implementation
0 commit comments