Commit graph

339 commits

Author SHA1 Message Date
Philipp Wiesemann
20dbab5d8d Added missing @Override annotations in Java file. 2013-11-10 17:35:07 +01:00
Philipp Wiesemann
aa059d0a18 Changed motion listener implementation not to inherit from Activity class. 2013-11-10 15:04:58 +01:00
Philipp Wiesemann
d01fdd5e48 Moved two function calls so they are only called if needed.
If the MotionEvent is not from joystick the return values are not needed.
2013-11-10 14:58:48 +01:00
Gabriel Jacobo
dd726d96bf [Android] Fixes Bug 2041 - can't get SDL_QUIT event...
Thanks to Denis Bernard!

Also, changed the Android manifest so the app doesn't quit with orientation
changes, and made testgles.c exit properly on Android.
2013-11-06 11:23:24 -03:00
Gabriel Jacobo
7075ece4a5 Adds Joystick support for Android
This bumps the build SDK level to 12 (up from 10). Runtime requirements remain
the same (at API level < 12 joystick support is disabled).

Also enables building SDL for armv7 and x86.
2013-11-05 20:07:39 -03:00
Sam Lantinga
e8d2a8b3b8 Fixed bug 2156 - Android: Accelerometer values fed to joystick driver are inverted for the X axis and wrong for Z
Denis Bernard

Background information: http://developer.android.com/reference/android/hardware/SensorEvent.html#values

Steps to reproduce: compile testjoystick.c as an android app (change screen size according to your device). While running the app, also run:

adb logcat -c; adb logcat -s 'SDL:*' 'SDL/APP:*'

When tilting the device left/right, the joystick moves in the opposite direction of what one would expect. Or at least, the behaviour is not consistent with the Y axis.

Also when the device sits on a table (obviously not moving), the Z axis value oscillates between -32000 and +32000 (by overflow):

I/SDL/APP ( 1994): Joystick 0 axis 2 value: 32511
I/SDL/APP ( 1994): Joystick 0 axis 2 value: 32575
I/SDL/APP ( 1994): Joystick 0 axis 2 value: 32383
I/SDL/APP ( 1994): Joystick 0 axis 2 value: -32386
I/SDL/APP ( 1994): Joystick 0 axis 2 value: -32450
I/SDL/APP ( 1994): Joystick 0 axis 2 value: -32578

This is caused by the accelerometer yielding a constant value around 9.81 for Z and feeding something like 0.9 to 1.1 to the joystick driver, resulting in the overflow.

Proposed fix in SDLActivity.java (swap X and subtract G from Z reading)
2013-10-20 23:52:02 -07:00
Sam Lantinga
84d3120257 Fixed bug 2155 - automatically remap accelerometer coordinates according to screen orientation on Android
Denis Bernard

Background information: http://android-developers.blogspot.fr/2010/09/one-screen-turn-deserves-another.html and http://developer.android.com/reference/android/hardware/SensorEvent.html

Right now, the Android accelerometer event handler feeds raw accelerometer data  to the SDL Joystick driver. The result is that for landscape-only applications, the axis need to be swapped if running on a portrait device (like a phone), and vice-versa: running a portrait only app on a landscape device like a tablet.

The purpose of this patch is to perform coordinate remapping of the accelerometer data before feeding it to the SDL joystick driver so that the X axis of the joystick is always aligned with the X axis of the display, same for the Y axis.

This has been tested on applications that support screen orientation changes as well as applications with fixed screen orientations, both on phones and tablets.
2013-10-17 23:44:30 -07:00
Sam Lantinga
e7dba74084 Fixed bug 2146 - Enable static linking of libSDL on Android
Denis Bernard

This patch to Android.mk adds support for static linking of libSDL for Android applications. A patched readme with static build instructions is also provided.

It does not break existing build environments setup according to the README-android.txt since the static library version will not be built in not required.

The static build uses the Android NDK module system (see docs/IMPORT-MODULE.html in the NDK folder and step 5 in the instructions below).

Instructions:
1. Copy the android-project directory wherever you want to keep your projects
   and rename it to the name of your project.
2. Create a symlink to SDL/src/main/android/SDL_android_main.c as
   <project>/jni/src/SDL_android_main.c
3. Rename <project>/jni/src/Android_static.mk to <project>/jni/src/Android.mk
   (overwrite the existing one)
4. Edit <project>/jni/src/Android.mk to include your source files
5. create and export an environment variable named NDK_MODULE_PATH that points
   to the parent directory of this SDL directory. e.g.:

   export NDK_MODULE_PATH="$PWD"/..

6. Edit <project>/src/org/libsdl/app/SDLActivity.java and remove the call to
   System.loadLibrary("SDL2") line 42.
7. Run 'ndk-build' (a script provided by the NDK). This compiles the C source

Although this requires an environment variable to be setup, it can be added once and for all to the main Android.mk of the project.
2013-10-10 21:51:39 -07:00
Philipp Wiesemann
20b394d072 Added detection of touch devices before first touch events happen on Android.
On Android available touch devices are now added with video initialization (like
the keyboard). This fixes SDL_GetNumTouchDevices() returning 0 before any touch
events happened although there is a touch screen available. The adding of touch
devices after a touch event was received is still active to allow connecting
devices later (if this is possible) and to provide a fallback if the new init
did not work somehow. For the implementation JNI was used and API level 9 is
required. There seems to be nothing in the Android NDK's input header (input.h)
to implement everything on C side without communication with Java side.
2013-10-05 17:08:19 +02:00
Gabriel Jacobo
cd9a7c392c Fixes #2036 and #2038, bypass camera zoom and shutter keypresses on Android. 2013-08-22 10:22:22 -03:00
Gabriel Jacobo
ef4a588d99 Fixes bug #2037, common EGL code for Android and X11 2013-08-19 16:29:46 -03:00
Gabriel Jacobo
a3982939c5 Fixes #2022, do not resume on Android when surfaceChanged
If the app is in landscape mode and the user presses the power button, a pause
is followed immediately by a surfaceChanged event because the lock screen
is shown in portrait mode. This triggers a "false" resume.
So, we just pause and resume following the onWindowFocusChanged events.

Also, wait for SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND before
blocking the event pump.
2013-08-12 11:13:50 -03:00
Gabriel Jacobo
610264fb0b Start Android Audio Thread after audio buffer and AudioTrack are ready.
Also, it starts the Audio Thread from the native side, putting the code in line
with other backends.
2013-08-08 21:25:09 -03:00
Gabriel Jacobo
29c4f05ed5 Add some protection against double init of the Android audio backend 2013-08-08 09:47:42 -03:00
Philipp Wiesemann
2ec969cb57 Fixed volume keys not being handled by Android if screen keyboard is visible.
See bug #1569.
2013-08-04 23:28:34 +02:00
Gabriel Jacobo
2a6b235190 Fixes bug #1889, allows for GL Context deletion/recreation on Android
Thanks ny00!
2013-08-03 12:54:39 -03:00
Gabriel Jacobo
ab545a05b9 Temporary fix for bug #1639 SDL does not message back closing of screen keyboard
See FIXME notes on patch for details.
2013-08-02 12:38:39 -03:00
Sam Lantinga
9943bac533 Fixed bug 1569 - Android volume keys not honoured inside SDL
Joseba García Echebarria

The current version of SDL HG in Android doesn't do anything when volume keys are pressed.
The change makes SDL ignore volume keys so that they're handled by the OS and the sound volume can be changed within an app.
2013-07-31 21:08:22 -07:00
Gabriel Jacobo
51f5bfbc4b Set mAudioTrack to null when AudioTrack initialization fails
Prevents potential problems when stopping the app.
2013-07-31 16:25:50 -03:00
Gabriel Jacobo
512f5dfc21 Fix for bug 2001, verify that the AudioTrack is properly initialized
...and fail to initialize the audio backend if it's not!
2013-07-31 10:04:59 -03:00
Gabriel Jacobo
7c9692c8c5 Consider the case where an attribute is set to EGL_DONT_CARE in eglChooseConfig
SDL doesn't currently use EGL_DONT_CARE, but it doesn' hurt to future proof.
2013-07-26 12:37:36 -03:00
Gabriel Jacobo
c73a37ac6f [Android] Bug 1827, select the best matching config provided by eglChooseConfig 2013-07-26 12:22:40 -03:00
Eric Wing
a99edf3519 Android: Removed all unnecessary dependencies on C++.
C++ is a bit of a minefield on Android. Much functionality still doesn't work, and Android can't decide on which C++ standard library to use, so it provides 3 different ones, all of which are incompatible with each other. (It looks like clang is coming too which will add a new compiler and a 4th standard library.)

As middleware, SDL might be distributed as a binary and intermixed with other projects already using C++. If C++ is intermixed in a bad way, bad things will happen. Removing dependencies on C++ will avoid this problem and downstream users won't have to worry/care.

--HG--
rename : src/core/android/SDL_android.cpp => src/core/android/SDL_android.c
rename : src/main/android/SDL_android_main.cpp => src/main/android/SDL_android_main.c
2013-07-22 02:51:45 -07:00
Gabriel Jacobo
b2d7f92773 Adds Input Focus handling on Android to improve pausing/resuming behavior
Ref: http://android-developers.blogspot.com/2011/11/making-android-games-that-play-nice.html
2013-07-09 10:25:16 -03:00
Gabriel Jacobo
4dbe83c72a Fixes Bug 1896 - Android app is running while the screen is locked
Original patch by ny00@outlook.com
2013-07-06 15:22:49 -03:00
Philipp Wiesemann
ad82c94c55 Updated names of README files in source comments. 2013-06-09 11:58:31 +02:00
Philipp Wiesemann
f54e7cdaa8 Fixed Android Lint warning in AndroidManifest.xml.
If targetSdkVersion not set it becomes same as minSdkVersion and causes warning.
2013-06-09 11:51:59 +02:00
Philipp Wiesemann
8fc42c451c Added deactivated loading of SDL2_net to Java file. 2013-05-30 12:23:36 +02:00
Sam Lantinga
2ac8624930 Added mobile application events, with implementations for iOS and Android 2013-05-18 12:48:50 -07:00
Philipp Wiesemann
7615624d82 Corrected comment in Java file. 2013-05-18 14:04:37 +02:00
Philipp Wiesemann
5126239a00 Changed import statements in Java file. 2013-05-18 14:03:45 +02:00
Sam Lantinga
e8051fbb53 There's no need to keep these private. If you extend SDLActivity, you should know what you're doing. 2013-05-15 23:18:29 -07:00
Philipp Wiesemann
8d53137515 Fixed Android Lint warning in AndroidManifest.xml. 2013-05-10 21:19:40 +02:00
Philipp Wiesemann
4f70701db1 Removed not needed block from Java file. 2013-05-05 16:01:19 +02:00
Philipp Wiesemann
4266102f1d Changed signatures of methods in Java file to return boolean, adapted C++ file.
This way more checking for errors is possible which is currently not done here.
2013-05-05 15:54:56 +02:00
Philipp Wiesemann
89805a7cae Changed signature of method recently added in Java file. 2013-05-05 15:50:21 +02:00
Philipp Wiesemann
ffd1362c16 Added a method in Java file which may be overridden for custom messages. 2013-05-05 12:53:57 +02:00
Philipp Wiesemann
3fd91d1319 Fixed possible leak and its Android Lint warning in Java file. 2013-05-05 12:50:34 +02:00
Philipp Wiesemann
103fc07702 Removed not needed casts from Java file. 2013-04-27 17:23:20 +02:00
Philipp Wiesemann
9e39871ec5 Removed not needed import statements from Java file. 2013-04-27 17:17:37 +02:00
Philipp Wiesemann
628e39e91c Removed dead store from Java file because value never used. 2013-04-27 17:15:40 +02:00
Philipp Wiesemann
65291c1e99 Renamed inner class in Java file to avoid confusion with an unrelated class. 2013-04-27 17:10:14 +02:00
Philipp Wiesemann
423489e19d Changed Java source file to use constant from API instead of just a String. 2013-04-27 14:26:15 +02:00
Philipp Wiesemann
bdd9df5fd9 Added missing @Override annotations in Java source file to reduce warnings. 2013-04-27 14:13:30 +02:00
Philipp Wiesemann
1e5aaadf49 Corrected a comment in Java source file. 2013-04-27 13:33:05 +02:00
Gabriel Jacobo
ba5fc3539a Fix for bug #1776 by Jonathan Dearborn 2013-04-19 14:40:39 -03:00
Sam Lantinga
25cefc7ef6 Fixed bug 1779 - SDL's Android project template has old default icons from Android.
Philipp Wiesemann

SDL's Android project template has old default icons from Android while iOS project template has custom icons with SDL's logo.

There is a Wizard in the Android Developer Tools to create "Android Icon Sets". As an example I created icons from the iOS loading screen and attached them in a ZIP archive. They are named "ic_launcher.png" instead of "icon.png" because that is the new name used in Android projects. To use them the AndroidManifest.xml needs to be changed to have "@drawable/ic_launcher" instead of "@drawable/icon". I do not know why there was no icon created for ldpi. Maybe it is deprecated.
2013-04-02 07:55:25 -07:00
Gabriel Jacobo
6fe4eabf3e Backed out changeset: 9cef1005df5f 2013-04-01 13:20:22 -03:00
Sam Lantinga
3c610adc98 Fixed bug 1700 - Joysticks not supported in Android 2013-03-19 23:03:57 -07:00
Gabriel Jacobo
24df19a3d3 Fixes AndroidManifest comment, Android API level 10 = Android 2.3.3 2013-03-04 10:39:21 -03:00