| Summary: | [Android] Joysticks do not have unique IDs | ||
|---|---|---|---|
| Product: | SDL | Reporter: | David Brady <dbrady> |
| Component: | joystick | Assignee: | Sylvain <sylvain.becker> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | gabomdq |
| Version: | HG 2.1 | ||
| Hardware: | All | ||
| OS: | Android (All) | ||
| Attachments: |
Patch to get the descriptor for the device.
patch with multiple API |
||
The patch does not apply cleanly right now, besides that, getJoystickDescriptor is pasted twice (once inside DummyEdit) As a matter of style, perhaps it would be best to create a SDLJoystickHandler_API16 class that inherits from SDLJoystickHandler_API12 where getJoystickDescriptor is based on InputDevice.getDescriptor, overriding a base method which just returns the joystick name (or whatever alternative we can fiure out). Sorry, this patch was extremely rushed, as I'm trying to ship a project. I mostly just wanted to see if it would be accepted. I'll clean it up and try to resubmit next week. I'm not sure I understand what it is that you would like me to do with it though? I would really rather not bump up the minimum API version to 16, that's why I used reflection to call the function instead of calling it directly. It sounds like you want me to create an API16 class that calls the function directly if we target API16? I'm pretty new to Java, so sorry if I'm misunderstanding something. It's quite easy to do, if you look at how SDLJoystickHandler_API and SDLJoystickHandler_API12 work.
Basically, SDLJoystickHandler_API is an empty class that gets instantiated if the API level of the device is <= 11, and SDLJoystickHandler_API12 gets instantiated in devices that actually support joysticks:
if(Build.VERSION.SDK_INT >= 12) {
mJoystickHandler = new SDLJoystickHandler_API12();
}
else {
mJoystickHandler = new SDLJoystickHandler();
}
You can add a new SDLJoystickHandler_API16 that inherits from SDLJoystickHandler_API12 and that goes to town with any API level 16 functions, just as long as you instantiate it correctly depending on Build.VERSION.SDK_INT
It's the same reflection trick essentially, but what I suggested falls in line with what SDLActivity is doing now.
That's what I had thought when I originally saw that code, but I've never been able to get the project to build with API9. Is there some trick to that? API 9 is not supported by SDL, the minimum is 10. If 10 does not work, it's a bug :) Requirements are listed at the top of this file: https://hg.libsdl.org/SDL/file/d7b7ec662687/README-android.txt I meant 10... It definitely does not work for me. I must have some trouble in my project setup somewhere if it works for you. Are you building from Eclipse or the command line, or both? Only command line. The only "trick" I can think of is that you have to build against an API of level 12 (target=android-12). This does not prevent the app from running on level 10 devices though, due to the introspection thingy. Hey Sylvain, you want to take a crack at implementing this patch using the correct API level abstraction? Does it look like a good change in general? Created attachment 2897 [details]
patch with multiple API
Hi !
Here's a patch with a API16 class extending API12 to provide the joystickDescriptor string.
Fixed, thanks! https://hg.libsdl.org/SDL/rev/3e57ce45a890 |
Created attachment 1536 [details] Patch to get the descriptor for the device. When I attempted to make a mapping file for Android gamepads, I quickly discovered that most of the ones that I have here show up as the same device (Broadcom Bluetooth HID), meaning that it was impossible to make mappings on Android, since every device looked the same. This patch will check for the existence of the getDescriptor function added in Jelly Bean, and use it if it's there. The Android Dashboard says that the majority of Android phones should support this function, and doing it this way will not force us to bump up our API version.