Hide touch controls if gamepad is detected

This commit is contained in:
PabloG02
2023-06-28 01:06:46 +02:00
committed by Niccolò Betto
parent 95de8f9d59
commit abc9b91c13

View File

@ -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)
}