Skip to content

Commit

Permalink
Moved device-specific code into DeviceUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
avently committed Sep 3, 2020
1 parent e833d41 commit b8a35e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
17 changes: 2 additions & 15 deletions app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1538,8 +1538,9 @@ public void setControlsSize() {
&& navBarAtTheBottom ? size.y : ViewGroup.LayoutParams.MATCH_PARENT;
controlsRoot.requestLayout();

final DisplayMetrics metrics = getRootView().getResources().getDisplayMetrics();
int topPadding = isFullscreen && !isInMultiWindow() ? getStatusBarHeight() : 0;
topPadding = !isLandscape && hasCutout(topPadding) ? 0 : topPadding;
topPadding = !isLandscape && DeviceUtils.hasCutout(topPadding, metrics) ? 0 : topPadding;
getRootView().findViewById(R.id.playbackWindowRoot).setTranslationY(topPadding);
getBottomControlsRoot().setTranslationY(-topPadding);
}
Expand Down Expand Up @@ -1569,20 +1570,6 @@ private int getStatusBarHeight() {
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));
Expand Down
15 changes: 15 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 @@ -6,6 +6,8 @@
import android.content.res.Configuration;
import android.os.BatteryManager;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.KeyEvent;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -72,4 +74,17 @@ public static boolean isConfirmKey(final int keyCode) {
return false;
}
}

/*
* Compares current status bar height with default status bar height in Android and decides,
* does the device has cutout or not
* */
public static boolean hasCutout(final float statusBarHeight, final DisplayMetrics metrics) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
final float defaultStatusBarHeight = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 25, metrics);
return statusBarHeight > defaultStatusBarHeight;
}
return false;
}
}

0 comments on commit b8a35e9

Please sign in to comment.