1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Replace the system UI visibility flags with WindowCompat calls.

This commit is contained in:
Isira Seneviratne 2022-08-28 06:41:38 +05:30
parent 1bb166a9e8
commit f766ef2033
2 changed files with 29 additions and 37 deletions

View File

@ -27,7 +27,6 @@ import android.graphics.Color;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
@ -55,6 +54,9 @@ import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat; 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 androidx.preference.PreferenceManager;
import com.google.android.exoplayer2.PlaybackException; import com.google.android.exoplayer2.PlaybackException;
@ -1962,15 +1964,17 @@ public final class VideoDetailFragment
return; return;
} }
// Prevent jumping of the player on devices with cutout final var window = activity.getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { final var windowInsetsController = WindowCompat.getInsetsController(window,
activity.getWindow().getAttributes().layoutInDisplayCutoutMode = window.getDecorView());
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
} WindowCompat.setDecorFitsSystemWindows(window, true);
activity.getWindow().getDecorView().setSystemUiVisibility(0); windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); .BEHAVIOR_SHOW_BARS_BY_TOUCH);
activity.getWindow().setStatusBarColor(ThemeHelper.resolveColorFromAttr( windowInsetsController.show(WindowInsetsCompat.Type.systemBars());
requireContext(), android.R.attr.colorPrimary));
window.setStatusBarColor(ThemeHelper.resolveColorFromAttr(requireContext(),
android.R.attr.colorPrimary));
} }
private void hideSystemUi() { private void hideSystemUi() {
@ -1982,30 +1986,19 @@ public final class VideoDetailFragment
return; return;
} }
// Prevent jumping of the player on devices with cutout final var window = activity.getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { final var windowInsetsController = WindowCompat.getInsetsController(window,
activity.getWindow().getAttributes().layoutInDisplayCutoutMode = window.getDecorView());
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 WindowCompat.setDecorFitsSystemWindows(window, false);
// if I include this flag. So without it is better in this case windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat
final boolean isInMultiWindow = DeviceUtils.isInMultiWindow(activity); .BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
if (!isInMultiWindow) { windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
visibility |= View.SYSTEM_UI_FLAG_FULLSCREEN;
}
activity.getWindow().getDecorView().setSystemUiVisibility(visibility);
if (isInMultiWindow || isFullscreen()) { if (DeviceUtils.isInMultiWindow(activity) || isFullscreen()) {
activity.getWindow().setStatusBarColor(Color.TRANSPARENT); window.setStatusBarColor(Color.TRANSPARENT);
activity.getWindow().setNavigationBarColor(Color.TRANSPARENT); window.setNavigationBarColor(Color.TRANSPARENT);
} }
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} }
// Listener implementation // Listener implementation

View File

@ -32,7 +32,6 @@ import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewParent; import android.view.ViewParent;
import android.view.WindowManager;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -40,6 +39,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -451,11 +452,9 @@ public final class MainPlayerUi extends VideoPlayerUi implements View.OnLayoutCh
getParentActivity().map(Activity::getWindow).ifPresent(window -> { getParentActivity().map(Activity::getWindow).ifPresent(window -> {
window.setStatusBarColor(Color.TRANSPARENT); window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT); window.setNavigationBarColor(Color.TRANSPARENT);
final int visibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE WindowCompat.setDecorFitsSystemWindows(window, false);
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN WindowCompat.getInsetsController(window, window.getDecorView())
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; .show(WindowInsetsCompat.Type.systemBars());
window.getDecorView().setSystemUiVisibility(visibility);
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}); });
} }
} }