Skip to content

Commit

Permalink
Fixed bug 3843 - Android missing some code in SDLHapticHandler
Browse files Browse the repository at this point in the history
Sylvain

Some check for android SDK version are missing from https://hg.libsdl.org/SDL/rev/3d7a29a369a0
here's a patch
  • Loading branch information
slouken committed Sep 23, 2017
1 parent 099ae43 commit 14ed0d2
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions android-project/src/org/libsdl/app/SDLControllerManager.java
Expand Up @@ -300,45 +300,53 @@ public void run(int device_id, int length) {
public void pollHapticDevices() {

final int deviceId_VIBRATOR_SERVICE = 999999;
boolean hasVibrator = false;
boolean hasVibratorService = 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,
// so the first controller seen by SDL matches what the receiver
// considers to be the first controller

for(int i=deviceIds.length-1; i>-1; i--) {
SDLHaptic haptic = getHaptic(deviceIds[i]);
if (haptic == null) {
InputDevice device = InputDevice.getDevice(deviceIds[i]);
Vibrator vib = device.getVibrator();
if (vib.hasVibrator()) {
haptic = new SDLHaptic();
haptic.device_id = deviceIds[i];
haptic.name = device.getName();
haptic.vib = vib;
mHaptics.add(haptic);
SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
if (Build.VERSION.SDK_INT >= 16)
{
for (int i = deviceIds.length - 1; i > -1; i--) {
SDLHaptic haptic = getHaptic(deviceIds[i]);
if (haptic == null) {
InputDevice device = InputDevice.getDevice(deviceIds[i]);
Vibrator vib = device.getVibrator();
if (vib.hasVibrator()) {
haptic = new SDLHaptic();
haptic.device_id = deviceIds[i];
haptic.name = device.getName();
haptic.vib = vib;
mHaptics.add(haptic);
SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
}
}
}
}

/* Check VIBRATOR_SERVICE */
{
Vibrator vib = (Vibrator) SDL.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);
SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
}
}
Vibrator vib = (Vibrator) SDL.getContext().getSystemService(Context.VIBRATOR_SERVICE);
if (vib != null) {
if (Build.VERSION.SDK_INT >= 11) {
hasVibratorService = vib.hasVibrator();
} else {
hasVibratorService = true;
}

if (hasVibratorService) {
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);
SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
}
}
}

/* Check removed devices */
Expand All @@ -350,8 +358,8 @@ public void pollHapticDevices() {
if (device_id == deviceIds[j]) break;
}

if (device_id == deviceId_VIBRATOR_SERVICE && hasVibrator) {
// don't remove the vibrator if it is still present
if (device_id == deviceId_VIBRATOR_SERVICE && hasVibratorService) {
// don't remove the vibrator if it is still present
} else if (j == deviceIds.length) {
removedDevices.add(device_id);
}
Expand Down

0 comments on commit 14ed0d2

Please sign in to comment.