Extract display height and only set for foldables

This commit is contained in:
Abandoned Cart 2023-04-22 15:17:11 -04:00 committed by skriand
parent 9742014f9b
commit 88f56d814d

View File

@ -128,6 +128,19 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
private var gameSurface : Surface? = null
private val displayHeight by lazy {
with (windowManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
maximumWindowMetrics.bounds.height()
} else {
val displayMetrics = DisplayMetrics()
@Suppress("DEPRECATION")
defaultDisplay.getMetrics(displayMetrics)
displayMetrics.heightPixels
}
}
}
/**
* This is the entry point into the emulation code for libskyline
*
@ -319,9 +332,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
WindowInfoTracker.getOrCreate(this@EmulationActivity)
.windowLayoutInfo(this@EmulationActivity)
.collect { newLayoutInfo ->
updateCurrentLayout(newLayoutInfo)
}
.collect { updateCurrentLayout(it) }
}
}
@ -505,19 +516,10 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
*/
private fun updateCurrentLayout(newLayoutInfo: WindowLayoutInfo) {
if (!emulationSettings.supportFoldableScreen) return
binding.onScreenGameView.minimumHeight = with (windowManager) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
maximumWindowMetrics.bounds.height()
} else {
val displayMetrics = DisplayMetrics()
@Suppress("DEPRECATION")
defaultDisplay.getMetrics(displayMetrics)
displayMetrics.heightPixels
}
}
requestedOrientation = emulationSettings.orientation
val foldingFeature = newLayoutInfo.displayFeatures.find { it is FoldingFeature }
(foldingFeature as? FoldingFeature)?.let {
binding.onScreenGameView.minimumHeight = displayHeight
requestedOrientation = emulationSettings.orientation
if (it.isSeparating) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
if (it.orientation == FoldingFeature.Orientation.HORIZONTAL)