Fixed bug 3843 - Android missing some code in SDLHapticHandler
authorSam Lantinga <slouken@libsdl.org>
Sat, 23 Sep 2017 12:37:09 -0700
changeset 115425c39c05ced36
parent 11541 433786fcf04a
child 11543 53b03749a7ff
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/04dd43a2c83a
here's a patch
android-project/src/org/libsdl/app/SDLControllerManager.java
     1.1 --- a/android-project/src/org/libsdl/app/SDLControllerManager.java	Fri Sep 22 22:28:21 2017 -0400
     1.2 +++ b/android-project/src/org/libsdl/app/SDLControllerManager.java	Sat Sep 23 12:37:09 2017 -0700
     1.3 @@ -300,7 +300,7 @@
     1.4      public void pollHapticDevices() {
     1.5          
     1.6          final int deviceId_VIBRATOR_SERVICE = 999999;
     1.7 -        boolean hasVibrator = false;
     1.8 +        boolean hasVibratorService = false;
     1.9  
    1.10          int[] deviceIds = InputDevice.getDeviceIds();
    1.11          // It helps processing the device ids in reverse order
    1.12 @@ -308,37 +308,45 @@
    1.13          // so the first controller seen by SDL matches what the receiver
    1.14          // considers to be the first controller
    1.15  
    1.16 -        for(int i=deviceIds.length-1; i>-1; i--) {
    1.17 -            SDLHaptic haptic = getHaptic(deviceIds[i]);
    1.18 -            if (haptic == null) {
    1.19 -                InputDevice device = InputDevice.getDevice(deviceIds[i]);
    1.20 -                Vibrator vib = device.getVibrator();
    1.21 -                if (vib.hasVibrator()) {
    1.22 -                    haptic = new SDLHaptic();
    1.23 -                    haptic.device_id = deviceIds[i];
    1.24 -                    haptic.name = device.getName();
    1.25 -                    haptic.vib = vib;
    1.26 -                    mHaptics.add(haptic);
    1.27 -                    SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
    1.28 +        if (Build.VERSION.SDK_INT >= 16)
    1.29 +        {
    1.30 +            for (int i = deviceIds.length - 1; i > -1; i--) {
    1.31 +                SDLHaptic haptic = getHaptic(deviceIds[i]);
    1.32 +                if (haptic == null) {
    1.33 +                    InputDevice device = InputDevice.getDevice(deviceIds[i]);
    1.34 +                    Vibrator vib = device.getVibrator();
    1.35 +                    if (vib.hasVibrator()) {
    1.36 +                        haptic = new SDLHaptic();
    1.37 +                        haptic.device_id = deviceIds[i];
    1.38 +                        haptic.name = device.getName();
    1.39 +                        haptic.vib = vib;
    1.40 +                        mHaptics.add(haptic);
    1.41 +                        SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
    1.42 +                    }
    1.43                  }
    1.44              }
    1.45          }
    1.46  
    1.47          /* Check VIBRATOR_SERVICE */
    1.48 -        {
    1.49 -           Vibrator vib = (Vibrator) SDL.getContext().getSystemService(Context.VIBRATOR_SERVICE);
    1.50 -           if (vib != null && vib.hasVibrator()) {
    1.51 -              hasVibrator = true;
    1.52 -              SDLHaptic haptic = getHaptic(deviceId_VIBRATOR_SERVICE);
    1.53 -              if (haptic == null) {
    1.54 -                 haptic = new SDLHaptic();
    1.55 -                 haptic.device_id = deviceId_VIBRATOR_SERVICE;
    1.56 -                 haptic.name = "VIBRATOR_SERVICE";
    1.57 -                 haptic.vib = vib; 
    1.58 -                 mHaptics.add(haptic);
    1.59 -                 SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
    1.60 -              }
    1.61 -           }
    1.62 +        Vibrator vib = (Vibrator) SDL.getContext().getSystemService(Context.VIBRATOR_SERVICE);
    1.63 +        if (vib != null) {
    1.64 +            if (Build.VERSION.SDK_INT >= 11) {
    1.65 +                hasVibratorService = vib.hasVibrator();
    1.66 +            } else {
    1.67 +                hasVibratorService = true;
    1.68 +            }
    1.69 +
    1.70 +            if (hasVibratorService) {
    1.71 +                SDLHaptic haptic = getHaptic(deviceId_VIBRATOR_SERVICE);
    1.72 +                if (haptic == null) {
    1.73 +                    haptic = new SDLHaptic();
    1.74 +                    haptic.device_id = deviceId_VIBRATOR_SERVICE;
    1.75 +                    haptic.name = "VIBRATOR_SERVICE";
    1.76 +                    haptic.vib = vib; 
    1.77 +                    mHaptics.add(haptic);
    1.78 +                    SDLControllerManager.nativeAddHaptic(haptic.device_id, haptic.name);
    1.79 +                }
    1.80 +            }
    1.81          }
    1.82  
    1.83          /* Check removed devices */
    1.84 @@ -350,8 +358,8 @@
    1.85                  if (device_id == deviceIds[j]) break;
    1.86              }
    1.87  
    1.88 -            if (device_id == deviceId_VIBRATOR_SERVICE && hasVibrator) {
    1.89 -               // don't remove the vibrator if it is still present
    1.90 +            if (device_id == deviceId_VIBRATOR_SERVICE && hasVibratorService) {
    1.91 +                // don't remove the vibrator if it is still present
    1.92              } else if (j == deviceIds.length) {
    1.93                  removedDevices.add(device_id);
    1.94              }