Skip to content

Commit f766ef2

Browse files
Replace the system UI visibility flags with WindowCompat calls.
1 parent 1bb166a commit f766ef2

2 files changed

Lines changed: 29 additions & 37 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import android.graphics.Rect;
2828
import android.graphics.drawable.Drawable;
2929
import android.net.Uri;
30-
import android.os.Build;
3130
import android.os.Bundle;
3231
import android.os.Handler;
3332
import android.os.Looper;
@@ -55,6 +54,9 @@
5554
import androidx.appcompat.widget.Toolbar;
5655
import androidx.coordinatorlayout.widget.CoordinatorLayout;
5756
import androidx.core.content.ContextCompat;
57+
import androidx.core.view.WindowCompat;
58+
import androidx.core.view.WindowInsetsCompat;
59+
import androidx.core.view.WindowInsetsControllerCompat;
5860
import androidx.preference.PreferenceManager;
5961

6062
import 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

app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
import android.view.View;
3333
import android.view.ViewGroup;
3434
import android.view.ViewParent;
35-
import android.view.WindowManager;
3635
import android.widget.FrameLayout;
3736
import android.widget.LinearLayout;
3837

3938
import androidx.annotation.NonNull;
4039
import androidx.annotation.Nullable;
4140
import androidx.appcompat.app.AppCompatActivity;
4241
import androidx.appcompat.content.res.AppCompatResources;
42+
import androidx.core.view.WindowCompat;
43+
import androidx.core.view.WindowInsetsCompat;
4344
import androidx.fragment.app.FragmentActivity;
4445
import androidx.recyclerview.widget.ItemTouchHelper;
4546
import androidx.recyclerview.widget.RecyclerView;
@@ -451,11 +452,9 @@ public void showSystemUIPartially() {
451452
getParentActivity().map(Activity::getWindow).ifPresent(window -> {
452453
window.setStatusBarColor(Color.TRANSPARENT);
453454
window.setNavigationBarColor(Color.TRANSPARENT);
454-
final int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
455-
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
456-
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
457-
window.getDecorView().setSystemUiVisibility(visibility);
458-
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
455+
WindowCompat.setDecorFitsSystemWindows(window, false);
456+
WindowCompat.getInsetsController(window, window.getDecorView())
457+
.show(WindowInsetsCompat.Type.systemBars());
459458
});
460459
}
461460
}

0 commit comments

Comments
 (0)