Fixed wrong padding on devices with cutout on vertical videos
This commit is contained in:
parent
8030312924
commit
e833d415e3
|
@ -1499,9 +1499,10 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
// It doesn't include NavigationBar, notches, etc.
|
||||
display.getSize(size);
|
||||
|
||||
final boolean isLandscape = service.isLandscape();
|
||||
final int width = isFullscreen
|
||||
? (service.isLandscape()
|
||||
? size.x : size.y) : ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
? (isLandscape ? size.x : size.y)
|
||||
: ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
final int gravity = isFullscreen
|
||||
? (display.getRotation() == Surface.ROTATION_90
|
||||
? Gravity.START : Gravity.END)
|
||||
|
@ -1532,14 +1533,15 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
// And the situations when we need to set custom height is
|
||||
// in fullscreen mode in tablet in non-multiWindow mode or with vertical video.
|
||||
// Other than that MATCH_PARENT is good
|
||||
final boolean navBarAtTheBottom = DeviceUtils.isTablet(service) || !service.isLandscape();
|
||||
final boolean navBarAtTheBottom = DeviceUtils.isTablet(service) || !isLandscape;
|
||||
controlsRoot.getLayoutParams().height = isFullscreen && !isInMultiWindow()
|
||||
&& navBarAtTheBottom ? size.y : ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
controlsRoot.requestLayout();
|
||||
|
||||
final int topPadding = isFullscreen && !isInMultiWindow() ? getStatusBarHeight() : 0;
|
||||
getRootView().findViewById(R.id.playbackWindowRoot).setPadding(0, topPadding, 0, 0);
|
||||
getRootView().findViewById(R.id.playbackWindowRoot).requestLayout();
|
||||
int topPadding = isFullscreen && !isInMultiWindow() ? getStatusBarHeight() : 0;
|
||||
topPadding = !isLandscape && hasCutout(topPadding) ? 0 : topPadding;
|
||||
getRootView().findViewById(R.id.playbackWindowRoot).setTranslationY(topPadding);
|
||||
getBottomControlsRoot().setTranslationY(-topPadding);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1548,8 +1550,12 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
*/
|
||||
private int getStatusBarHeight() {
|
||||
int statusBarHeight = 0;
|
||||
final int resourceId = service.getResources().getIdentifier(
|
||||
"status_bar_height_landscape", "dimen", "android");
|
||||
final int resourceId = service.isLandscape()
|
||||
? service.getResources().getIdentifier(
|
||||
"status_bar_height_landscape", "dimen", "android")
|
||||
: service.getResources().getIdentifier(
|
||||
"status_bar_height", "dimen", "android");
|
||||
|
||||
if (resourceId > 0) {
|
||||
statusBarHeight = service.getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
|
@ -1563,6 +1569,20 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
return statusBarHeight;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compares current status bar height with default status bar height in Android and decides,
|
||||
* does the device has cutout or not
|
||||
* */
|
||||
private boolean hasCutout(final float statusBarHeight) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
final DisplayMetrics metrics = getRootView().getResources().getDisplayMetrics();
|
||||
final float defaultStatusBarHeight = TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, 25, metrics);
|
||||
return statusBarHeight > defaultStatusBarHeight;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void setMuteButton(final ImageButton button, final boolean isMuted) {
|
||||
button.setImageDrawable(AppCompatResources.getDrawable(service, isMuted
|
||||
? R.drawable.ic_volume_off_white_24dp : R.drawable.ic_volume_up_white_24dp));
|
||||
|
@ -2081,7 +2101,7 @@ public class VideoPlayerImpl extends VideoPlayer
|
|||
* This will be called when a user goes to another app/activity, turns off a screen.
|
||||
* We don't want to interrupt playback and don't want to see notification so
|
||||
* next lines of code will enable audio-only playback only if needed
|
||||
* */
|
||||
*/
|
||||
private void onFragmentStopped() {
|
||||
if (videoPlayerSelected() && (isPlaying() || isLoading())) {
|
||||
if (backgroundPlaybackEnabled()) {
|
||||
|
|
Loading…
Reference in New Issue