Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide touch controls if gamepad is detected when booting game #52

Merged
merged 1 commit into from Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/src/main/java/emu/skyline/EmulationActivity.kt
Expand Up @@ -374,6 +374,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 @@ -639,6 +641,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