diff options
| author | 2023-06-12 12:23:07 -0400 | |
|---|---|---|
| committer | 2023-06-14 16:35:54 -0400 | |
| commit | 0b442b6dd280d2fbd5e05811fd6ac0c95e0d0b39 (patch) | |
| tree | ccfcfeca72bce7dc2338decddfec15d5525aef5c /src/android | |
| parent | android: Add a separate foldable layout set (diff) | |
| download | yuzu-0b442b6dd280d2fbd5e05811fd6ac0c95e0d0b39.tar.gz yuzu-0b442b6dd280d2fbd5e05811fd6ac0c95e0d0b39.tar.xz yuzu-0b442b6dd280d2fbd5e05811fd6ac0c95e0d0b39.zip | |
android: Set layout by fragment, not view
Diffstat (limited to 'src/android')
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 c0332a447..5e37db46f 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 | |||
| 53 | import org.yuzu.yuzu_emu.features.settings.model.Settings | 53 | import org.yuzu.yuzu_emu.features.settings.model.Settings |
| 54 | import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity | 54 | import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity |
| 55 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile | 55 | import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile |
| 56 | import org.yuzu.yuzu_emu.overlay.InputOverlay | ||
| 56 | import org.yuzu.yuzu_emu.utils.* | 57 | import org.yuzu.yuzu_emu.utils.* |
| 57 | 58 | ||
| 58 | class EmulationFragment : Fragment(), SurfaceHolder.Callback { | 59 | class EmulationFragment : Fragment(), SurfaceHolder.Callback { |
| @@ -66,6 +67,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 66 | 67 | ||
| 67 | val args by navArgs<EmulationFragmentArgs>() | 68 | val args by navArgs<EmulationFragmentArgs>() |
| 68 | 69 | ||
| 70 | private var isInFoldableLayout = false | ||
| 71 | |||
| 69 | private lateinit var onReturnFromSettings: ActivityResultLauncher<Intent> | 72 | private lateinit var onReturnFromSettings: ActivityResultLauncher<Intent> |
| 70 | 73 | ||
| 71 | override fun onAttach(context: Context) { | 74 | override fun onAttach(context: Context) { |
| @@ -195,6 +198,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 195 | 198 | ||
| 196 | override fun onConfigurationChanged(newConfig: Configuration) { | 199 | override fun onConfigurationChanged(newConfig: Configuration) { |
| 197 | super.onConfigurationChanged(newConfig) | 200 | super.onConfigurationChanged(newConfig) |
| 201 | if (!isInFoldableLayout) { | ||
| 202 | if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { | ||
| 203 | binding.surfaceInputOverlay.setOrientation(InputOverlay.PORTRAIT) | ||
| 204 | } else { | ||
| 205 | binding.surfaceInputOverlay.setOrientation(InputOverlay.LANDSCAPE) | ||
| 206 | } | ||
| 207 | } | ||
| 198 | if (!binding.surfaceInputOverlay.isInEditMode) refreshInputOverlay() | 208 | if (!binding.surfaceInputOverlay.isInEditMode) refreshInputOverlay() |
| 199 | } | 209 | } |
| 200 | 210 | ||
| @@ -215,6 +225,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 215 | } | 225 | } |
| 216 | ) | 226 | ) |
| 217 | 227 | ||
| 228 | updateScreenLayout() | ||
| 229 | |||
| 218 | emulationState.run(emulationActivity!!.isActivityRecreated) | 230 | emulationState.run(emulationActivity!!.isActivityRecreated) |
| 219 | } | 231 | } |
| 220 | 232 | ||
| @@ -321,6 +333,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 321 | else -> { it.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE } | 333 | else -> { it.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE } |
| 322 | } | 334 | } |
| 323 | } | 335 | } |
| 336 | onConfigurationChanged(resources.configuration) | ||
| 324 | } | 337 | } |
| 325 | 338 | ||
| 326 | private val Number.toPx get() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), Resources.getSystem().displayMetrics).toInt() | 339 | 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 { | |||
| 332 | if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) { | 345 | if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) { |
| 333 | binding.emulationContainer.layoutParams.height = it.bounds.top | 346 | binding.emulationContainer.layoutParams.height = it.bounds.top |
| 334 | // Prevent touch regions from being displayed in the hinge | 347 | // Prevent touch regions from being displayed in the hinge |
| 335 | binding.surfaceInputOverlay.isInFoldableLayout = true | ||
| 336 | binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx | 348 | binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx |
| 337 | binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx) | 349 | binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx) |
| 338 | binding.inGameMenu.layoutParams.height = it.bounds.bottom | 350 | binding.inGameMenu.layoutParams.height = it.bounds.bottom |
| 351 | isInFoldableLayout = true | ||
| 352 | binding.surfaceInputOverlay.setOrientation(InputOverlay.FOLDABLE) | ||
| 339 | refreshInputOverlay() | 353 | refreshInputOverlay() |
| 340 | } | 354 | } |
| 341 | } | 355 | } |
| @@ -345,8 +359,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 345 | binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT | 359 | binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT |
| 346 | binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT | 360 | binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT |
| 347 | binding.overlayContainer.updatePadding(0, 0, 0, 0) | 361 | binding.overlayContainer.updatePadding(0, 0, 0, 0) |
| 348 | binding.surfaceInputOverlay.isInFoldableLayout = false | ||
| 349 | binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT | 362 | binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT |
| 363 | isInFoldableLayout = false | ||
| 350 | updateScreenLayout() | 364 | updateScreenLayout() |
| 351 | } | 365 | } |
| 352 | binding.emulationContainer.requestLayout() | 366 | 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 f6b29865e..9b3054f0b 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 | |||
| 668 | 668 | ||
| 669 | private fun getResourceValue(descriptor: String, position: Int) : Float { | 669 | private fun getResourceValue(descriptor: String, position: Int) : Float { |
| 670 | return when (descriptor) { | 670 | return when (descriptor) { |
| 671 | portrait -> resources.getInteger(portraitResources[position]).toFloat() / 1000 | 671 | PORTRAIT -> resources.getInteger(portraitResources[position]).toFloat() / 1000 |
| 672 | foldable -> resources.getInteger(foldableResources[position]).toFloat() / 1000 | 672 | FOLDABLE -> resources.getInteger(foldableResources[position]).toFloat() / 1000 |
| 673 | else -> resources.getInteger(landscapeResources[position]).toFloat() / 1000 | 673 | else -> resources.getInteger(landscapeResources[position]).toFloat() / 1000 |
| 674 | } | 674 | } |
| 675 | } | 675 | } |
| @@ -804,32 +804,18 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context | |||
| 804 | return inEditMode | 804 | return inEditMode |
| 805 | } | 805 | } |
| 806 | 806 | ||
| 807 | override fun onConfigurationChanged(newConfig: Configuration?) { | 807 | fun setOrientation(descriptor: String) { |
| 808 | super.onConfigurationChanged(newConfig) | 808 | orientation = descriptor |
| 809 | if (!isInFoldableLayout) { | ||
| 810 | orientation = if (newConfig?.orientation == Configuration.ORIENTATION_PORTRAIT) | ||
| 811 | portrait | ||
| 812 | else | ||
| 813 | "" | ||
| 814 | } | ||
| 815 | } | 809 | } |
| 816 | 810 | ||
| 817 | var isInFoldableLayout : Boolean = false | ||
| 818 | set(value) { | ||
| 819 | if (value) | ||
| 820 | orientation = foldable | ||
| 821 | else | ||
| 822 | onConfigurationChanged(resources.configuration) | ||
| 823 | field = value | ||
| 824 | } | ||
| 825 | |||
| 826 | companion object { | 811 | companion object { |
| 827 | private val preferences: SharedPreferences = | 812 | private val preferences: SharedPreferences = |
| 828 | PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) | 813 | PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) |
| 829 | 814 | ||
| 830 | private const val portrait = "-Portrait" | 815 | const val LANDSCAPE = "" |
| 831 | private const val foldable = "-Foldable" | 816 | const val PORTRAIT = "-Portrait" |
| 832 | private var orientation = "" | 817 | const val FOLDABLE = "-Foldable" |
| 818 | private var orientation = LANDSCAPE | ||
| 833 | 819 | ||
| 834 | /** | 820 | /** |
| 835 | * Resizes a [Bitmap] by a given scale factor | 821 | * 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 07ddf3470..04280fae2 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 | <resources> | 2 | <resources> |
| 3 | <integer name="game_title_lines">2</integer> | 3 | <integer name="game_title_lines">2</integer> |
| 4 | 4 | ||
| 5 | <!-- Default SWITCH portrait layout --> | ||
| 6 | <integer name="SWITCH_BUTTON_A_PORTRAIT_X">840</integer> | ||
| 7 | <integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer> | ||
| 8 | <integer name="SWITCH_BUTTON_B_PORTRAIT_X">740</integer> | ||
| 9 | <integer name="SWITCH_BUTTON_B_PORTRAIT_Y">860</integer> | ||
| 10 | <integer name="SWITCH_BUTTON_X_PORTRAIT_X">740</integer> | ||
| 11 | <integer name="SWITCH_BUTTON_X_PORTRAIT_Y">780</integer> | ||
| 12 | <integer name="SWITCH_BUTTON_Y_PORTRAIT_X">640</integer> | ||
| 13 | <integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer> | ||
| 14 | <integer name="SWITCH_STICK_L_PORTRAIT_X">180</integer> | ||
| 15 | <integer name="SWITCH_STICK_L_PORTRAIT_Y">640</integer> | ||
| 16 | <integer name="SWITCH_STICK_R_PORTRAIT_X">820</integer> | ||
| 17 | <integer name="SWITCH_STICK_R_PORTRAIT_Y">640</integer> | ||
| 18 | <integer name="SWITCH_TRIGGER_L_PORTRAIT_X">140</integer> | ||
| 19 | <integer name="SWITCH_TRIGGER_L_PORTRAIT_Y">240</integer> | ||
| 20 | <integer name="SWITCH_TRIGGER_R_PORTRAIT_X">860</integer> | ||
| 21 | <integer name="SWITCH_TRIGGER_R_PORTRAIT_Y">240</integer> | ||
| 22 | <integer name="SWITCH_TRIGGER_ZL_PORTRAIT_X">140</integer> | ||
| 23 | <integer name="SWITCH_TRIGGER_ZL_PORTRAIT_Y">180</integer> | ||
| 24 | <integer name="SWITCH_TRIGGER_ZR_PORTRAIT_X">860</integer> | ||
| 25 | <integer name="SWITCH_TRIGGER_ZR_PORTRAIT_Y">180</integer> | ||
| 26 | <integer name="SWITCH_BUTTON_MINUS_PORTRAIT_X">440</integer> | ||
| 27 | <integer name="SWITCH_BUTTON_MINUS_PORTRAIT_Y">950</integer> | ||
| 28 | <integer name="SWITCH_BUTTON_PLUS_PORTRAIT_X">560</integer> | ||
| 29 | <integer name="SWITCH_BUTTON_PLUS_PORTRAIT_Y">950</integer> | ||
| 30 | <integer name="SWITCH_BUTTON_HOME_PORTRAIT_X">600</integer> | ||
| 31 | <integer name="SWITCH_BUTTON_HOME_PORTRAIT_Y">950</integer> | ||
| 32 | <integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_X">400</integer> | ||
| 33 | <integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_Y">950</integer> | ||
| 34 | <integer name="SWITCH_BUTTON_DPAD_PORTRAIT_X">240</integer> | ||
| 35 | <integer name="SWITCH_BUTTON_DPAD_PORTRAIT_Y">820</integer> | ||
| 36 | |||
| 37 | <!-- Default SWITCH landscape layout --> | 5 | <!-- Default SWITCH landscape layout --> |
| 38 | <integer name="SWITCH_BUTTON_A_X">760</integer> | 6 | <integer name="SWITCH_BUTTON_A_X">760</integer> |
| 39 | <integer name="SWITCH_BUTTON_A_Y">790</integer> | 7 | <integer name="SWITCH_BUTTON_A_Y">790</integer> |
| @@ -66,16 +34,48 @@ | |||
| 66 | <integer name="SWITCH_BUTTON_DPAD_X">260</integer> | 34 | <integer name="SWITCH_BUTTON_DPAD_X">260</integer> |
| 67 | <integer name="SWITCH_BUTTON_DPAD_Y">790</integer> | 35 | <integer name="SWITCH_BUTTON_DPAD_Y">790</integer> |
| 68 | 36 | ||
| 37 | <!-- Default SWITCH portrait layout --> | ||
| 38 | <integer name="SWITCH_BUTTON_A_PORTRAIT_X">840</integer> | ||
| 39 | <integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer> | ||
| 40 | <integer name="SWITCH_BUTTON_B_PORTRAIT_X">740</integer> | ||
| 41 | <integer name="SWITCH_BUTTON_B_PORTRAIT_Y">860</integer> | ||
| 42 | <integer name="SWITCH_BUTTON_X_PORTRAIT_X">740</integer> | ||
| 43 | <integer name="SWITCH_BUTTON_X_PORTRAIT_Y">780</integer> | ||
| 44 | <integer name="SWITCH_BUTTON_Y_PORTRAIT_X">640</integer> | ||
| 45 | <integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer> | ||
| 46 | <integer name="SWITCH_STICK_L_PORTRAIT_X">180</integer> | ||
| 47 | <integer name="SWITCH_STICK_L_PORTRAIT_Y">640</integer> | ||
| 48 | <integer name="SWITCH_STICK_R_PORTRAIT_X">820</integer> | ||
| 49 | <integer name="SWITCH_STICK_R_PORTRAIT_Y">640</integer> | ||
| 50 | <integer name="SWITCH_TRIGGER_L_PORTRAIT_X">140</integer> | ||
| 51 | <integer name="SWITCH_TRIGGER_L_PORTRAIT_Y">240</integer> | ||
| 52 | <integer name="SWITCH_TRIGGER_R_PORTRAIT_X">860</integer> | ||
| 53 | <integer name="SWITCH_TRIGGER_R_PORTRAIT_Y">240</integer> | ||
| 54 | <integer name="SWITCH_TRIGGER_ZL_PORTRAIT_X">140</integer> | ||
| 55 | <integer name="SWITCH_TRIGGER_ZL_PORTRAIT_Y">180</integer> | ||
| 56 | <integer name="SWITCH_TRIGGER_ZR_PORTRAIT_X">860</integer> | ||
| 57 | <integer name="SWITCH_TRIGGER_ZR_PORTRAIT_Y">180</integer> | ||
| 58 | <integer name="SWITCH_BUTTON_MINUS_PORTRAIT_X">440</integer> | ||
| 59 | <integer name="SWITCH_BUTTON_MINUS_PORTRAIT_Y">950</integer> | ||
| 60 | <integer name="SWITCH_BUTTON_PLUS_PORTRAIT_X">560</integer> | ||
| 61 | <integer name="SWITCH_BUTTON_PLUS_PORTRAIT_Y">950</integer> | ||
| 62 | <integer name="SWITCH_BUTTON_HOME_PORTRAIT_X">600</integer> | ||
| 63 | <integer name="SWITCH_BUTTON_HOME_PORTRAIT_Y">950</integer> | ||
| 64 | <integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_X">400</integer> | ||
| 65 | <integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_Y">950</integer> | ||
| 66 | <integer name="SWITCH_BUTTON_DPAD_PORTRAIT_X">240</integer> | ||
| 67 | <integer name="SWITCH_BUTTON_DPAD_PORTRAIT_Y">820</integer> | ||
| 68 | |||
| 69 | <!-- Default SWITCH foldable layout --> | 69 | <!-- Default SWITCH foldable layout --> |
| 70 | <integer name="SWITCH_BUTTON_A_FOLDABLE_X">830</integer> | 70 | <integer name="SWITCH_BUTTON_A_FOLDABLE_X">840</integer> |
| 71 | <integer name="SWITCH_BUTTON_A_FOLDABLE_Y">420</integer> | 71 | <integer name="SWITCH_BUTTON_A_FOLDABLE_Y">420</integer> |
| 72 | <integer name="SWITCH_BUTTON_B_FOLDABLE_X">730</integer> | 72 | <integer name="SWITCH_BUTTON_B_FOLDABLE_X">740</integer> |
| 73 | <integer name="SWITCH_BUTTON_B_FOLDABLE_Y">470</integer> | 73 | <integer name="SWITCH_BUTTON_B_FOLDABLE_Y">460</integer> |
| 74 | <integer name="SWITCH_BUTTON_X_FOLDABLE_X">730</integer> | 74 | <integer name="SWITCH_BUTTON_X_FOLDABLE_X">740</integer> |
| 75 | <integer name="SWITCH_BUTTON_X_FOLDABLE_Y">370</integer> | 75 | <integer name="SWITCH_BUTTON_X_FOLDABLE_Y">380</integer> |
| 76 | <integer name="SWITCH_BUTTON_Y_FOLDABLE_X">630</integer> | 76 | <integer name="SWITCH_BUTTON_Y_FOLDABLE_X">640</integer> |
| 77 | <integer name="SWITCH_BUTTON_Y_FOLDABLE_Y">420</integer> | 77 | <integer name="SWITCH_BUTTON_Y_FOLDABLE_Y">420</integer> |
| 78 | <integer name="SWITCH_STICK_L_FOLDABLE_X">170</integer> | 78 | <integer name="SWITCH_STICK_L_FOLDABLE_X">180</integer> |
| 79 | <integer name="SWITCH_STICK_L_FOLDABLE_Y">240</integer> | 79 | <integer name="SWITCH_STICK_L_FOLDABLE_Y">240</integer> |
| 80 | <integer name="SWITCH_STICK_R_FOLDABLE_X">820</integer> | 80 | <integer name="SWITCH_STICK_R_FOLDABLE_X">820</integer> |
| 81 | <integer name="SWITCH_STICK_R_FOLDABLE_Y">240</integer> | 81 | <integer name="SWITCH_STICK_R_FOLDABLE_Y">240</integer> |