From 9742014f9baf9d57359d80ac0d9eb83b14ec6204 Mon Sep 17 00:00:00 2001 From: Abandoned Cart Date: Sat, 22 Apr 2023 09:03:54 -0400 Subject: [PATCH] Fix and make foldable screen support optional --- .../java/emu/skyline/EmulationActivity.kt | 37 +++++++++---------- .../emu/skyline/settings/EmulationSettings.kt | 1 + app/src/main/res/values/array.xml | 2 - app/src/main/res/values/strings.xml | 3 ++ .../main/res/xml/emulation_preferences.xml | 6 +++ 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/emu/skyline/EmulationActivity.kt b/app/src/main/java/emu/skyline/EmulationActivity.kt index 0adc35ae..4dd9bf57 100644 --- a/app/src/main/java/emu/skyline/EmulationActivity.kt +++ b/app/src/main/java/emu/skyline/EmulationActivity.kt @@ -504,27 +504,26 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo * Updating the layout depending on type and state of device */ private fun updateCurrentLayout(newLayoutInfo: WindowLayoutInfo) { - val displayMetrics = DisplayMetrics() - windowManager.defaultDisplay.getMetrics(displayMetrics) - binding.onScreenGameView.minimumHeight = displayMetrics.heightPixels - requestedOrientation = - if (emulationSettings.orientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { - emulationSettings.orientation + if (!emulationSettings.supportFoldableScreen) return + binding.onScreenGameView.minimumHeight = with (windowManager) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + maximumWindowMetrics.bounds.height() } else { - ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + val displayMetrics = DisplayMetrics() + @Suppress("DEPRECATION") + defaultDisplay.getMetrics(displayMetrics) + displayMetrics.heightPixels } - for (displayFeature in newLayoutInfo.displayFeatures) { - val foldFeature = displayFeature as? FoldingFeature - foldFeature?.let { - //Folding feature separates the display area into two distinct sections - if (it.isSeparating) { - if (emulationSettings.orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED){ - requestedOrientation = emulationSettings.orientation - } - if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) { - binding.onScreenGameView.minimumHeight = displayFeature.bounds.top - } - } + } + requestedOrientation = emulationSettings.orientation + val foldingFeature = newLayoutInfo.displayFeatures.find { it is FoldingFeature } + (foldingFeature as? FoldingFeature)?.let { + if (it.isSeparating) { + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED + if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) + binding.onScreenGameView.minimumHeight = it.bounds.top + else + requestedOrientation = emulationSettings.orientation } } } diff --git a/app/src/main/java/emu/skyline/settings/EmulationSettings.kt b/app/src/main/java/emu/skyline/settings/EmulationSettings.kt index 3ba61123..818c5bb6 100644 --- a/app/src/main/java/emu/skyline/settings/EmulationSettings.kt +++ b/app/src/main/java/emu/skyline/settings/EmulationSettings.kt @@ -39,6 +39,7 @@ class EmulationSettings private constructor(context : Context, prefName : String var orientation by sharedPreferences(context, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, prefName = prefName) var aspectRatio by sharedPreferences(context, 0, prefName = prefName) var respectDisplayCutout by sharedPreferences(context, false, prefName = prefName) + var supportFoldableScreen by sharedPreferences(context, false, prefName = prefName) // GPU var gpuDriver by sharedPreferences(context, SYSTEM_GPU_DRIVER, prefName = prefName) diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index b7ee68ea..88ad6132 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -85,14 +85,12 @@ Device Aspect Ratio (Stretch to fit) - Landscape (auto) Auto Landscape Landscape (reverse) 6 - -1 0 8 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 05426883..6106373a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -91,6 +91,9 @@ Respect Display Cutout Do not draw UI elements in the cutout area Allow UI elements to be drawn in the cutout area + Support Foldable Screens + Folded devices will display game and controller separately + Display controller over games even when device is folded Audio Disable Audio Output diff --git a/app/src/main/res/xml/emulation_preferences.xml b/app/src/main/res/xml/emulation_preferences.xml index 7cb111a3..a24cfc5c 100644 --- a/app/src/main/res/xml/emulation_preferences.xml +++ b/app/src/main/res/xml/emulation_preferences.xml @@ -67,6 +67,12 @@ android:summaryOn="@string/respect_display_cutout_enabled" app:key="respect_display_cutout" app:title="@string/respect_display_cutout" /> +