Skip to content

Commit d5a0f8f

Browse files
committed
Set opacity of the popup close button to 0.8 on Android 12 and higher
Setting this opacity should allow touches outside NewPipe when using the popup player. See https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_NOT_TOUCHABLE for more details.
1 parent 8441aff commit d5a0f8f

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ public final class PlayerHelper {
7878
private static final NumberFormat SPEED_FORMATTER = new DecimalFormat("0.##x");
7979
private static final NumberFormat PITCH_FORMATTER = new DecimalFormat("##%");
8080

81+
/**
82+
* Maximum opacity allowed for Android 12 and higher to allow touches on other apps when using
83+
* NewPipe's popup player.
84+
*
85+
* <p>
86+
* This value is hardcoded instead of being get dynamically with the method linked of the
87+
* constant documentation below, because it is not static and popup player layout parameters
88+
* are generated with static methods.
89+
* </p>
90+
*
91+
* @see WindowManager.LayoutParams#FLAG_NOT_TOUCHABLE
92+
*/
93+
private static final float MAXIMUM_OPACITY_ALLOWED_FOR_S_AND_HIGHER = 0.8f;
94+
8195
@Retention(SOURCE)
8296
@IntDef({AUTOPLAY_TYPE_ALWAYS, AUTOPLAY_TYPE_WIFI,
8397
AUTOPLAY_TYPE_NEVER})
@@ -572,6 +586,12 @@ public static WindowManager.LayoutParams buildCloseOverlayLayoutParams() {
572586
flags,
573587
PixelFormat.TRANSLUCENT);
574588

589+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
590+
// Setting maximum opacity allowed for touch events to other apps for Android 12 and
591+
// higher to prevent non interaction when using other apps with the popup player
592+
closeOverlayLayoutParams.alpha = MAXIMUM_OPACITY_ALLOWED_FOR_S_AND_HIGHER;
593+
}
594+
575595
closeOverlayLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
576596
closeOverlayLayoutParams.softInputMode =
577597
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;

0 commit comments

Comments
 (0)