Skip to content

Commit

Permalink
Hide touch controls if gamepad is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloG02 authored and lynxnb committed Jul 3, 2023
1 parent 95de8f9 commit abc9b91
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/src/main/java/emu/skyline/EmulationActivity.kt
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit abc9b91

Please sign in to comment.