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.
This commit is contained in:
Philipp Wiesemann 2013-10-05 17:08:19 +02:00
parent 31db3ac3c8
commit 20b394d072
6 changed files with 67 additions and 0 deletions

View file

@ -31,6 +31,7 @@
#include "SDL_androidtouch.h"
#include "../../core/android/SDL_android.h"
#define ACTION_DOWN 0
#define ACTION_UP 1
@ -53,6 +54,19 @@ static void Android_GetWindowCoordinates(float x, float y,
*window_y = (int)(y * window_h);
}
void Android_InitTouch(void)
{
int i;
int* ids;
int number = Android_JNI_GetTouchDeviceIds(&ids);
if (0 < number) {
for (i = 0; i < number; ++i) {
SDL_AddTouch((SDL_TouchID) ids[i], ""); /* no error handling */
}
SDL_free(ids);
}
}
void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p)
{
SDL_TouchID touchDeviceId = 0;

View file

@ -22,6 +22,7 @@
#include "SDL_androidvideo.h"
extern void Android_InitTouch(void);
extern void Android_OnTouch( int touch_device_id_in, int pointer_finger_id_in, int action, float x, float y, float p);
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -36,6 +36,7 @@
#include "SDL_androidclipboard.h"
#include "SDL_androidevents.h"
#include "SDL_androidkeyboard.h"
#include "SDL_androidtouch.h"
#include "SDL_androidwindow.h"
#define ANDROID_VID_DRIVER_NAME "Android"
@ -165,6 +166,8 @@ Android_VideoInit(_THIS)
Android_InitKeyboard();
Android_InitTouch();
/* We're done! */
return 0;
}