Android: better readibility for pollHapticDevices()

This commit is contained in:
Sylvain Becker 2020-10-07 14:55:23 +02:00
parent 20c070d869
commit bffbc7e316

View File

@ -509,37 +509,41 @@ class SDLHapticHandler {
} }
/* Check removed devices */ /* Check removed devices */
ArrayList<Integer> removedDevices = new ArrayList<Integer>(); ArrayList<Integer> removedDevices = null;
for(int i=0; i < mHaptics.size(); i++) { for (SDLHaptic haptic : mHaptics) {
int device_id = mHaptics.get(i).device_id; int device_id = haptic.device_id;
int j; int i;
for (j=0; j < deviceIds.length; j++) { for (i = 0; i < deviceIds.length; i++) {
if (device_id == deviceIds[j]) break; if (device_id == deviceIds[i]) break;
} }
if (device_id == deviceId_VIBRATOR_SERVICE && hasVibratorService) { 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 (i == deviceIds.length) {
if (removedDevices == null) {
removedDevices = new ArrayList<Integer>();
}
removedDevices.add(device_id); removedDevices.add(device_id);
} }
} }
for(int i=0; i < removedDevices.size(); i++) { if (removedDevices != null) {
int device_id = removedDevices.get(i); for (int device_id : removedDevices) {
SDLControllerManager.nativeRemoveHaptic(device_id); SDLControllerManager.nativeRemoveHaptic(device_id);
for (int j=0; j < mHaptics.size(); j++) { for (int i = 0; i < mHaptics.size(); i++) {
if (mHaptics.get(j).device_id == device_id) { if (mHaptics.get(i).device_id == device_id) {
mHaptics.remove(j); mHaptics.remove(i);
break; break;
}
} }
} }
} }
} }
protected SDLHaptic getHaptic(int device_id) { protected SDLHaptic getHaptic(int device_id) {
for(int i=0; i < mHaptics.size(); i++) { for (SDLHaptic haptic : mHaptics) {
if (mHaptics.get(i).device_id == device_id) { if (haptic.device_id == device_id) {
return mHaptics.get(i); return haptic;
} }
} }
return null; return null;