Android Joystick support

Hi,

First of all let me apologize for the post mess; the forum.list
syncing wasn’t working for me for quite some time and I just changed
to using the list.
I’ve started a new thread so that the content will be easier to find later on.
I’ll be more careful with these things from now on.

I’ve updated the patch in bugzilla (
http://bugzilla.libsdl.org/show_bug.cgi?id=1700 ).
The Android >= 16 requirement was incorrect. I must’ve missread the
Android docs. The code did have two places where Android >= 12 is
needed:
* A constant -> I’ve replaced it by its value and documented where
the value came from.
* A method for determining the number of axes in a joystick -> On
earlier versions of Android a sane default (2) can be returned

So I’d say that the code should now include mostly correct joystick
support for Android 9-11 and correct behaviour for Android 12 and
over.

As for what you mention: I’ve been testing this in a cheap USB gamepad
connected to a Galaxy Nexus running 4.2 and for what I’ve seen, button
presses are sent as keyboard presses and hence must be processed there
whereas D-PAD & joystick moves are sent as joystick events. To my
knowledge, the OUYA controller works pretty much this same way.

It’d be interesting to know if this code works directly in the OUYA.
I’d say it should and will definitely test it ASAP.

Regards,
Joseba

As for what you mention: I’ve been testing this in a cheap USB gamepad
connected to a Galaxy Nexus running 4.2 and for what I’ve seen, button
presses are sent as keyboard presses and hence must be processed there
whereas D-PAD & joystick moves are sent as joystick events. To my
knowledge, the OUYA controller works pretty much this same way.

That’s exactly how it works, although I think the OUYA buttons are
sent as the letters “O”, “U”, “Y”, “A” (while on Android a controller
would probably return different letters, I presume). I don’t remember
how touchpad events are handled.

Hi,

First of all let me apologize for the post mess; the forum.list
syncing wasn’t working for me for quite some time and I just changed
to using the list.
I’ve started a new thread so that the content will be easier to find
later on.
I’ll be more careful with these things from now on.

Well, it’s simply an issue with the syncing. It’s surely better than me
having troubles while using the list from the very beginning, simply
because I’m trying to do some things the manual way (mainly replying)…

  • A constant -> I’ve replaced it by its value and documented where
    the value came from.
  • A method for determining the number of axes in a joystick -> On
    earlier versions of Android a sane default (2) can be returned

I can see why both of these are done. Since Android pre-3.1 does not
have native game controller support, though, I’ve wondered if a
different approach may be better (and only for API<12): Treat a gamepad
as a keyboard. We shouldn’t expect analog axes and trackpads to work,
but at least simple binary buttons and D-pads can. Of course this way
has its own issues.

As for what you mention: I’ve been testing this in a cheap USB gamepad
connected to a Galaxy Nexus running 4.2 and for what I’ve seen, button
presses are sent as keyboard presses and hence must be processed there
whereas D-PAD & joystick moves are sent as joystick events.

According to a couple of test apps, that is indeed what I have observed,
more or less. Can you use the D-pad, an analog stick or other axes for
navigating through various UI elements (like apps) on Android in
general? If yes, these could be related to the synthesized D-pad events,
as hinted by the KeyTest app
(https://github.com/chrisboyle/keytest/downloads). The same applies to
UI element presses/selections in the UI (possibly sending
KEYCODE_DPAD_CENTER events).