Fix and make foldable screen support optional

This commit is contained in:
Abandoned Cart 2023-04-22 09:03:54 -04:00 committed by skriand
parent 4c7fd0447d
commit 9742014f9b
5 changed files with 28 additions and 21 deletions

View File

@ -504,27 +504,26 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
* Updating the layout depending on type and state of device * Updating the layout depending on type and state of device
*/ */
private fun updateCurrentLayout(newLayoutInfo: WindowLayoutInfo) { private fun updateCurrentLayout(newLayoutInfo: WindowLayoutInfo) {
val displayMetrics = DisplayMetrics() if (!emulationSettings.supportFoldableScreen) return
windowManager.defaultDisplay.getMetrics(displayMetrics) binding.onScreenGameView.minimumHeight = with (windowManager) {
binding.onScreenGameView.minimumHeight = displayMetrics.heightPixels if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
requestedOrientation = maximumWindowMetrics.bounds.height()
if (emulationSettings.orientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
emulationSettings.orientation
} else { } 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 requestedOrientation = emulationSettings.orientation
foldFeature?.let { val foldingFeature = newLayoutInfo.displayFeatures.find { it is FoldingFeature }
//Folding feature separates the display area into two distinct sections (foldingFeature as? FoldingFeature)?.let {
if (it.isSeparating) { if (it.isSeparating) {
if (emulationSettings.orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED){ requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
requestedOrientation = emulationSettings.orientation if (it.orientation == FoldingFeature.Orientation.HORIZONTAL)
} binding.onScreenGameView.minimumHeight = it.bounds.top
if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) { else
binding.onScreenGameView.minimumHeight = displayFeature.bounds.top requestedOrientation = emulationSettings.orientation
}
}
} }
} }
} }

View File

@ -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 orientation by sharedPreferences(context, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, prefName = prefName)
var aspectRatio by sharedPreferences(context, 0, prefName = prefName) var aspectRatio by sharedPreferences(context, 0, prefName = prefName)
var respectDisplayCutout by sharedPreferences(context, false, prefName = prefName) var respectDisplayCutout by sharedPreferences(context, false, prefName = prefName)
var supportFoldableScreen by sharedPreferences(context, false, prefName = prefName)
// GPU // GPU
var gpuDriver by sharedPreferences(context, SYSTEM_GPU_DRIVER, prefName = prefName) var gpuDriver by sharedPreferences(context, SYSTEM_GPU_DRIVER, prefName = prefName)

View File

@ -85,14 +85,12 @@
<item>Device Aspect Ratio (Stretch to fit)</item> <item>Device Aspect Ratio (Stretch to fit)</item>
</string-array> </string-array>
<string-array name="orientation_entries"> <string-array name="orientation_entries">
<item>Landscape (auto)</item>
<item>Auto</item> <item>Auto</item>
<item>Landscape</item> <item>Landscape</item>
<item>Landscape (reverse)</item> <item>Landscape (reverse)</item>
</string-array> </string-array>
<integer-array name="orientation_values"> <integer-array name="orientation_values">
<item>6</item> <item>6</item>
<item>-1</item>
<item>0</item> <item>0</item>
<item>8</item> <item>8</item>
</integer-array> </integer-array>

View File

@ -91,6 +91,9 @@
<string name="respect_display_cutout">Respect Display Cutout</string> <string name="respect_display_cutout">Respect Display Cutout</string>
<string name="respect_display_cutout_enabled">Do not draw UI elements in the cutout area</string> <string name="respect_display_cutout_enabled">Do not draw UI elements in the cutout area</string>
<string name="respect_display_cutout_disabled">Allow UI elements to be drawn in the cutout area</string> <string name="respect_display_cutout_disabled">Allow UI elements to be drawn in the cutout area</string>
<string name="support_foldable_screen">Support Foldable Screens</string>
<string name="support_foldable_screen_enabled">Folded devices will display game and controller separately</string>
<string name="support_foldable_screen_disabled">Display controller over games even when device is folded</string>
<!-- Settings - Audio --> <!-- Settings - Audio -->
<string name="audio">Audio</string> <string name="audio">Audio</string>
<string name="disable_audio_output">Disable Audio Output</string> <string name="disable_audio_output">Disable Audio Output</string>

View File

@ -67,6 +67,12 @@
android:summaryOn="@string/respect_display_cutout_enabled" android:summaryOn="@string/respect_display_cutout_enabled"
app:key="respect_display_cutout" app:key="respect_display_cutout"
app:title="@string/respect_display_cutout" /> app:title="@string/respect_display_cutout" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:summaryOff="@string/support_foldable_screen_disabled"
android:summaryOn="@string/support_foldable_screen_enabled"
app:key="support_foldable_screen"
app:title="@string/support_foldable_screen" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:key="category_audio" android:key="category_audio"