mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-22 12:15:38 +01:00
android: Set layout by fragment, not view
This commit is contained in:
parent
2b5dde162a
commit
0b442b6dd2
@ -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<EmulationFragmentArgs>()
|
||||
|
||||
private var isInFoldableLayout = false
|
||||
|
||||
private lateinit var onReturnFromSettings: ActivityResultLauncher<Intent>
|
||||
|
||||
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()
|
||||
|
@ -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
|
||||
|
@ -2,38 +2,6 @@
|
||||
<resources>
|
||||
<integer name="game_title_lines">2</integer>
|
||||
|
||||
<!-- Default SWITCH portrait layout -->
|
||||
<integer name="SWITCH_BUTTON_A_PORTRAIT_X">840</integer>
|
||||
<integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer>
|
||||
<integer name="SWITCH_BUTTON_B_PORTRAIT_X">740</integer>
|
||||
<integer name="SWITCH_BUTTON_B_PORTRAIT_Y">860</integer>
|
||||
<integer name="SWITCH_BUTTON_X_PORTRAIT_X">740</integer>
|
||||
<integer name="SWITCH_BUTTON_X_PORTRAIT_Y">780</integer>
|
||||
<integer name="SWITCH_BUTTON_Y_PORTRAIT_X">640</integer>
|
||||
<integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer>
|
||||
<integer name="SWITCH_STICK_L_PORTRAIT_X">180</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_Y">640</integer>
|
||||
<integer name="SWITCH_TRIGGER_L_PORTRAIT_X">140</integer>
|
||||
<integer name="SWITCH_TRIGGER_L_PORTRAIT_Y">240</integer>
|
||||
<integer name="SWITCH_TRIGGER_R_PORTRAIT_X">860</integer>
|
||||
<integer name="SWITCH_TRIGGER_R_PORTRAIT_Y">240</integer>
|
||||
<integer name="SWITCH_TRIGGER_ZL_PORTRAIT_X">140</integer>
|
||||
<integer name="SWITCH_TRIGGER_ZL_PORTRAIT_Y">180</integer>
|
||||
<integer name="SWITCH_TRIGGER_ZR_PORTRAIT_X">860</integer>
|
||||
<integer name="SWITCH_TRIGGER_ZR_PORTRAIT_Y">180</integer>
|
||||
<integer name="SWITCH_BUTTON_MINUS_PORTRAIT_X">440</integer>
|
||||
<integer name="SWITCH_BUTTON_MINUS_PORTRAIT_Y">950</integer>
|
||||
<integer name="SWITCH_BUTTON_PLUS_PORTRAIT_X">560</integer>
|
||||
<integer name="SWITCH_BUTTON_PLUS_PORTRAIT_Y">950</integer>
|
||||
<integer name="SWITCH_BUTTON_HOME_PORTRAIT_X">600</integer>
|
||||
<integer name="SWITCH_BUTTON_HOME_PORTRAIT_Y">950</integer>
|
||||
<integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_X">400</integer>
|
||||
<integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_Y">950</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_PORTRAIT_X">240</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_PORTRAIT_Y">820</integer>
|
||||
|
||||
<!-- Default SWITCH landscape layout -->
|
||||
<integer name="SWITCH_BUTTON_A_X">760</integer>
|
||||
<integer name="SWITCH_BUTTON_A_Y">790</integer>
|
||||
@ -66,16 +34,48 @@
|
||||
<integer name="SWITCH_BUTTON_DPAD_X">260</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_Y">790</integer>
|
||||
|
||||
<!-- Default SWITCH portrait layout -->
|
||||
<integer name="SWITCH_BUTTON_A_PORTRAIT_X">840</integer>
|
||||
<integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer>
|
||||
<integer name="SWITCH_BUTTON_B_PORTRAIT_X">740</integer>
|
||||
<integer name="SWITCH_BUTTON_B_PORTRAIT_Y">860</integer>
|
||||
<integer name="SWITCH_BUTTON_X_PORTRAIT_X">740</integer>
|
||||
<integer name="SWITCH_BUTTON_X_PORTRAIT_Y">780</integer>
|
||||
<integer name="SWITCH_BUTTON_Y_PORTRAIT_X">640</integer>
|
||||
<integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer>
|
||||
<integer name="SWITCH_STICK_L_PORTRAIT_X">180</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_Y">640</integer>
|
||||
<integer name="SWITCH_TRIGGER_L_PORTRAIT_X">140</integer>
|
||||
<integer name="SWITCH_TRIGGER_L_PORTRAIT_Y">240</integer>
|
||||
<integer name="SWITCH_TRIGGER_R_PORTRAIT_X">860</integer>
|
||||
<integer name="SWITCH_TRIGGER_R_PORTRAIT_Y">240</integer>
|
||||
<integer name="SWITCH_TRIGGER_ZL_PORTRAIT_X">140</integer>
|
||||
<integer name="SWITCH_TRIGGER_ZL_PORTRAIT_Y">180</integer>
|
||||
<integer name="SWITCH_TRIGGER_ZR_PORTRAIT_X">860</integer>
|
||||
<integer name="SWITCH_TRIGGER_ZR_PORTRAIT_Y">180</integer>
|
||||
<integer name="SWITCH_BUTTON_MINUS_PORTRAIT_X">440</integer>
|
||||
<integer name="SWITCH_BUTTON_MINUS_PORTRAIT_Y">950</integer>
|
||||
<integer name="SWITCH_BUTTON_PLUS_PORTRAIT_X">560</integer>
|
||||
<integer name="SWITCH_BUTTON_PLUS_PORTRAIT_Y">950</integer>
|
||||
<integer name="SWITCH_BUTTON_HOME_PORTRAIT_X">600</integer>
|
||||
<integer name="SWITCH_BUTTON_HOME_PORTRAIT_Y">950</integer>
|
||||
<integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_X">400</integer>
|
||||
<integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_Y">950</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_PORTRAIT_X">240</integer>
|
||||
<integer name="SWITCH_BUTTON_DPAD_PORTRAIT_Y">820</integer>
|
||||
|
||||
<!-- Default SWITCH foldable layout -->
|
||||
<integer name="SWITCH_BUTTON_A_FOLDABLE_X">830</integer>
|
||||
<integer name="SWITCH_BUTTON_A_FOLDABLE_X">840</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_B_FOLDABLE_X">740</integer>
|
||||
<integer name="SWITCH_BUTTON_B_FOLDABLE_Y">460</integer>
|
||||
<integer name="SWITCH_BUTTON_X_FOLDABLE_X">740</integer>
|
||||
<integer name="SWITCH_BUTTON_X_FOLDABLE_Y">380</integer>
|
||||
<integer name="SWITCH_BUTTON_Y_FOLDABLE_X">640</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_X">180</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>
|
||||
|
Loading…
Reference in New Issue
Block a user