Commit Graph

76 Commits

Author SHA1 Message Date
Sam Lantinga
6ed184ec69 Added SDL_IsAndroidTV() 2018-02-06 15:03:35 -08:00
Sam Lantinga
fab2e2463f Removed armeabi from the SDL build API list, since it's not supported by the latest Android SDK 2018-01-27 12:07:05 -08:00
Sam Lantinga
616827ae64 Fixed bug 4001 - Android, prevent error message box to crash
Sylvain

Prevent the error message box to crash after being clicked.
Because of "SDLActivity.mSingleton.finish();"
2017-12-19 11:19:10 -08:00
Sam Lantinga
b92e2f027a Fixed bug 4004 - iOS: don't hide keyboard on RETURN
Dominik Reichardt

As discussed in 2012 the iOS onscreen keyboard hides when you hit RETURN (see https://discourse.libsdl.org/t/on-screen-keyboard-change/19216).
IMO this is a bad idea to not be able to influence this behavior and just recently this was fixed for Android by adding the hint SDL_HINT_ANDROID_RETURN_HIDES_IME in changeset 11768	6ce3bb5e38a5.
2017-12-19 10:57:21 -08:00
Sam Lantinga
2afc0b7fa5 Add the ability to set SDL to handle Return as 'hide IME' on Android softkeyboard. (thanks Rachel!) 2017-12-12 12:52:23 -08:00
Sam Lantinga
c317ab978f Fixed Android build error on older SDK 2017-11-12 10:59:05 -08:00
Sam Lantinga
50e422adfe Fixed bug 3917 - Android, issues with getManifestEnvironmentVariable
Sylvain

What about getting some return code instead of creating another native function.
2017-11-04 22:03:28 -07:00
Sam Lantinga
758156a765 Fixed bug 3917 - Android, issues with getManifestEnvironmentVariable
We're going to push the manifest environment variables from the Java side instead of continually querying for them from the native side.
2017-11-04 09:37:29 -07:00
Sam Lantinga
bb8c3a9cc2 Make SDL fullscreen windows on Android actually fullscreen 2017-11-02 10:41:55 -07:00
Sam Lantinga
522901b88d Fixed bug 3933 - Android, no need of the listener thread
Sylvain

A listener thread has been added to know when the native thread would end.
But now, it is more easy to only check that after the main function has returned. It's one thread less.
2017-11-02 08:46:14 -07:00
Sam Lantinga
8c46580231 Allow the activity to persist through connecting or disconnecting a keyboard 2017-11-01 18:41:11 -07:00
Sam Lantinga
62c3acaf9f Moved the meta-data into the right section 2017-11-01 18:40:11 -07:00
Sam Lantinga
a90be440e8 Added controller mapping for Android TV remotes
Also fixed the back button on the remote exiting the application
2017-11-01 10:06:58 -07:00
Sam Lantinga
4478707b0a Add SDL_GetDisplayDPI implementation on Android. (thanks Rachel!) 2017-10-31 13:49:59 -07:00
Sam Lantinga
6d23ea4bf0 Fixed Java string comparison with "" 2017-10-29 21:09:09 -07:00
Sam Lantinga
8e37bed3b6 android: Fix softkeyboard issue in SDL on Android. 2017-10-26 10:41:38 -07:00
Sam Lantinga
8fd0c22adc Added the ability to set SDL hints from AndroidManifest.xml (thanks Rachel!)
This is especially useful for things like the accelerometer hint which could be needed before application main().
2017-10-24 00:17:07 -07:00
Sam Lantinga
45536710f3 Fixed crash if mSurface isn't set up when we pause the application 2017-10-24 00:04:40 -07:00
Sam Lantinga
81f7e0c1f7 Removed unneeded file automatically generated by Android Studio 2017-10-23 23:35:04 -07:00
Sam Lantinga
b8d8a1f122 Updated the minimum and target SDK versions in AndroidManifest.xml 2017-10-23 23:26:40 -07:00
Sam Lantinga
edf0fae139 Updated Android build tools version, which bumped minimum deployment target to API 14
Also added native code to the Android gradle project, which allows using gradle or Android Studio to build the entire SDL application without a separate ndk-build step.
2017-10-23 23:23:47 -07:00
Sam Lantinga
76cdce440c Fixed build with older Android SDK 2017-10-23 23:23:34 -07:00
Sam Lantinga
f08480af78 Switched to new style gradle Android application build process 2017-10-23 15:23:43 -07:00
Sam Lantinga
c339d9ed6d Reverted changes 6acdea394736 and 1448a2ac30fe
I don't want to introduce any regressions with Android TV remote support
2017-10-20 10:29:22 -07:00
Sam Lantinga
2001898dce Fixed Android joystick detection 2017-10-19 15:37:52 -07:00
Sam Lantinga
9d9be45682 Don't use DPAD devices as joystick input on Android 2017-10-19 13:54:56 -07:00
Sam Lantinga
dff56c3497 Android Studio code analyzer fixes 2017-10-13 19:55:07 -07:00
Sam Lantinga
14ed0d24c8 Fixed bug 3843 - Android missing some code in SDLHapticHandler
Sylvain

Some check for android SDK version are missing from https://hg.libsdl.org/SDL/rev/3d7a29a369a0
here's a patch
2017-09-23 12:37:09 -07:00
Sam Lantinga
82557750b0 Separated out SDL Android java code so audio, controller, and filesystem APIs can be used independently of the SDL activity, in Qt apps for example. 2017-09-22 08:31:56 -07:00
Sam Lantinga
53b2c91d26 Separated out SDL Android java code so audio, controller, and filesystem APIs can be used independently of the SDL activity, in Qt apps for example. 2017-09-22 08:30:46 -07:00
Sam Lantinga
6c38c9007b Update Android SDK required to API level 16
Sylvain

Some API 16 methods are used (InputDevice: getDescriptor(), getVibrator()), so we need to compile at least with SDK API 16. Hence default.properties and project.properties have been modified to use android-16.

There are also some modification to SDLActivity.java not to use getVibrator() if we run under API 16. And not to check to presence of hasVibrator() if we are under API 11.
-some hard-coded constant can be expandend.
- rename a local variable (hasVibrator to hasVibratorService)
2017-08-31 15:12:08 -07:00
Sam Lantinga
347fe70432 Fixed bug 3789 - Android : small clean up
Sylvain

Since https://hg.libsdl.org/SDL/rev/6546daa45a02
SDL_android_main.c is empty and then produce a warning
nativeInit does not exist and dont need to be mark undefined
2017-08-30 14:25:01 -07:00
Sam Lantinga
c684eb2cde Add a way to set the context when other activities are active so many SDL API functions still work. 2017-08-28 23:04:47 -07:00
Sam Lantinga
60182eb71b Allow overriding the main entry point on Android 2017-08-28 14:40:21 -07:00
Sam Lantinga
dbb0a2aa74 Removed the need for libSDL2main.a on Android, and separated JNI initialization out for other integrations 2017-08-28 14:34:15 -07:00
Sam Lantinga
2a945b44cb Fixed bug 2361 - [Android] Joysticks do not have unique IDs
David Brady

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.
2017-08-28 10:03:39 -07:00
Sam Lantinga
c45932ba7e Fixed bug 2277 - Hardware keyboard control key sequences don't get reported
chw

Control key sequences from hardware keyboards (wireless/USB/bluetooth) get not properly reported on Android devices.
The attached patch uses the idea from http://stackoverflow.com/questions/12337117/capture-all-ctrl-under-android to make control key sequences appear as normal SDL_KEYDOWN events instead of cooked text input.
2017-08-28 09:54:16 -07:00
Sam Lantinga
fe21a74763 Fixed bug 2266 - please add notifications for clipboard updates on Android
Sylvain

Hi! here's a patch for that with two class loaded regarding API level.
Test both case : before API 11 and after.

I also remove now unused GetSystemServiceFromUIThread() and minor clean-up (haptic warning prototype).
2017-08-27 18:43:52 -07:00
Sam Lantinga
6885bc88bf Fixed bug 2265 - Voice to text feature on Android repeats some text via SDL_TEXTINPUT
Sylvain

Small patch for this issue. I tested it and it seems to work.

- it can send several backspaces (instead of only 1).
- it calls directly "sendKeyEvent()" instead of "super.sendKeyEvent()".
  otherwise, it would go through the android internals, calling again "onKey()".
  and then the "backspace" would arrive after the next "commitText()".
2017-08-27 18:36:54 -07:00
Sam Lantinga
d03409e118 Fixed bug 3191 - haptic system on android?
Sylvain

- add vibrator service in the list of haptic devices. I use an hard-coded device_id for it ...
2017-08-14 06:18:08 -07:00
Sam Lantinga
e54eede265 Provide the correct state of the on-screen keyboard to the API (patch from Sylvain) 2017-08-13 21:05:15 -07:00
Sam Lantinga
6ee661398d Fixed bug 3235 - Make the Android window creation similar to iOS' window creation
Sylvain

Here's a patch.
It tries to get the hint first. Resizable will allow any orientation. Otherwise it uses width/height window.

setOrientation method is splitted in static and non-static, so that it can be overloaded in a user subclass.

Some artefact observed :
surfaceChanged() can be called twice at the beginning. When the phone starts in portrait and run a landscape application.
2017-08-13 20:55:59 -07:00
Sam Lantinga
0a52db54bd Fixed bug 3191 - haptic system on android?
Patch provided by jintiao and Milan Nikolic, thanks!
2017-08-12 08:15:09 -07:00
Sam Lantinga
df5898b0d3 Fixed bug 3464 - Fix for Android hint SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH
ny00

According to the current documentation in SDL_hints.h, if SDL_HINT_ANDROID_SEPARATE_MOUSE_AND_TOUCH is set to "0" (or not set at all) then mouse input should lead to touch events, along with corresponding *fake* mouse events with mouse id SDL_TOUCH_MOUSEID.

However, while moving a mouse around (actually using a trackpad identified as a mouse), I get SDL mouse motion events with differing mouse ids, as follows:
- If the mouse is moved while a mouse button is pressed, the mouse id is SDL_TOUCH_MOUSEID.
- Otherwise, the mouse id for mouse motion events is 0.

I've attached sample code for reference, which includes logs of the various mouse events (the "which" field is covered).

I believe that no actual mouse event should arrive, if the hint is unset. In particular, no mouse motion event should arrive while no mouse button is pressed.

I'm going to attach a patch which resolves this, while also disabling mouse wheel motion events.
2017-08-11 13:37:40 -07:00
Sam Lantinga
a47bf37464 Fixed bug 3728 - [Android] crash when shared libraries are no loaded
Sylvain

On Android, when shared libraries are not correctly loaded (eg SDLActivity.mBrokenLibraries is true), there is a pop-up with an error message.

After user dismisses the pop-up, application crashes:
- because the native function "nativePause()" may no be loaded (if libSDL2.so is not loaded).
- because mSurface is null.
2017-08-09 20:23:48 -07:00
Ryan C. Gordon
a9c7bc85f1 android: add screenSize to AndroidManifest's configChanges (thanks, Daniel!).
Fixes Bugzilla #3448.

"Starting with Android API 13, another configuration change must be declared
to be handled by the app if it is desired to not let the system handle
rotation itself:

https://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

This will have effect if either a developer or SDL per default will set target
API > 12. Currently it is set to 12, but this might change in the future, like
when applying this patch: https://bugzilla.libsdl.org/show_bug.cgi?id=3445

The effect of not having this change applied is that the SDL app is destroyed
upon rotation. Even when the manifest has an additional entry to e.g. always
stay in landscape mode, the onDestroy() call will happen on devices that are
portrait per default, when switching off screen due to power save. The device
will then (at least try to) rotate into portrait to show the portrait screen
lock after resume.

I believe it is safe to apply this patch even with target API still set to 12,
the additional parameter is simply ignored."
2017-05-19 15:06:05 -04:00
Ryan C. Gordon
366adae360 android: More robust fix for screen locking in landscape (thanks, Sylvain!).
Fixes Bugzilla #3562.

From Sylvain:

"With an android landscape application, if you quickly lock, then unlock your
device, you can see sometimes a quick glitch: screen badly draws in portrait,
then it correctly displays in landscape.

Not talking of a smooth rotation, it's a drawing glitch. And you need to have
a plain lock screen, with no model nor passphrase.


I think it happens because the call to "nativeResume()" occurs sometimes too
early.

It should be done once you have *all* those three things (in any sequence):
- onWindowsFocusChanged() set to true
- onResume() called
- a valid call to onSurfaceChanged()


Currently, this is not the case: you don't need to have onResume() called.
Just need to have isPaused, (eg onPaused()).
So "isPaused" should be renamed as "isResumedCalled".
But you also need some kind of isPaused state to make sure to don't call
nativePause() twice (and deadlocks...).
There are also redundant checks to "mHasFocus" and some creation of the
initialisation thread code from onSurfaceChanged() that could me moved.

So here's this patch:
- add some states, so we have cleaner transitions.
- make sure "onResume()" is called.
- some clean up
- it also goes faster in pause state (focus changed, onPause, without requiring isSurfaceReady which does seems to be needed).


Tested on a few devices and it removes the glitch.
But I haven't tested when the activity goes back to "init" state."
2017-04-07 20:17:30 -04:00
Ryan C. Gordon
2092a88359 android: fix wrong events when locking device in landscape (thanks, Joshua!).
"Using an application in portrait orientation, turning off the device would
dispatch SDL_APP_WILLENTERBACKGROUND, then SDL_APP_DIDENTERBACKGROUND then
lock the screen.

However, rotating the application the application to landscape, then turning
off the device would incorrectly dispatch SDL_APP_WILLENTERBACKGROUND,
SDL_APP_WILLENTERBACKGROUND, SDL_APP_WILLENTERFOREGROUND and then
SDL_APP_DIDENTERFOREGROUND before locking the screen. You can imagine how
this created trouble :)

It appears this occurs because (on this application) turning off a device
when in landscape is triggering a resize. The resize logic in SDLActivity
triggers a resume.

This patch has resolved the issue on my device:

It prevents the dispatch of (improper) FOREGROUND events when locking
the device, but we get still events when the device is turned back on
and unlocked."
2017-03-31 23:43:53 -04:00
dmuratshin
01f66613db fixed SENSOR_LANDSCAPE and SENSOR_PORTRAIT mode false nativeResume bug 2017-01-12 10:58:35 -08:00
Sam Lantinga
ae8ca7c54d Fixed bug 3444 - Android-TV: no more handling of back button on remote
ny00

Unfortunately, simply checking the return codes of "onNativePadDown/Up" as previously done has its own issue:

If an SDL joystick is connected *and* opened, then a proper KeyEvent, say with keycode KEYCODE_BUTTON_1, should lead to an SDL joystick button event as expected.

If, however, the joystick was *not* opened, then "onNativePadDown/Up" will return a negative value, so before the commit from bug 3426, you could unexpectedly get a keyboard event. (In practice, you'll just get a log message, since KEYCODE_BUTTON_1 has no mapping to a proper SDL_ScanCode value, but it's still an problem).

What should still be done, though, is checking the key code itself. We do have the KeyEvent.isGamepadButton method, but according my test, it returns "true" exactly (and only) for the KEYCODE_BUTTON* values, and not for KEYCODE_DPAD* or any other key code.

Here is a possible solution:
- Do check the return codes of "onNativePadDown/Up" as previously done.
- In addition, in "Android_OnPadDown/Up" from src/joystick/android/SDL_sysjoystick.c, 0 should *always* be returned in case the key code can be translated to an SDL_joystick button; Even if no matching joystick can be found.
2016-10-17 22:09:22 -07:00