2626import android .graphics .Rect ;
2727import android .graphics .drawable .Drawable ;
2828import android .net .Uri ;
29+ import android .os .Build ;
2930import android .os .Bundle ;
3031import android .os .Handler ;
3132import android .os .Looper ;
5354import androidx .appcompat .widget .Toolbar ;
5455import androidx .coordinatorlayout .widget .CoordinatorLayout ;
5556import androidx .core .content .ContextCompat ;
56- import androidx .core .view .WindowCompat ;
57- import androidx .core .view .WindowInsetsCompat ;
58- import androidx .core .view .WindowInsetsControllerCompat ;
5957import androidx .preference .PreferenceManager ;
6058
6159import com .google .android .exoplayer2 .PlaybackException ;
@@ -1928,17 +1926,15 @@ private void showSystemUi() {
19281926 return ;
19291927 }
19301928
1931- final var window = activity .getWindow ();
1932- final var windowInsetsController = WindowCompat .getInsetsController (window ,
1933- window .getDecorView ());
1934-
1935- WindowCompat .setDecorFitsSystemWindows (window , true );
1936- windowInsetsController .setSystemBarsBehavior (WindowInsetsControllerCompat
1937- .BEHAVIOR_SHOW_BARS_BY_TOUCH );
1938- windowInsetsController .show (WindowInsetsCompat .Type .systemBars ());
1939-
1940- window .setStatusBarColor (ThemeHelper .resolveColorFromAttr (requireContext (),
1941- android .R .attr .colorPrimary ));
1929+ // Prevent jumping of the player on devices with cutout
1930+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
1931+ activity .getWindow ().getAttributes ().layoutInDisplayCutoutMode =
1932+ WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT ;
1933+ }
1934+ activity .getWindow ().getDecorView ().setSystemUiVisibility (0 );
1935+ activity .getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
1936+ activity .getWindow ().setStatusBarColor (ThemeHelper .resolveColorFromAttr (
1937+ requireContext (), android .R .attr .colorPrimary ));
19421938 }
19431939
19441940 private void hideSystemUi () {
@@ -1950,19 +1946,30 @@ private void hideSystemUi() {
19501946 return ;
19511947 }
19521948
1953- final var window = activity .getWindow ();
1954- final var windowInsetsController = WindowCompat .getInsetsController (window ,
1955- window .getDecorView ());
1949+ // Prevent jumping of the player on devices with cutout
1950+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
1951+ activity .getWindow ().getAttributes ().layoutInDisplayCutoutMode =
1952+ WindowManager .LayoutParams .LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES ;
1953+ }
1954+ int visibility = View .SYSTEM_UI_FLAG_LAYOUT_STABLE
1955+ | View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1956+ | View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1957+ | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
1958+ | View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY ;
19561959
1957- WindowCompat .setDecorFitsSystemWindows (window , false );
1958- windowInsetsController .setSystemBarsBehavior (WindowInsetsControllerCompat
1959- .BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE );
1960- windowInsetsController .hide (WindowInsetsCompat .Type .systemBars ());
1960+ // In multiWindow mode status bar is not transparent for devices with cutout
1961+ // if I include this flag. So without it is better in this case
1962+ final boolean isInMultiWindow = DeviceUtils .isInMultiWindow (activity );
1963+ if (!isInMultiWindow ) {
1964+ visibility |= View .SYSTEM_UI_FLAG_FULLSCREEN ;
1965+ }
1966+ activity .getWindow ().getDecorView ().setSystemUiVisibility (visibility );
19611967
1962- if (DeviceUtils . isInMultiWindow ( activity ) || isFullscreen ()) {
1963- window .setStatusBarColor (Color .TRANSPARENT );
1964- window .setNavigationBarColor (Color .TRANSPARENT );
1968+ if (isInMultiWindow || isFullscreen ()) {
1969+ activity . getWindow () .setStatusBarColor (Color .TRANSPARENT );
1970+ activity . getWindow () .setNavigationBarColor (Color .TRANSPARENT );
19651971 }
1972+ activity .getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
19661973 }
19671974
19681975 // Listener implementation
0 commit comments