From 0b442b6dd280d2fbd5e05811fd6ac0c95e0d0b39 Mon Sep 17 00:00:00 2001 From: Abandoned Cart Date: Mon, 12 Jun 2023 12:23:07 -0400 Subject: [PATCH] android: Set layout by fragment, not view --- .../yuzu_emu/fragments/EmulationFragment.kt | 18 ++++- .../org/yuzu/yuzu_emu/overlay/InputOverlay.kt | 30 ++----- .../app/src/main/res/values/integers.xml | 78 +++++++++---------- 3 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt index c0332a4479..5e37db46f1 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt @@ -53,6 +53,7 @@ import org.yuzu.yuzu_emu.features.settings.model.IntSetting import org.yuzu.yuzu_emu.features.settings.model.Settings import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile +import org.yuzu.yuzu_emu.overlay.InputOverlay import org.yuzu.yuzu_emu.utils.* class EmulationFragment : Fragment(), SurfaceHolder.Callback { @@ -66,6 +67,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { val args by navArgs() + private var isInFoldableLayout = false + private lateinit var onReturnFromSettings: ActivityResultLauncher override fun onAttach(context: Context) { @@ -195,6 +198,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) + if (!isInFoldableLayout) { + if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { + binding.surfaceInputOverlay.setOrientation(InputOverlay.PORTRAIT) + } else { + binding.surfaceInputOverlay.setOrientation(InputOverlay.LANDSCAPE) + } + } if (!binding.surfaceInputOverlay.isInEditMode) refreshInputOverlay() } @@ -215,6 +225,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { } ) + updateScreenLayout() + emulationState.run(emulationActivity!!.isActivityRecreated) } @@ -321,6 +333,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { else -> { it.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE } } } + onConfigurationChanged(resources.configuration) } private val Number.toPx get() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), Resources.getSystem().displayMetrics).toInt() @@ -332,10 +345,11 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) { binding.emulationContainer.layoutParams.height = it.bounds.top // Prevent touch regions from being displayed in the hinge - binding.surfaceInputOverlay.isInFoldableLayout = true binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx) binding.inGameMenu.layoutParams.height = it.bounds.bottom + isInFoldableLayout = true + binding.surfaceInputOverlay.setOrientation(InputOverlay.FOLDABLE) refreshInputOverlay() } } @@ -345,8 +359,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT binding.overlayContainer.updatePadding(0, 0, 0, 0) - binding.surfaceInputOverlay.isInFoldableLayout = false binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT + isInFoldableLayout = false updateScreenLayout() } binding.emulationContainer.requestLayout() diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt index f6b29865e3..9b3054f0b4 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt @@ -668,8 +668,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context private fun getResourceValue(descriptor: String, position: Int) : Float { return when (descriptor) { - portrait -> resources.getInteger(portraitResources[position]).toFloat() / 1000 - foldable -> resources.getInteger(foldableResources[position]).toFloat() / 1000 + PORTRAIT -> resources.getInteger(portraitResources[position]).toFloat() / 1000 + FOLDABLE -> resources.getInteger(foldableResources[position]).toFloat() / 1000 else -> resources.getInteger(landscapeResources[position]).toFloat() / 1000 } } @@ -804,32 +804,18 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context return inEditMode } - override fun onConfigurationChanged(newConfig: Configuration?) { - super.onConfigurationChanged(newConfig) - if (!isInFoldableLayout) { - orientation = if (newConfig?.orientation == Configuration.ORIENTATION_PORTRAIT) - portrait - else - "" - } + fun setOrientation(descriptor: String) { + orientation = descriptor } - var isInFoldableLayout : Boolean = false - set(value) { - if (value) - orientation = foldable - else - onConfigurationChanged(resources.configuration) - field = value - } - companion object { private val preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) - private const val portrait = "-Portrait" - private const val foldable = "-Foldable" - private var orientation = "" + const val LANDSCAPE = "" + const val PORTRAIT = "-Portrait" + const val FOLDABLE = "-Foldable" + private var orientation = LANDSCAPE /** * Resizes a [Bitmap] by a given scale factor diff --git a/src/android/app/src/main/res/values/integers.xml b/src/android/app/src/main/res/values/integers.xml index 07ddf34701..04280fae28 100644 --- a/src/android/app/src/main/res/values/integers.xml +++ b/src/android/app/src/main/res/values/integers.xml @@ -2,38 +2,6 @@ 2 - - 840 - 820 - 740 - 860 - 740 - 780 - 640 - 820 - 180 - 640 - 820 - 640 - 140 - 240 - 860 - 240 - 140 - 180 - 860 - 180 - 440 - 950 - 560 - 950 - 600 - 950 - 400 - 950 - 240 - 820 - 760 790 @@ -66,16 +34,48 @@ 260 790 + + 840 + 820 + 740 + 860 + 740 + 780 + 640 + 820 + 180 + 640 + 820 + 640 + 140 + 240 + 860 + 240 + 140 + 180 + 860 + 180 + 440 + 950 + 560 + 950 + 600 + 950 + 400 + 950 + 240 + 820 + - 830 + 840 420 - 730 - 470 - 730 - 370 - 630 + 740 + 460 + 740 + 380 + 640 420 - 170 + 180 240 820 240