mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-05-22 16:59:11 +00:00
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:
@@ -64,10 +64,16 @@ class PopupWindow(
|
|||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
private val mParams: WindowManager.LayoutParams = WindowManager.LayoutParams().apply {
|
private val mParams: WindowManager.LayoutParams = WindowManager.LayoutParams().apply {
|
||||||
height = WindowManager.LayoutParams.WRAP_CONTENT
|
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
|
type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
|
||||||
format = PixelFormat.TRANSLUCENT
|
format = PixelFormat.TRANSLUCENT
|
||||||
gravity = Gravity.BOTTOM
|
gravity = Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL
|
||||||
dimAmount = 0.3f
|
dimAmount = 0.3f
|
||||||
flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or
|
flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or
|
||||||
WindowManager.LayoutParams.FLAG_FULLSCREEN or
|
WindowManager.LayoutParams.FLAG_FULLSCREEN or
|
||||||
@@ -84,7 +90,6 @@ class PopupWindow(
|
|||||||
mParams.x = 0
|
mParams.x = 0
|
||||||
mParams.y = 0
|
mParams.y = 0
|
||||||
|
|
||||||
mParams.gravity = Gravity.BOTTOM
|
|
||||||
mView.setOnClickListener {
|
mView.setOnClickListener {
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user