android: Add a separate foldable layout set

This commit is contained in:
Abandoned Cart 2023-06-12 10:36:06 -04:00
parent fb28f9fd96
commit 2b5dde162a
3 changed files with 222 additions and 206 deletions

View File

@ -332,6 +332,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) { if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) {
binding.emulationContainer.layoutParams.height = it.bounds.top binding.emulationContainer.layoutParams.height = it.bounds.top
// Prevent touch regions from being displayed in the hinge // Prevent touch regions from being displayed in the hinge
binding.surfaceInputOverlay.isInFoldableLayout = true
binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx
binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx) binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx)
binding.inGameMenu.layoutParams.height = it.bounds.bottom binding.inGameMenu.layoutParams.height = it.bounds.bottom
@ -344,6 +345,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
binding.overlayContainer.updatePadding(0, 0, 0, 0) binding.overlayContainer.updatePadding(0, 0, 0, 0)
binding.surfaceInputOverlay.isInFoldableLayout = false
binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
updateScreenLayout() updateScreenLayout()
} }

View File

@ -553,10 +553,7 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
private fun defaultOverlay() { private fun defaultOverlay() {
if (!preferences.getBoolean(Settings.PREF_OVERLAY_INIT, false)) { if (!preferences.getBoolean(Settings.PREF_OVERLAY_INIT, false)) {
if (orientation == portrait) defaultOverlayByLayout(orientation)
defaultOverlayPortrait()
else
defaultOverlayLandscape()
} }
resetButtonPlacement() resetButtonPlacement()
@ -566,265 +563,239 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
} }
fun resetButtonPlacement() { fun resetButtonPlacement() {
if (orientation == portrait) defaultOverlayByLayout(orientation)
defaultOverlayPortrait()
else
defaultOverlayLandscape()
refreshControls() refreshControls()
} }
private fun defaultOverlayPortrait() { private val landscapeResources = arrayOf(
// Each value represents the position of the button in relation to the screen size without insets. R.integer.SWITCH_BUTTON_A_X,
preferences.edit() R.integer.SWITCH_BUTTON_A_Y,
.putFloat( R.integer.SWITCH_BUTTON_B_X,
ButtonType.BUTTON_A.toString() + "$portrait-X", R.integer.SWITCH_BUTTON_B_Y,
resources.getInteger(R.integer.SWITCH_BUTTON_A_PORTRAIT_X).toFloat() / 1000 R.integer.SWITCH_BUTTON_X_X,
R.integer.SWITCH_BUTTON_X_Y,
R.integer.SWITCH_BUTTON_Y_X,
R.integer.SWITCH_BUTTON_Y_Y,
R.integer.SWITCH_TRIGGER_ZL_X,
R.integer.SWITCH_TRIGGER_ZL_Y,
R.integer.SWITCH_TRIGGER_ZR_X,
R.integer.SWITCH_TRIGGER_ZR_Y,
R.integer.SWITCH_BUTTON_DPAD_X,
R.integer.SWITCH_BUTTON_DPAD_Y,
R.integer.SWITCH_TRIGGER_L_X,
R.integer.SWITCH_TRIGGER_L_Y,
R.integer.SWITCH_TRIGGER_R_X,
R.integer.SWITCH_TRIGGER_R_Y,
R.integer.SWITCH_BUTTON_PLUS_X,
R.integer.SWITCH_BUTTON_PLUS_Y,
R.integer.SWITCH_BUTTON_MINUS_X,
R.integer.SWITCH_BUTTON_MINUS_Y,
R.integer.SWITCH_BUTTON_HOME_X,
R.integer.SWITCH_BUTTON_HOME_Y,
R.integer.SWITCH_BUTTON_CAPTURE_X,
R.integer.SWITCH_BUTTON_CAPTURE_Y,
R.integer.SWITCH_STICK_R_X,
R.integer.SWITCH_STICK_R_Y,
R.integer.SWITCH_STICK_L_X,
R.integer.SWITCH_STICK_L_Y
) )
.putFloat(
ButtonType.BUTTON_A.toString() + "$portrait-Y", private val portraitResources = arrayOf(
resources.getInteger(R.integer.SWITCH_BUTTON_A_PORTRAIT_Y).toFloat() / 1000 R.integer.SWITCH_BUTTON_A_PORTRAIT_X,
R.integer.SWITCH_BUTTON_A_PORTRAIT_Y,
R.integer.SWITCH_BUTTON_B_PORTRAIT_X,
R.integer.SWITCH_BUTTON_B_PORTRAIT_Y,
R.integer.SWITCH_BUTTON_X_PORTRAIT_X,
R.integer.SWITCH_BUTTON_X_PORTRAIT_Y,
R.integer.SWITCH_BUTTON_Y_PORTRAIT_X,
R.integer.SWITCH_BUTTON_Y_PORTRAIT_Y,
R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_X,
R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_Y,
R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_X,
R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_Y,
R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_X,
R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_Y,
R.integer.SWITCH_TRIGGER_L_PORTRAIT_X,
R.integer.SWITCH_TRIGGER_L_PORTRAIT_Y,
R.integer.SWITCH_TRIGGER_R_PORTRAIT_X,
R.integer.SWITCH_TRIGGER_R_PORTRAIT_Y,
R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_X,
R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_Y,
R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_X,
R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_Y,
R.integer.SWITCH_BUTTON_HOME_PORTRAIT_X,
R.integer.SWITCH_BUTTON_HOME_PORTRAIT_Y,
R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_X,
R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_Y,
R.integer.SWITCH_STICK_R_PORTRAIT_X,
R.integer.SWITCH_STICK_R_PORTRAIT_Y,
R.integer.SWITCH_STICK_L_PORTRAIT_X,
R.integer.SWITCH_STICK_L_PORTRAIT_Y
) )
.putFloat(
ButtonType.BUTTON_B.toString() + "$portrait-X", private val foldableResources = arrayOf(
resources.getInteger(R.integer.SWITCH_BUTTON_B_PORTRAIT_X).toFloat() / 1000 R.integer.SWITCH_BUTTON_A_FOLDABLE_X,
R.integer.SWITCH_BUTTON_A_FOLDABLE_Y,
R.integer.SWITCH_BUTTON_B_FOLDABLE_X,
R.integer.SWITCH_BUTTON_B_FOLDABLE_Y,
R.integer.SWITCH_BUTTON_X_FOLDABLE_X,
R.integer.SWITCH_BUTTON_X_FOLDABLE_Y,
R.integer.SWITCH_BUTTON_Y_FOLDABLE_X,
R.integer.SWITCH_BUTTON_Y_FOLDABLE_Y,
R.integer.SWITCH_TRIGGER_ZL_FOLDABLE_X,
R.integer.SWITCH_TRIGGER_ZL_FOLDABLE_Y,
R.integer.SWITCH_TRIGGER_ZR_FOLDABLE_X,
R.integer.SWITCH_TRIGGER_ZR_FOLDABLE_Y,
R.integer.SWITCH_BUTTON_DPAD_FOLDABLE_X,
R.integer.SWITCH_BUTTON_DPAD_FOLDABLE_Y,
R.integer.SWITCH_TRIGGER_L_FOLDABLE_X,
R.integer.SWITCH_TRIGGER_L_FOLDABLE_Y,
R.integer.SWITCH_TRIGGER_R_FOLDABLE_X,
R.integer.SWITCH_TRIGGER_R_FOLDABLE_Y,
R.integer.SWITCH_BUTTON_PLUS_FOLDABLE_X,
R.integer.SWITCH_BUTTON_PLUS_FOLDABLE_Y,
R.integer.SWITCH_BUTTON_MINUS_FOLDABLE_X,
R.integer.SWITCH_BUTTON_MINUS_FOLDABLE_Y,
R.integer.SWITCH_BUTTON_HOME_FOLDABLE_X,
R.integer.SWITCH_BUTTON_HOME_FOLDABLE_Y,
R.integer.SWITCH_BUTTON_CAPTURE_FOLDABLE_X,
R.integer.SWITCH_BUTTON_CAPTURE_FOLDABLE_Y,
R.integer.SWITCH_STICK_R_FOLDABLE_X,
R.integer.SWITCH_STICK_R_FOLDABLE_Y,
R.integer.SWITCH_STICK_L_FOLDABLE_X,
R.integer.SWITCH_STICK_L_FOLDABLE_Y
) )
.putFloat(
ButtonType.BUTTON_B.toString() + "$portrait-Y", private fun getResourceValue(descriptor: String, position: Int) : Float {
resources.getInteger(R.integer.SWITCH_BUTTON_B_PORTRAIT_Y).toFloat() / 1000 return when (descriptor) {
) portrait -> resources.getInteger(portraitResources[position]).toFloat() / 1000
.putFloat( foldable -> resources.getInteger(foldableResources[position]).toFloat() / 1000
ButtonType.BUTTON_X.toString() + "$portrait-X", else -> resources.getInteger(landscapeResources[position]).toFloat() / 1000
resources.getInteger(R.integer.SWITCH_BUTTON_X_PORTRAIT_X).toFloat() / 1000 }
)
.putFloat(
ButtonType.BUTTON_X.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_X_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.BUTTON_Y.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_BUTTON_Y_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.BUTTON_Y.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_Y_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.TRIGGER_ZL.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.TRIGGER_ZL.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.TRIGGER_ZR.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.TRIGGER_ZR.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.DPAD_UP.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.DPAD_UP.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.TRIGGER_L.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_TRIGGER_L_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.TRIGGER_L.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_TRIGGER_L_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.TRIGGER_R.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_TRIGGER_R_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.TRIGGER_R.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_TRIGGER_R_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.BUTTON_PLUS.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.BUTTON_PLUS.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.BUTTON_MINUS.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.BUTTON_MINUS.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.BUTTON_HOME.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_BUTTON_HOME_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.BUTTON_HOME.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_HOME_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.BUTTON_CAPTURE.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_X)
.toFloat() / 1000
)
.putFloat(
ButtonType.BUTTON_CAPTURE.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_Y)
.toFloat() / 1000
)
.putFloat(
ButtonType.STICK_R.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_STICK_R_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.STICK_R.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_STICK_R_PORTRAIT_Y).toFloat() / 1000
)
.putFloat(
ButtonType.STICK_L.toString() + "$portrait-X",
resources.getInteger(R.integer.SWITCH_STICK_L_PORTRAIT_X).toFloat() / 1000
)
.putFloat(
ButtonType.STICK_L.toString() + "$portrait-Y",
resources.getInteger(R.integer.SWITCH_STICK_L_PORTRAIT_Y).toFloat() / 1000
)
.apply()
} }
private fun defaultOverlayLandscape() { private fun defaultOverlayByLayout(descriptor: String) {
// Each value represents the position of the button in relation to the screen size without insets. // Each value represents the position of the button in relation to the screen size without insets.
preferences.edit() preferences.edit()
.putFloat( .putFloat(
ButtonType.BUTTON_A.toString() + "-X", ButtonType.BUTTON_A.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_BUTTON_A_X).toFloat() / 1000 getResourceValue(descriptor, 0)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_A.toString() + "-Y", ButtonType.BUTTON_A.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_A_Y).toFloat() / 1000 getResourceValue(descriptor, 1)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_B.toString() + "-X", ButtonType.BUTTON_B.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_BUTTON_B_X).toFloat() / 1000 getResourceValue(descriptor, 2)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_B.toString() + "-Y", ButtonType.BUTTON_B.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_B_Y).toFloat() / 1000 getResourceValue(descriptor, 3)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_X.toString() + "-X", ButtonType.BUTTON_X.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_BUTTON_X_X).toFloat() / 1000 getResourceValue(descriptor, 4)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_X.toString() + "-Y", ButtonType.BUTTON_X.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_X_Y).toFloat() / 1000 getResourceValue(descriptor, 5)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_Y.toString() + "-X", ButtonType.BUTTON_Y.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_BUTTON_Y_X).toFloat() / 1000 getResourceValue(descriptor, 6)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_Y.toString() + "-Y", ButtonType.BUTTON_Y.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_Y_Y).toFloat() / 1000 getResourceValue(descriptor, 7)
) )
.putFloat( .putFloat(
ButtonType.TRIGGER_ZL.toString() + "-X", ButtonType.TRIGGER_ZL.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_X).toFloat() / 1000 getResourceValue(descriptor, 8)
) )
.putFloat( .putFloat(
ButtonType.TRIGGER_ZL.toString() + "-Y", ButtonType.TRIGGER_ZL.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_Y).toFloat() / 1000 getResourceValue(descriptor, 9)
) )
.putFloat( .putFloat(
ButtonType.TRIGGER_ZR.toString() + "-X", ButtonType.TRIGGER_ZR.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_X).toFloat() / 1000 getResourceValue(descriptor, 10)
) )
.putFloat( .putFloat(
ButtonType.TRIGGER_ZR.toString() + "-Y", ButtonType.TRIGGER_ZR.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_Y).toFloat() / 1000 getResourceValue(descriptor, 11)
) )
.putFloat( .putFloat(
ButtonType.DPAD_UP.toString() + "-X", ButtonType.DPAD_UP.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_X).toFloat() / 1000 getResourceValue(descriptor, 12)
) )
.putFloat( .putFloat(
ButtonType.DPAD_UP.toString() + "-Y", ButtonType.DPAD_UP.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_Y).toFloat() / 1000 getResourceValue(descriptor, 13)
) )
.putFloat( .putFloat(
ButtonType.TRIGGER_L.toString() + "-X", ButtonType.TRIGGER_L.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_TRIGGER_L_X).toFloat() / 1000 getResourceValue(descriptor, 14)
) )
.putFloat( .putFloat(
ButtonType.TRIGGER_L.toString() + "-Y", ButtonType.TRIGGER_L.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_TRIGGER_L_Y).toFloat() / 1000 getResourceValue(descriptor, 15)
) )
.putFloat( .putFloat(
ButtonType.TRIGGER_R.toString() + "-X", ButtonType.TRIGGER_R.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_TRIGGER_R_X).toFloat() / 1000 getResourceValue(descriptor, 16)
) )
.putFloat( .putFloat(
ButtonType.TRIGGER_R.toString() + "-Y", ButtonType.TRIGGER_R.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_TRIGGER_R_Y).toFloat() / 1000 getResourceValue(descriptor, 17)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_PLUS.toString() + "-X", ButtonType.BUTTON_PLUS.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_X).toFloat() / 1000 getResourceValue(descriptor, 18)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_PLUS.toString() + "-Y", ButtonType.BUTTON_PLUS.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_Y).toFloat() / 1000 getResourceValue(descriptor, 19)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_MINUS.toString() + "-X", ButtonType.BUTTON_MINUS.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_X).toFloat() / 1000 getResourceValue(descriptor, 20)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_MINUS.toString() + "-Y", ButtonType.BUTTON_MINUS.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_Y).toFloat() / 1000 getResourceValue(descriptor, 21)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_HOME.toString() + "-X", ButtonType.BUTTON_HOME.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_BUTTON_HOME_X).toFloat() / 1000 getResourceValue(descriptor, 22)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_HOME.toString() + "-Y", ButtonType.BUTTON_HOME.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_HOME_Y).toFloat() / 1000 getResourceValue(descriptor, 23)
) )
.putFloat( .putFloat(
ButtonType.BUTTON_CAPTURE.toString() + "-X", ButtonType.BUTTON_CAPTURE.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_X) getResourceValue(descriptor, 24)
.toFloat() / 1000
) )
.putFloat( .putFloat(
ButtonType.BUTTON_CAPTURE.toString() + "-Y", ButtonType.BUTTON_CAPTURE.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_Y) getResourceValue(descriptor, 25)
.toFloat() / 1000
) )
.putFloat( .putFloat(
ButtonType.STICK_R.toString() + "-X", ButtonType.STICK_R.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_STICK_R_X).toFloat() / 1000 getResourceValue(descriptor, 26)
) )
.putFloat( .putFloat(
ButtonType.STICK_R.toString() + "-Y", ButtonType.STICK_R.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_STICK_R_Y).toFloat() / 1000 getResourceValue(descriptor, 27)
) )
.putFloat( .putFloat(
ButtonType.STICK_L.toString() + "-X", ButtonType.STICK_L.toString() + "$descriptor-X",
resources.getInteger(R.integer.SWITCH_STICK_L_X).toFloat() / 1000 getResourceValue(descriptor, 28)
) )
.putFloat( .putFloat(
ButtonType.STICK_L.toString() + "-Y", ButtonType.STICK_L.toString() + "$descriptor-Y",
resources.getInteger(R.integer.SWITCH_STICK_L_Y).toFloat() / 1000 getResourceValue(descriptor, 29)
) )
.apply() .apply()
} }
@ -835,18 +806,29 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
override fun onConfigurationChanged(newConfig: Configuration?) { override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
orientation = if (!isInFoldableLayout) {
if (newConfig?.orientation == Configuration.ORIENTATION_PORTRAIT) orientation = if (newConfig?.orientation == Configuration.ORIENTATION_PORTRAIT)
portrait portrait
else else
"" ""
} }
}
var isInFoldableLayout : Boolean = false
set(value) {
if (value)
orientation = foldable
else
onConfigurationChanged(resources.configuration)
field = value
}
companion object { companion object {
private val preferences: SharedPreferences = private val preferences: SharedPreferences =
PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
private const val portrait = "-Portrait" private const val portrait = "-Portrait"
private const val foldable = "-Foldable"
private var orientation = "" private var orientation = ""
/** /**

View File

@ -3,15 +3,15 @@
<integer name="game_title_lines">2</integer> <integer name="game_title_lines">2</integer>
<!-- Default SWITCH portrait layout --> <!-- Default SWITCH portrait layout -->
<integer name="SWITCH_BUTTON_A_PORTRAIT_X">830</integer> <integer name="SWITCH_BUTTON_A_PORTRAIT_X">840</integer>
<integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer> <integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer>
<integer name="SWITCH_BUTTON_B_PORTRAIT_X">730</integer> <integer name="SWITCH_BUTTON_B_PORTRAIT_X">740</integer>
<integer name="SWITCH_BUTTON_B_PORTRAIT_Y">870</integer> <integer name="SWITCH_BUTTON_B_PORTRAIT_Y">860</integer>
<integer name="SWITCH_BUTTON_X_PORTRAIT_X">730</integer> <integer name="SWITCH_BUTTON_X_PORTRAIT_X">740</integer>
<integer name="SWITCH_BUTTON_X_PORTRAIT_Y">770</integer> <integer name="SWITCH_BUTTON_X_PORTRAIT_Y">780</integer>
<integer name="SWITCH_BUTTON_Y_PORTRAIT_X">630</integer> <integer name="SWITCH_BUTTON_Y_PORTRAIT_X">640</integer>
<integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer> <integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer>
<integer name="SWITCH_STICK_L_PORTRAIT_X">170</integer> <integer name="SWITCH_STICK_L_PORTRAIT_X">180</integer>
<integer name="SWITCH_STICK_L_PORTRAIT_Y">640</integer> <integer name="SWITCH_STICK_L_PORTRAIT_Y">640</integer>
<integer name="SWITCH_STICK_R_PORTRAIT_X">820</integer> <integer name="SWITCH_STICK_R_PORTRAIT_X">820</integer>
<integer name="SWITCH_STICK_R_PORTRAIT_Y">640</integer> <integer name="SWITCH_STICK_R_PORTRAIT_Y">640</integer>
@ -66,4 +66,36 @@
<integer name="SWITCH_BUTTON_DPAD_X">260</integer> <integer name="SWITCH_BUTTON_DPAD_X">260</integer>
<integer name="SWITCH_BUTTON_DPAD_Y">790</integer> <integer name="SWITCH_BUTTON_DPAD_Y">790</integer>
<!-- Default SWITCH foldable layout -->
<integer name="SWITCH_BUTTON_A_FOLDABLE_X">830</integer>
<integer name="SWITCH_BUTTON_A_FOLDABLE_Y">420</integer>
<integer name="SWITCH_BUTTON_B_FOLDABLE_X">730</integer>
<integer name="SWITCH_BUTTON_B_FOLDABLE_Y">470</integer>
<integer name="SWITCH_BUTTON_X_FOLDABLE_X">730</integer>
<integer name="SWITCH_BUTTON_X_FOLDABLE_Y">370</integer>
<integer name="SWITCH_BUTTON_Y_FOLDABLE_X">630</integer>
<integer name="SWITCH_BUTTON_Y_FOLDABLE_Y">420</integer>
<integer name="SWITCH_STICK_L_FOLDABLE_X">170</integer>
<integer name="SWITCH_STICK_L_FOLDABLE_Y">240</integer>
<integer name="SWITCH_STICK_R_FOLDABLE_X">820</integer>
<integer name="SWITCH_STICK_R_FOLDABLE_Y">240</integer>
<integer name="SWITCH_TRIGGER_L_FOLDABLE_X">140</integer>
<integer name="SWITCH_TRIGGER_L_FOLDABLE_Y">100</integer>
<integer name="SWITCH_TRIGGER_R_FOLDABLE_X">860</integer>
<integer name="SWITCH_TRIGGER_R_FOLDABLE_Y">100</integer>
<integer name="SWITCH_TRIGGER_ZL_FOLDABLE_X">140</integer>
<integer name="SWITCH_TRIGGER_ZL_FOLDABLE_Y">40</integer>
<integer name="SWITCH_TRIGGER_ZR_FOLDABLE_X">860</integer>
<integer name="SWITCH_TRIGGER_ZR_FOLDABLE_Y">40</integer>
<integer name="SWITCH_BUTTON_MINUS_FOLDABLE_X">440</integer>
<integer name="SWITCH_BUTTON_MINUS_FOLDABLE_Y">550</integer>
<integer name="SWITCH_BUTTON_PLUS_FOLDABLE_X">560</integer>
<integer name="SWITCH_BUTTON_PLUS_FOLDABLE_Y">550</integer>
<integer name="SWITCH_BUTTON_HOME_FOLDABLE_X">600</integer>
<integer name="SWITCH_BUTTON_HOME_FOLDABLE_Y">550</integer>
<integer name="SWITCH_BUTTON_CAPTURE_FOLDABLE_X">400</integer>
<integer name="SWITCH_BUTTON_CAPTURE_FOLDABLE_Y">550</integer>
<integer name="SWITCH_BUTTON_DPAD_FOLDABLE_X">240</integer>
<integer name="SWITCH_BUTTON_DPAD_FOLDABLE_Y">420</integer>
</resources> </resources>