We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2358

Summary: [Android] Joystick Button Mappings are strange
Product: SDL Reporter: David Brady <dbrady>
Component: joystickAssignee: Gabriel Jacobo <gabomdq>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: API change    
Priority: P2 CC: gabomdq, philipp.wiesemann
Version: HG 2.1   
Hardware: All   
OS: Android (All)   
Attachments: Patch to re-assign button IDs
Sort Joystick axes
Fix for typo in button ID patch
Corrected sorting patch

Description David Brady 2014-01-22 02:12:58 UTC
Created attachment 1529 [details]
Patch to re-assign button IDs

The GameController API is very nice, but it would be great to fall back to the Joystick API if the GameController is not mapped.  But sadly, the button IDs for SDL Android do not correspond even slightly to button mappings on other platforms.  I would like to re-order the default button IDs to be somewhat reasonable, so that even unsupported controllers can be a little playable.

Patch is attached which reorders the basic joystick button IDs to match the GameController API (where applicable).
Comment 1 David Brady 2014-01-22 02:36:04 UTC
Created attachment 1530 [details]
Sort Joystick axes

Related to this bug...  This isn't the best solution to the problem, but joystick axes can come in a semi-random order.  This simply sorts them by axis ID, which works well for standard controllers (even more so if #2229 were accepted).  It might be better to explicitly reorder the left and right sticks to the first 4 axes, then sort the rest.  But I wanted to keep it simple.
Comment 2 David Brady 2014-01-22 02:47:07 UTC
Created attachment 1531 [details]
Fix for typo in button ID patch
Comment 3 Philipp Wiesemann 2014-01-22 23:30:57 UTC
(In reply to David Brady from comment #1)
> Created attachment 1530 [details]
> Sort Joystick axes
> 
> Related to this bug...  This isn't the best solution to the problem, but
> joystick axes can come in a semi-random order.  This simply sorts them by
> axis ID, which works well for standard controllers (even more so if #2229
> were accepted).  It might be better to explicitly reorder the left and right
> sticks to the first 4 axes, then sort the rest.  But I wanted to keep it
> simple.

The Comparator's compare() method could be simplified by just subtracting the two values. It does not have to be exactly -1/0/1 just negative/0/positive. [1]

[1] http://developer.android.com/reference/java/util/Comparator.html#compare(T, T)
Comment 4 Gabriel Jacobo 2014-01-23 11:45:43 UTC
Can you update your axis sorting patch with Philipp's recommendation (and fix spacing while you are at it :) )

Also, we don't use tabs, just four spaces, and comments use the old ANSI C style only (playing along with the fantasy that we are ANSI C compatible).

The button patch (with tabs fixed ;) ) is here: https://hg.libsdl.org/SDL/rev/7e01e3908f41
Comment 5 David Brady 2014-01-23 18:22:53 UTC
Created attachment 1534 [details]
Corrected sorting patch

Thank you Gabriel.  My apologies for the style, I forgot to fix it up.  I'll be better about that in the future.  Here's the corrected patch.
Comment 6 Gabriel Jacobo 2014-01-24 12:55:27 UTC
There was a missing "import java.util.List;" :)

Fixed in https://hg.libsdl.org/SDL/rev/d7b7ec662687