Commit graph

166 commits

Author SHA1 Message Date
Cole Campbell
c3ab42cd1f Commit KEYCODE_SPACE as text input on Android 2016-07-04 10:39:32 -04:00
Sam Lantinga
d7c4e4aa49 Fixed bug 3426 - Fixes for joystick related issues
ny00

This report is going to cover three issues, with a suggestion for fixes. For reference, tests were done using an installation of android-x86-5.1-rc1.iso within a VirtualBox session. I've actually used an adapter that accepts up to two Playstation 1/2 controllers.

A ZIP file should be attached, with the following contents:
- The patch file itself.
- Outputs of joysticks lists from testjoystick with different orders (before fixing bug).
- Game controllers database entries (for reference).
--- Different outputs for different platforms may stem from different tools being used; The Android mapping was manually constructed using a previously available mapping as a base.
--- Note that it turns out the Linux mapping is already out there in some form: https://github.com/gabomdq/SDL_GameControllerDB/blob/master/gamecontrollerdb.txt

And so, let's begin listing the issues:

1. While changeset https://hg.libsdl.org/SDL/rev/f6567f77f663 has good intentions, it appears to make various input devices being mistakenly detected as SDL joysticks. I got lists of the devices from joysticktest, given in the ZIP file. "badordering.txt" is what I get if the device has been plugged since a reboot of the virtual machine, while I've gotten "goodordering.txt" after hot-plugging the USB adapter. As expected, only in the latter case I could use the controller in the test program (assuming it isn't modified).

To take care of this, I updated pollInputDevices and added the function SDLActivity.isDeviceSDLJoystick, in order to have a better filter. Note that it also checks that the device id is non-negative, since VIRTUAL_KEYBOARD appears to include a SOURCE_DPAD, and I should probably keep accepting it as an SDL_joystick (good if you want, say, to support multiple independent d-pad devices).

I hope the device id filter does not break support for the virtual remote (mentioned in the changeset above).

2. So there's a weird glitch here, where the game controller is reported to have SOURCE_KEYBOARD and SOURCE_JOYSTICK, while each controller button press/release emits a KeyEvent with SOURCE_KEYBOARD only. So obviously any test going over the event's own sources is expected to fail.

It is possible to try and filter by the key code, but then there are the dpad key codes, which can also be emitted by actual PC keyboard's key presses/releases (the arrow keys).

So instead, I just call the newly added isDeviceSDLJoystick function again and check if the input device (not the event) has any source considered to be a joystick/gamepad for us.

3. Finally, if SDL2 properly detects an SDL_Joystick being connected, but it is not opened, then whenever a KeyEvent is received after a button press/release from the same controller, SDLActivity.onNativePadDown/onNativePadUp returns a negative value. In such a case, the onKey handler continues to check for SOURCE_KEYBOARD (and possibly also SOURCE_MOUSE), which is clearly not desired.

And so, in the given patch, the return values of onNativePadDown and onNativePadUp are ignored and "true" is returned either way.

(Note: Maybe the native functions should be modified to have the return value of "void".)

Finally, as another side-note, I've noticed that the various bitwise tests for sources are wrong. For instance, to check if an InputDevice 'device' has source SOURCE_JOYSTICK, the value (device.getSources() & SOURCE_JOYSTICK) should be compared to SOURCE_JOYSTICK, not 0.
However, I think there's enough that this patch covers. At the least, isDeviceSDLJoystick partially solves this.
2016-09-29 16:52:48 -07:00
Sam Lantinga
82e80692e1 Fixed bug 3427 - Android accelerometer z-axis incorrect
Alex Szpakowski

As seen here https://bitbucket.org/rude/love/issues/1202/accelerometer-z-axis , the Java code for sending accelerometer data to SDL's C code has an incorrect Z-axis calculation.
2016-09-29 16:40:34 -07:00
Philipp Wiesemann
aee365bac1 Android: Removed unused internal function. 2016-08-30 21:15:46 +02:00
Ryan C. Gordon
1ef00d5809 android: implement audio capture support. 2016-08-11 22:04:49 -04:00
Philipp Wiesemann
a07ce859b0 Android: Updated a comment. 2016-07-27 20:47:08 +02:00
Philipp Wiesemann
b8ba8f4d1e Android: Replaced deprecated AbsoluteLayout with RelativeLayout.
Fixes Bugzilla #2211.
2016-07-27 20:46:18 +02:00
Philipp Wiesemann
97ea1e70a3 Android: Fixed ignoring a return value while handling motion events.
This should not have caused problems yet because the return value was identical.
2016-01-26 22:20:05 +01:00
Philipp Wiesemann
e50b7e4996 Android: Fixed finishing Activity on some devices if right mouse button pressed.
Partially fixes Bugzilla #3227.
2016-01-13 19:31:03 +01:00
Philipp Wiesemann
acfa3cd6b7 Android: Fixed a comment. 2016-01-12 22:22:24 +01:00
Philipp Wiesemann
ab3959041f Android: Added missing import statement.
It did not compile without.
2015-10-15 22:26:00 +02:00
Ryan C. Gordon
9a5276c5ba Fix some Android keyboards that didn't work properly.
This conversation came from Joshua Granick on Twitter, starting here:

https://twitter.com/singmajesty/status/653640543675641857

"We found an issue where certain Android keyboards (like the S6 with
predictive text) wouldn't work ... Certain keyboards use a predictive text
mode that does not dispatch a traditional onKey events, which is troublesome
... but telling the OS to use a "visible password" keyboard helps deal with
this problem ... perhaps there's some other way (onKeyPreIme?) to do
"textediting" events, but for now, this should be a fast fix ...
I hear it affects the Galaxy Tab A 8.0", Galaxy S6, Asus ZenPhone 2, maybe
others"
2015-10-15 12:52:00 -04:00
Philipp Wiesemann
0695fbe89f Android: Added a new method in SDLSurface. 2015-10-07 21:16:40 +02:00
Philipp Wiesemann
30f533b548 Android: Removed three internal functions not used by SDL.
They were not needed internally since the switch to the common EGL backend.

Thanks to the SDL mailing list for pointing out that the functions seem unused.
2015-09-27 20:12:47 +02:00
Philipp Wiesemann
1a31b4723b Android: Improved last error message for failed APK expansion file use. 2015-09-18 21:26:28 +02:00
Philipp Wiesemann
d1ffadbeb6 Android: Added additional error messages for APK expansion file use. 2015-09-17 22:36:11 +02:00
Philipp Wiesemann
8fa156a2f8 Android: Fixed trying to read from APK expansion files without version hint set.
This also fixed overwriting the asset error message which is more useful if no
APK expansion files are available and the requested file was not found.
2015-09-17 22:30:24 +02:00
Philipp Wiesemann
2ab482abc1 Android: Renamed SDLActivity's Java method used for APK expansion files.
The name was not correct.
2015-09-17 22:24:54 +02:00
Philipp Wiesemann
e3768b7fc3 Android: Removed empty onDraw() override method from SDLActivity.
It was redundant because SDLActivity already inherits an empty method from the
base class SurfaceView (which does not implement it but inherits it from View).
Visibility of onDraw() in SDLActivity is now protected again instead of public.
2015-09-17 22:14:37 +02:00
Philipp Wiesemann
36a91d1b09 Android: Fixed unused variable warning. 2015-09-05 20:21:35 +02:00
Philipp Wiesemann
298097bcff Android: Fixed missing break warning. 2015-09-05 20:21:06 +02:00
Sam Lantinga
34a0b04786 Fixed bug 2949 - [Android] Virtual DPAD remote not registered
Sylvain

I have an android device to which I try to connect the google virtual remote application.
https://play.google.com/store/apps/details?id=com.google.android.tv.remote

The java method "pollInputDevices()" detects it as an input source 0x701 which is (SOURCE_KEYBOARD | SOURCE_GAMEPAD | SOURCE_DPAD).

It it not added because it does not AND-bitwise with "SOURCE_CLASS_JOYSTICK".
It's only a virtual DPAD and it works when checking also with SOURCE_CLASS_BUTTON
2015-06-16 23:58:09 -07:00
Sam Lantinga
945a347ea0 Fixed bug 2774 - Android: screen distorted in Landscape after background/foreground
Sylvain

With a Landscape application.
Going to background with Home Key, then foreground.
The screen is distorted.

This has been reported by Samsung. It happens on S5 and Samsung Alpha, see the video attached.

I have captured the following logcat:

V/SDL     (20549): onResume()
V/SDL     (20549): surfaceCreated()
V/SDL     (20549): surfaceChanged()
V/SDL     (20549): pixel format RGB_565
V/SDL     (20549): Window size:1920x1080
I/SDL     (20549): SDL_Android_Init()
I/SDL     (20549): SDL_Android_Init() finished!
V/SDL     (20549): SDL audio: opening device
V/SDL     (20549): SDL audio: wanted stereo 16-bit 22.05kHz, 256 frames buffer
V/SDL     (20549): SDL audio: got stereo 16-bit 22.05kHz, 1764 frames buffer
V/SDL     (20549): onWindowFocusChanged(): true
V/SDL     (20549): onWindowFocusChanged(): false
V/SDL     (20549): onPause()
V/SDL     (20549): nativePause()
V/SDL     (20549): surfaceDestroyed()

Background / Foreground

V/SDL     (20549): onResume()
V/SDL     (20549): surfaceCreated()
V/SDL     (20549): surfaceChanged()
V/SDL     (20549): pixel format RGB_565
V/SDL     (20549): Window size:1080x1920
V/SDL     (20549): surfaceChanged()
V/SDL     (20549): pixel format RGB_565
V/SDL     (20549): Window size:1920x1080
V/SDL     (20549): onWindowFocusChanged(): true
V/SDL     (20549): nativeResume()



This seems to be related to the fact that I have in "AndroidManifest.xml":
android:configChanges="..."
Because of the fields: "orientation" and also "screenSize".


I have looked for another way to solve the issue. Discarding the "surfaceChanged" call, based on the "requestedOrientation" and the new Orientation. It seems to be better.


On my failing test case, the first "surfaceChanged()" is discarded. Sometimes the "focusChanged()" might appear between the two "surfaceChanged()", while the surface is not yet ready. Thus, discarding also the "nativeResume()".

So, for robustness, a call to "nativeResume()" is added at the end of "surfaceChanged()".

Some update:

1/ First I tried, to discard the surface using the current orientation (rather than width / heigh). -> that solve the issue sometimes, but not always.

2/ Samsung Certification now accepts my application that were previously failing.

3/ I personally now owns a Samsung S5, and was able to solve the issue on my side.

4/ I now use the patch and get no complaints from my users. (but I admit, nobody seemed to be complaining before neither...).

5/ I have added a v2 because of a new smart-phone called "Black Berry Passport" that has a square screen of 1440x1440. This screen has a "status bar" so the resolution is in fact : 1440x1308. (as reported by "surfaceChanged").

Problem is: the portrait resolution is in fact a Landscape!

So the "v1" patch is always discarding the "surface" of BlackBerry Passport. Which is terribly bad.


Hence, I added the "v2" patch not to discard the surface when aspect ratio is < 1.20. (BB 1440/1308 is : 1.1009). Which seems fair.
2015-06-16 22:16:35 -07:00
Philipp Wiesemann
18be5eb77d Android: Added missing space in three log messages.
Also fixed a typo and changed tag string to constant.
2015-05-31 19:23:16 +02:00
Ryan C. Gordon
ca08bb0d98 Android: Added basic drop file support (thanks, "noxalus"!).
This lets SDL-based apps respond to "Open With" commands properly, as they
can now obtain the requested path via a standard SDL dropfile event.

This is only checked on startup, so apps don't get drop events at any other
time, even if Android supports that, but this is still a definite
improvement.

Fixes Bugzilla #2762.
2015-05-26 20:36:45 -04:00
Philipp Wiesemann
1674b49dc4 Android: Fixed touch pressure being out of range.
According to the documentation of Android's MotionEvent, the getPressure() may
return values higher than 1 on some devices. To prevent passing such values into
SDL they are now corrected to 1 in Java before the JNI call (where it is assumed
to be correct).

Currently SDL only sends SDL_FINGERMOTION events if the touch state (position or
pressure) changed. By correcting pressure down to 1 some events may get dropped
in the rare case that only the pressure was changed but was out of range and the
position did not change.
2015-05-22 22:34:08 +02:00
Philipp Wiesemann
0e132b3325 Android: Replaced logging tag strings with constant. 2015-05-16 21:15:59 +02:00
Reto Schneider
0970b3829d Remove trailing spaces in Android source code. 2015-04-08 12:14:36 +02:00
Philipp Wiesemann
0f74f5f039 Android: Fixed calling a getter method twice. 2015-04-08 22:24:33 +02:00
Ryan C. Gordon
b344c3f2ed Log Android hardware at startup (thanks, rettichschnidi!).
Fixes Bugzilla #2653.
2015-04-08 01:37:17 -04:00
Joseba García Etxebarria
ddad0a1315 Cast the result of calling getButtonState to an Integer 2015-04-02 00:55:45 +02:00
Ryan C. Gordon
bedac6b53a Android: more separate-mouse-and-touch work.
This avoids a hint lookup for each mouse event we get by setting a static Java
variable from native code during our hint watcher callback.

Also attempts to do the right thing with mouse buttons if you happen to be
on an API14 (Ice Cream Sandwich, Android 4.0) or later device. We still
target API12 (Honeycomb MR1, Android 3.1) for SDL 2.0.4 though.

This isn't tested, so I'm pushing to see what the Android buildbot says. Stand
back, I'm a professional!

--HG--
extra : amend_source : 7748c650f37edd47c721e4e7e96cf5995f5ac459
2015-04-01 12:14:56 -04:00
Joseba García Etxebarria
1163b6da1c Renamed SDLGenericMotionListener back to SDLGenericMotionListener_API12 2015-03-27 18:09:51 -04:00
Philipp Wiesemann
8f0ea4bcf7 Android: Removed outdated comment from source. 2015-03-25 22:47:22 +01:00
Joseba García Etxebarria
e997a4144d * More Android patch work 2015-03-24 21:02:28 +01:00
Joseba García Etxebarria
3dcf5c743f * Improve mouse support in Android. These changes require Android API v12 to compile 2015-03-24 20:45:29 +01:00
Philipp Wiesemann
97b6937ee2 Fixed wrong comment in implementation for Android. 2015-01-31 10:32:45 +01:00
Philipp Wiesemann
d2aee7d409 Fixed bug 2816 - [patch] Android: Expose screen refresh rate
Jonas Kulla

Display::getRefreshRate() is available on all API levels.
2015-01-23 20:29:08 +01:00
Philipp Wiesemann
1f37dea55a Added name for second Java Thread on Android. 2014-11-23 20:35:51 +01:00
Philipp Wiesemann
7da09eba59 Fixed bug 2759 - Android findLibrary() returns NULL
Sylvain

extra patch with minor modifications:
- typo
- cancel-able set to false
- add the error message, so that the user can report it.
2014-10-24 11:53:34 +02:00
Philipp Wiesemann
2b40ad3b10 Added an option to define libraries to be loaded on Android in a derived class.
This way it is no more needed to modify SDLActivity.java to add own libraries.
2014-10-23 16:45:18 +02:00
Philipp Wiesemann
1e55e039ec Fixed alert dialog for not loaded libraries on Android being cancelable.
If the alert dialog could be canceled the Activity would not be finished here.
Also setting the property to "true" would be redundant because that is default.
2014-10-23 16:41:01 +02:00
Philipp Wiesemann
1d8143941f Fixed missing @Override annotation warning in source for Android. 2014-10-23 16:39:15 +02:00
Philipp Wiesemann
5767c4b5a3 Fixed upper case button in alert dialog for not loaded libraries on Android.
This is more consistent with the buttons of other dialogs on Android.
2014-10-23 16:38:03 +02:00
Philipp Wiesemann
25e97e03c9 Fixed typo in message of alert dialog for not loaded libraries on Android. 2014-10-23 16:34:48 +02:00
Philipp Wiesemann
db76896e79 Fixed writing new errors to standard output instead of error output on Android. 2014-10-23 16:33:27 +02:00
Philipp Wiesemann
8b744670c3 Fixed documentation in source for Android. 2014-10-23 16:31:02 +02:00
Gabriel Jacobo
c77c91bb2a [Android] #2759: Show a message on failure to load a .so library (by Sylvain) 2014-10-21 11:44:35 -03:00
Philipp Wiesemann
69e989c667 Fixed setting of screen saver state crashing on some version of Android.
Setting Window flags seems to affect Views and must be handled on UI thread.
2014-10-20 22:19:09 +02:00
Gabriel Jacobo
0ec4fc6589 Bug 2739 - [Android] No support for SDL_DisableScreenSaver by Martin Gerhardy 2014-10-20 10:10:39 -03:00