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 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 * 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) { lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
WindowInfoTracker.getOrCreate(this@EmulationActivity) WindowInfoTracker.getOrCreate(this@EmulationActivity)
.windowLayoutInfo(this@EmulationActivity) .windowLayoutInfo(this@EmulationActivity)
.collect { newLayoutInfo -> .collect { updateCurrentLayout(it) }
updateCurrentLayout(newLayoutInfo)
}
} }
} }
@ -505,19 +516,10 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
*/ */
private fun updateCurrentLayout(newLayoutInfo: WindowLayoutInfo) { private fun updateCurrentLayout(newLayoutInfo: WindowLayoutInfo) {
if (!emulationSettings.supportFoldableScreen) return 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 } val foldingFeature = newLayoutInfo.displayFeatures.find { it is FoldingFeature }
(foldingFeature as? FoldingFeature)?.let { (foldingFeature as? FoldingFeature)?.let {
binding.onScreenGameView.minimumHeight = displayHeight
requestedOrientation = emulationSettings.orientation
if (it.isSeparating) { if (it.isSeparating) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) if (it.orientation == FoldingFeature.Orientation.HORIZONTAL)