android: cap popup width on tablets and large screens (#521)

On tablets in landscape mode, the AirPods connection popup covers the
entire screen because width is set to MATCH_PARENT. This caps the popup
width to 400dp on screens wider than 600dp and centers it horizontally.

Also removes a duplicate gravity assignment in init that was overwriting
the CENTER_HORIZONTAL flag.

Fixes #425

Co-authored-by: TomasULR <creator_d@nvias.org>
This commit is contained in:
Tomáš Ulrych
2026-04-22 12:41:33 -07:00
committed by GitHub
parent 2363b80548
commit 8f9a04390a

View File

@@ -64,10 +64,16 @@ class PopupWindow(
@Suppress("DEPRECATION")
private val mParams: WindowManager.LayoutParams = WindowManager.LayoutParams().apply {
height = WindowManager.LayoutParams.WRAP_CONTENT
width = WindowManager.LayoutParams.MATCH_PARENT
val displayMetrics = context.resources.displayMetrics
val screenWidthDp = displayMetrics.widthPixels / displayMetrics.density
width = if (screenWidthDp >= 600) {
(400 * displayMetrics.density).toInt()
} else {
WindowManager.LayoutParams.MATCH_PARENT
}
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
format = PixelFormat.TRANSLUCENT
gravity = Gravity.BOTTOM
gravity = Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL
dimAmount = 0.3f
flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or
WindowManager.LayoutParams.FLAG_FULLSCREEN or
@@ -84,7 +90,6 @@ class PopupWindow(
mParams.x = 0
mParams.y = 0
mParams.gravity = Gravity.BOTTOM
mView.setOnClickListener {
close()
}