mirror of
https://github.com/Takiiiiiiii/strato.git
synced 2025-07-17 08:46:39 +00:00
Hide touch controls if gamepad is detected
This commit is contained in:
@ -376,6 +376,8 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
setOnClickListener { binding.onScreenControllerView.isInvisible = !binding.onScreenControllerView.isInvisible }
|
||||
}
|
||||
|
||||
binding.onScreenControllerView.isInvisible = isControllerConnected()
|
||||
|
||||
binding.onScreenPauseToggle.apply {
|
||||
isGone = !emulationSettings.showPauseButton
|
||||
setOnClickListener {
|
||||
@ -641,6 +643,23 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
||||
}
|
||||
}
|
||||
|
||||
private fun isControllerConnected() : Boolean {
|
||||
val deviceIds = InputDevice.getDeviceIds()
|
||||
|
||||
deviceIds.forEach { deviceId ->
|
||||
InputDevice.getDevice(deviceId).apply {
|
||||
// Verify that the device has gamepad buttons, control sticks, or both.
|
||||
if (sources and InputDevice.SOURCE_GAMEPAD == InputDevice.SOURCE_GAMEPAD
|
||||
|| sources and InputDevice.SOURCE_JOYSTICK == InputDevice.SOURCE_JOYSTICK) {
|
||||
// This device is a game controller.
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
override fun dispatchKeyEvent(event : KeyEvent) : Boolean {
|
||||
return if (inputHandler.handleKeyEvent(event)) true else super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
Reference in New Issue
Block a user