Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ public void onServiceConnected(final Player connectedPlayer,
// let's make the video in fullscreen again
checkLandscape();
} else if (player.isFullscreen() && !player.isVerticalVideo()
// Tablet UI has orientation-independent fullscreen
&& !DeviceUtils.isTablet(activity)) {
// Tablet UI has orientation-independent fullscreen,
// large screens can't be rotated programmatically anyway
&& !DeviceUtils.isTablet(activity)
&& !DeviceUtils.isOrientationRequestIgnored(activity)) {
// Device is in portrait orientation after rotation but UI is in fullscreen.
// Return back to non-fullscreen state
player.toggleFullscreen();
Expand Down Expand Up @@ -2286,21 +2288,25 @@ public void onScreenRotationButtonClicked() {
final boolean isTablet = DeviceUtils.isTablet(activity);
final boolean autoLocked = globalScreenOrientationLocked(activity);

// 1. 平板且(系统可自动旋转 或 当前已横),直接切播放器全屏/非全屏
if (isTablet && (!autoLocked || isLandscape)) {
// 1. Tablet with auto-rotate enabled (or already in landscape): toggle player
// fullscreen directly. On large screens (sw >= 600dp, e.g. unfolded foldables)
// the system ignores setRequestedOrientation(), so rotating programmatically
// is impossible — toggle fullscreen directly there as well
if (isTablet && (!autoLocked || isLandscape)
|| DeviceUtils.isOrientationRequestIgnored(requireContext())) {
player.toggleFullscreen();
return;
}

// 2. 手机 or 平板但系统锁定了自动旋转,就去真正设置屏幕方向
// 2. Phone (or tablet with auto-rotate locked): actually change screen orientation
if (!autoLocked) {
if (isLandscape) {
player.toggleFullscreen();
} else {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
} else {
// 系统锁定时,再用“强制模式”来切
// Auto-rotate is locked, force the orientation change
activity.setRequestedOrientation(
isLandscape
? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -5002,6 +5002,9 @@ public void onVideoSizeChanged(@NonNull final VideoSize videoSize) {
&& service.isLandscape() == isVerticalVideo
&& !DeviceUtils.isTv(context)
&& !DeviceUtils.isTablet(context)
// can't rotate large screens programmatically, and with the
// fallback to toggleFullscreen() this would exit fullscreen
&& !DeviceUtils.isOrientationRequestIgnored(context)
&& fragmentListener != null) {
// set correct orientation
fragmentListener.onScreenRotationButtonClicked();
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ public static boolean isTablet(@NonNull final Context context) {
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

/**
* Whether the system ignores {@link android.app.Activity#setRequestedOrientation(int)}.
*
* <p>Since Android 12L, devices with a display at least 600dp wide (tablets, unfolded
* foldables) may ignore fixed-orientation requests; since Android 16 with targetSdk 36
* this is guaranteed. On such screens fullscreen has to be toggled without trying to
* change the screen orientation.</p>
*/
public static boolean isOrientationRequestIgnored(@NonNull final Context context) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2
&& context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
}

public static boolean isConfirmKey(final int keyCode) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
Expand Down