From 39c500f33ca6d8c0ea0a58733e2d685fca284b2b Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 14 Feb 2023 08:27:04 +0100 Subject: [PATCH] Revert "Use WindowCompat." --- .../fragments/detail/VideoDetailFragment.java | 59 +++++++++++-------- .../newpipe/player/ui/MainPlayerUi.java | 11 ++-- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 0fb137528..baf420409 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -27,6 +27,7 @@ import android.graphics.Color; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -54,9 +55,6 @@ import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; -import androidx.core.view.WindowCompat; -import androidx.core.view.WindowInsetsCompat; -import androidx.core.view.WindowInsetsControllerCompat; import androidx.preference.PreferenceManager; import com.google.android.exoplayer2.PlaybackException; @@ -1961,17 +1959,15 @@ public final class VideoDetailFragment return; } - final var window = activity.getWindow(); - final var windowInsetsController = WindowCompat.getInsetsController(window, - window.getDecorView()); - - WindowCompat.setDecorFitsSystemWindows(window, true); - windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat - .BEHAVIOR_SHOW_BARS_BY_TOUCH); - windowInsetsController.show(WindowInsetsCompat.Type.systemBars()); - - window.setStatusBarColor(ThemeHelper.resolveColorFromAttr(requireContext(), - android.R.attr.colorPrimary)); + // Prevent jumping of the player on devices with cutout + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + activity.getWindow().getAttributes().layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT; + } + activity.getWindow().getDecorView().setSystemUiVisibility(0); + activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + activity.getWindow().setStatusBarColor(ThemeHelper.resolveColorFromAttr( + requireContext(), android.R.attr.colorPrimary)); } private void hideSystemUi() { @@ -1983,19 +1979,30 @@ public final class VideoDetailFragment return; } - final var window = activity.getWindow(); - final var windowInsetsController = WindowCompat.getInsetsController(window, - window.getDecorView()); - - WindowCompat.setDecorFitsSystemWindows(window, false); - windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat - .BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); - windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()); - - if (DeviceUtils.isInMultiWindow(activity) || isFullscreen()) { - window.setStatusBarColor(Color.TRANSPARENT); - window.setNavigationBarColor(Color.TRANSPARENT); + // Prevent jumping of the player on devices with cutout + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + activity.getWindow().getAttributes().layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; } + int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + + // In multiWindow mode status bar is not transparent for devices with cutout + // if I include this flag. So without it is better in this case + final boolean isInMultiWindow = DeviceUtils.isInMultiWindow(activity); + if (!isInMultiWindow) { + visibility |= View.SYSTEM_UI_FLAG_FULLSCREEN; + } + activity.getWindow().getDecorView().setSystemUiVisibility(visibility); + + if (isInMultiWindow || isFullscreen()) { + activity.getWindow().setStatusBarColor(Color.TRANSPARENT); + activity.getWindow().setNavigationBarColor(Color.TRANSPARENT); + } + activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } // Listener implementation diff --git a/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java b/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java index a5c745ae6..683629c25 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java +++ b/app/src/main/java/org/schabi/newpipe/player/ui/MainPlayerUi.java @@ -32,6 +32,7 @@ import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; +import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.LinearLayout; @@ -39,8 +40,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.content.res.AppCompatResources; -import androidx.core.view.WindowCompat; -import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.FragmentActivity; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; @@ -453,9 +452,11 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh getParentActivity().map(Activity::getWindow).ifPresent(window -> { window.setStatusBarColor(Color.TRANSPARENT); window.setNavigationBarColor(Color.TRANSPARENT); - WindowCompat.setDecorFitsSystemWindows(window, false); - WindowCompat.getInsetsController(window, window.getDecorView()) - .show(WindowInsetsCompat.Type.systemBars()); + final int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; + window.getDecorView().setSystemUiVisibility(visibility); + window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); }); } }