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 ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index d500b6d..711b7f3 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -593,23 +593,6 @@ public class SDLActivity extends Activity {
return false;
}
-
-
- /**
- * This method is called by SDL using JNI.
- */
- public static int openURL(String url)
- {
- try {
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(Uri.parse(url));
- mSingleton.startActivity(i);
- } catch (Exception ex) {
- return -1;
- }
- return 0;
- }
-
/**
* This method is called by SDL using JNI.
*/
@@ -892,6 +875,24 @@ public class SDLActivity extends Activity {
}
}
+ /**
+ * This method is called by SDL using JNI.
+ */
+ public static void pollHapticDevices() {
+ if (SDLActivity.mSDLThread != null) {
+ mHapticHandler.pollHapticDevices();
+ }
+ }
+
+ /**
+ * This method is called by SDL using JNI.
+ */
+ public static void hapticRun(int device_id, int length) {
+ if (SDLActivity.mSDLThread != null) {
+ mHapticHandler.run(device_id, length);
+ }
+ }
+
// Check if a given device is considered a possible SDL joystick
public static boolean isDeviceSDLJoystick(int deviceId) {
InputDevice device = InputDevice.getDevice(deviceId);
@@ -1808,18 +1809,6 @@ class SDLJoystickHandler_API12 extends SDLJoystickHandler {
return null;
}
- public static void pollHapticDevices() {
- if (SDLActivity.mSDLThread != null) {
- mHapticHandler.pollHapticDevices();
- }
- }
-
- public static void hapticRun(int device_id, int length) {
- if (SDLActivity.mSDLThread != null) {
- mHapticHandler.run(device_id, length);
- }
- }
-
@Override
public boolean handleMotionEvent(MotionEvent event) {
if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
@@ -1918,6 +1907,10 @@ class SDLHapticHandler {
}
public void pollHapticDevices() {
+
+ final int deviceId_VIBRATOR_SERVICE = 999999;
+ boolean hasVibrator = false;
+
int[] deviceIds = InputDevice.getDeviceIds();
// It helps processing the device ids in reverse order
// For example, in the case of the XBox 360 wireless dongle,
@@ -1940,6 +1933,23 @@ class SDLHapticHandler {
}
}
+ /* Check VIBRATOR_SERVICE */
+ {
+ Vibrator vib = (Vibrator) SDLActivity.mSingleton.getContext().getSystemService(Context.VIBRATOR_SERVICE);
+ if (vib != null && vib.hasVibrator()) {
+ hasVibrator = true;
+ SDLHaptic haptic = getHaptic(deviceId_VIBRATOR_SERVICE);
+ if (haptic == null) {
+ haptic = new SDLHaptic();
+ haptic.device_id = deviceId_VIBRATOR_SERVICE;
+ haptic.name = "VIBRATOR_SERVICE";
+ haptic.vib = vib;
+ mHaptics.add(haptic);
+ SDLActivity.nativeAddHaptic(haptic.device_id, haptic.name);
+ }
+ }
+ }
+
/* Check removed devices */
ArrayList<Integer> removedDevices = new ArrayList<Integer>();
for(int i=0; i < mHaptics.size(); i++) {
@@ -1948,7 +1958,10 @@ class SDLHapticHandler {
for (j=0; j < deviceIds.length; j++) {
if (device_id == deviceIds[j]) break;
}
- if (j == deviceIds.length) {
+
+ if (device_id == deviceId_VIBRATOR_SERVICE && hasVibrator) {
+ // don't remove the vibrator if it is still present
+ } else if (j == deviceIds.length) {
removedDevices.add(device_id);
}
}