Skip to content

Commit 39c500f

Browse files
authored
Revert "Use WindowCompat."
1 parent e0cb289 commit 39c500f

2 files changed

Lines changed: 37 additions & 29 deletions

File tree

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

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.graphics.Rect;
2828
import android.graphics.drawable.Drawable;
2929
import android.net.Uri;
30+
import android.os.Build;
3031
import android.os.Bundle;
3132
import android.os.Handler;
3233
import android.os.Looper;
@@ -54,9 +55,6 @@
5455
import androidx.appcompat.widget.Toolbar;
5556
import androidx.coordinatorlayout.widget.CoordinatorLayout;
5657
import androidx.core.content.ContextCompat;
57-
import androidx.core.view.WindowCompat;
58-
import androidx.core.view.WindowInsetsCompat;
59-
import androidx.core.view.WindowInsetsControllerCompat;
6058
import androidx.preference.PreferenceManager;
6159

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

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

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

3839
import androidx.annotation.NonNull;
3940
import androidx.annotation.Nullable;
4041
import androidx.appcompat.app.AppCompatActivity;
4142
import androidx.appcompat.content.res.AppCompatResources;
42-
import androidx.core.view.WindowCompat;
43-
import androidx.core.view.WindowInsetsCompat;
4443
import androidx.fragment.app.FragmentActivity;
4544
import androidx.recyclerview.widget.ItemTouchHelper;
4645
import androidx.recyclerview.widget.RecyclerView;
@@ -453,9 +452,11 @@ public void showSystemUIPartially() {
453452
getParentActivity().map(Activity::getWindow).ifPresent(window -> {
454453
window.setStatusBarColor(Color.TRANSPARENT);
455454
window.setNavigationBarColor(Color.TRANSPARENT);
456-
WindowCompat.setDecorFitsSystemWindows(window, false);
457-
WindowCompat.getInsetsController(window, window.getDecorView())
458-
.show(WindowInsetsCompat.Type.systemBars());
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);
459460
});
460461
}
461462
}

0 commit comments

Comments
 (0)