Prevent crash with PiP if asked aspect ratio is < 1/2.39 or > to 2.39
This commit is contained in:
parent
61454f5923
commit
a72ee81ec6
3 changed files with 26 additions and 8 deletions
|
@ -65,10 +65,14 @@ class Api26Compatibility {
|
||||||
val params = PictureInPictureParams.Builder()
|
val params = PictureInPictureParams.Builder()
|
||||||
.setAspectRatio(Compatibility.getPipRatio(activity, conference, !conference))
|
.setAspectRatio(Compatibility.getPipRatio(activity, conference, !conference))
|
||||||
.build()
|
.build()
|
||||||
if (!activity.enterPictureInPictureMode(params)) {
|
try {
|
||||||
Log.e("[Call] Failed to enter PiP mode")
|
if (!activity.enterPictureInPictureMode(params)) {
|
||||||
} else {
|
Log.e("[Call] Failed to enter PiP mode")
|
||||||
Log.i("[Call] Entering PiP mode with ${if (conference) "portrait" else "landscape"} aspect ratio")
|
} else {
|
||||||
|
Log.i("[Call] Entering PiP mode with ${if (conference) "portrait" else "landscape"} aspect ratio")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("[Call] Can't build PiP params: $e")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,8 +215,12 @@ class Api31Compatibility {
|
||||||
.setAutoEnterEnabled(enable)
|
.setAutoEnterEnabled(enable)
|
||||||
.setAspectRatio(Compatibility.getPipRatio(activity, conference, !conference))
|
.setAspectRatio(Compatibility.getPipRatio(activity, conference, !conference))
|
||||||
.build()
|
.build()
|
||||||
activity.setPictureInPictureParams(params)
|
try {
|
||||||
Log.i("[Call] PiP auto enter enabled params set to $enable with ${if (conference) "portrait" else "landscape"} aspect ratio")
|
activity.setPictureInPictureParams(params)
|
||||||
|
Log.i("[Call] PiP auto enter enabled params set to $enable with ${if (conference) "portrait" else "landscape"} aspect ratio")
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e("[Call] Can't build PiP params: $e")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -287,8 +287,18 @@ class Compatibility {
|
||||||
): Rational {
|
): Rational {
|
||||||
val displayMetrics = DisplayMetrics()
|
val displayMetrics = DisplayMetrics()
|
||||||
activity.windowManager.defaultDisplay.getMetrics(displayMetrics)
|
activity.windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||||
val height = displayMetrics.heightPixels
|
var height = displayMetrics.heightPixels
|
||||||
val width = displayMetrics.widthPixels
|
var width = displayMetrics.widthPixels
|
||||||
|
|
||||||
|
val aspectRatio = width / height
|
||||||
|
if (aspectRatio < 1 / 2.39) {
|
||||||
|
height = 2.39.toInt()
|
||||||
|
width = 1
|
||||||
|
} else if (aspectRatio > 2.39) {
|
||||||
|
width = 2.39.toInt()
|
||||||
|
height = 1
|
||||||
|
}
|
||||||
|
|
||||||
val ratio = if (width > height) {
|
val ratio = if (width > height) {
|
||||||
if (forcePortrait) {
|
if (forcePortrait) {
|
||||||
Rational(height, width)
|
Rational(height, width)
|
||||||
|
|
Loading…
Reference in a new issue