From 88f56d814d8cc07f857d2e4c07eb1d6e46a3384a Mon Sep 17 00:00:00 2001 From: Abandoned Cart Date: Sat, 22 Apr 2023 15:17:11 -0400 Subject: [PATCH] Extract display height and only set for foldables --- .../java/emu/skyline/EmulationActivity.kt | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/emu/skyline/EmulationActivity.kt b/app/src/main/java/emu/skyline/EmulationActivity.kt index 4dd9bf57..0b097487 100644 --- a/app/src/main/java/emu/skyline/EmulationActivity.kt +++ b/app/src/main/java/emu/skyline/EmulationActivity.kt @@ -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)