Skip to content

Commit 51af961

Browse files
authored
Merge pull request TeamNewPipe#8894 from Isira-Seneviratne/WindowCompat
Use WindowCompat.
2 parents 8699779 + f766ef2 commit 51af961

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;
@@ -1959,15 +1961,17 @@ private void showSystemUi() {
19591961
return;
19601962
}
19611963

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));
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));
19711975
}
19721976

19731977
private void hideSystemUi() {
@@ -1979,30 +1983,19 @@ private void hideSystemUi() {
19791983
return;
19801984
}
19811985

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;
1986+
final var window = activity.getWindow();
1987+
final var windowInsetsController = WindowCompat.getInsetsController(window,
1988+
window.getDecorView());
19921989

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);
1990+
WindowCompat.setDecorFitsSystemWindows(window, false);
1991+
windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat
1992+
.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
1993+
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
20001994

2001-
if (isInMultiWindow || isFullscreen()) {
2002-
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
2003-
activity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
1995+
if (DeviceUtils.isInMultiWindow(activity) || isFullscreen()) {
1996+
window.setStatusBarColor(Color.TRANSPARENT);
1997+
window.setNavigationBarColor(Color.TRANSPARENT);
20041998
}
2005-
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
20061999
}
20072000

20082001
// 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;
@@ -452,11 +453,9 @@ public void showSystemUIPartially() {
452453
getParentActivity().map(Activity::getWindow).ifPresent(window -> {
453454
window.setStatusBarColor(Color.TRANSPARENT);
454455
window.setNavigationBarColor(Color.TRANSPARENT);
455-
final int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
456-
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
457-
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
458-
window.getDecorView().setSystemUiVisibility(visibility);
459-
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
456+
WindowCompat.setDecorFitsSystemWindows(window, false);
457+
WindowCompat.getInsetsController(window, window.getDecorView())
458+
.show(WindowInsetsCompat.Type.systemBars());
460459
});
461460
}
462461
}

0 commit comments

Comments
 (0)