mirror of https://github.com/encounter/SDL.git
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
This commit is contained in:
parent
099ae43e81
commit
14ed0d24c8
|
@ -300,7 +300,7 @@ class SDLHapticHandler {
|
||||||
public void pollHapticDevices() {
|
public void pollHapticDevices() {
|
||||||
|
|
||||||
final int deviceId_VIBRATOR_SERVICE = 999999;
|
final int deviceId_VIBRATOR_SERVICE = 999999;
|
||||||
boolean hasVibrator = false;
|
boolean hasVibratorService = false;
|
||||||
|
|
||||||
int[] deviceIds = InputDevice.getDeviceIds();
|
int[] deviceIds = InputDevice.getDeviceIds();
|
||||||
// It helps processing the device ids in reverse order
|
// It helps processing the device ids in reverse order
|
||||||
|
@ -308,37 +308,45 @@ class SDLHapticHandler {
|
||||||
// so the first controller seen by SDL matches what the receiver
|
// so the first controller seen by SDL matches what the receiver
|
||||||
// considers to be the first controller
|
// considers to be the first controller
|
||||||
|
|
||||||
for(int i=deviceIds.length-1; i>-1; i--) {
|
if (Build.VERSION.SDK_INT >= 16)
|
||||||
SDLHaptic haptic = getHaptic(deviceIds[i]);
|
{
|
||||||
if (haptic == null) {
|
for (int i = deviceIds.length - 1; i > -1; i--) {
|
||||||
InputDevice device = InputDevice.getDevice(deviceIds[i]);
|
SDLHaptic haptic = getHaptic(deviceIds[i]);
|
||||||
Vibrator vib = device.getVibrator();
|
if (haptic == null) {
|
||||||
if (vib.hasVibrator()) {
|
InputDevice device = InputDevice.getDevice(deviceIds[i]);
|
||||||
haptic = new SDLHaptic();
|
Vibrator vib = device.getVibrator();
|
||||||
haptic.device_id = deviceIds[i];
|
if (vib.hasVibrator()) {
|
||||||
haptic.name = device.getName();
|
haptic = new SDLHaptic();
|
||||||
haptic.vib = vib;
|
haptic.device_id = deviceIds[i];
|
||||||
mHaptics.add(haptic);
|
haptic.name = device.getName();
|
||||||
SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
|
haptic.vib = vib;
|
||||||
|
mHaptics.add(haptic);
|
||||||
|
SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check VIBRATOR_SERVICE */
|
/* Check VIBRATOR_SERVICE */
|
||||||
{
|
Vibrator vib = (Vibrator) SDL.getContext().getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
Vibrator vib = (Vibrator) SDL.getContext().getSystemService(Context.VIBRATOR_SERVICE);
|
if (vib != null) {
|
||||||
if (vib != null && vib.hasVibrator()) {
|
if (Build.VERSION.SDK_INT >= 11) {
|
||||||
hasVibrator = true;
|
hasVibratorService = vib.hasVibrator();
|
||||||
SDLHaptic haptic = getHaptic(deviceId_VIBRATOR_SERVICE);
|
} else {
|
||||||
if (haptic == null) {
|
hasVibratorService = true;
|
||||||
haptic = new SDLHaptic();
|
}
|
||||||
haptic.device_id = deviceId_VIBRATOR_SERVICE;
|
|
||||||
haptic.name = "VIBRATOR_SERVICE";
|
if (hasVibratorService) {
|
||||||
haptic.vib = vib;
|
SDLHaptic haptic = getHaptic(deviceId_VIBRATOR_SERVICE);
|
||||||
mHaptics.add(haptic);
|
if (haptic == null) {
|
||||||
SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
|
haptic = new SDLHaptic();
|
||||||
}
|
haptic.device_id = deviceId_VIBRATOR_SERVICE;
|
||||||
}
|
haptic.name = "VIBRATOR_SERVICE";
|
||||||
|
haptic.vib = vib;
|
||||||
|
mHaptics.add(haptic);
|
||||||
|
SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check removed devices */
|
/* Check removed devices */
|
||||||
|
@ -350,8 +358,8 @@ class SDLHapticHandler {
|
||||||
if (device_id == deviceIds[j]) break;
|
if (device_id == deviceIds[j]) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device_id == deviceId_VIBRATOR_SERVICE && hasVibrator) {
|
if (device_id == deviceId_VIBRATOR_SERVICE && hasVibratorService) {
|
||||||
// don't remove the vibrator if it is still present
|
// don't remove the vibrator if it is still present
|
||||||
} else if (j == deviceIds.length) {
|
} else if (j == deviceIds.length) {
|
||||||
removedDevices.add(device_id);
|
removedDevices.add(device_id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue