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

@ -1,5 +1,7 @@
package org.libsdl.app;
import java.util.Arrays;
import android.app.*;
import android.content.*;
import android.view.*;
@ -386,6 +388,24 @@ public class SDLActivity extends Activity {
mAudioTrack = null;
}
}
// Input
/**
* @return an array which may be empty but is never null.
*/
public static int[] inputGetInputDeviceIds(int sources) {
int[] ids = InputDevice.getDeviceIds();
int[] filtered = new int[ids.length];
int used = 0;
for (int i = 0; i < ids.length; ++i) {
InputDevice device = InputDevice.getDevice(ids[i]);
if ((device != null) && ((device.getSources() & sources) != 0)) {
filtered[used++] = device.getId();
}
}
return Arrays.copyOf(filtered, used);
}
}
/**