Android: better readibility for pollHapticDevices()
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
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
index 12eebc6..05674d1 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
@@ -509,37 +509,41 @@ class SDLHapticHandler {
}
/* Check removed devices */
- ArrayList<Integer> removedDevices = new ArrayList<Integer>();
- for(int i=0; i < mHaptics.size(); i++) {
- int device_id = mHaptics.get(i).device_id;
- int j;
- for (j=0; j < deviceIds.length; j++) {
- if (device_id == deviceIds[j]) break;
+ ArrayList<Integer> removedDevices = null;
+ for (SDLHaptic haptic : mHaptics) {
+ int device_id = haptic.device_id;
+ int i;
+ for (i = 0; i < deviceIds.length; i++) {
+ if (device_id == deviceIds[i]) break;
}
if (device_id == deviceId_VIBRATOR_SERVICE && hasVibratorService) {
// 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);
}
}
- for(int i=0; i < removedDevices.size(); i++) {
- int device_id = removedDevices.get(i);
- SDLControllerManager.nativeRemoveHaptic(device_id);
- for (int j=0; j < mHaptics.size(); j++) {
- if (mHaptics.get(j).device_id == device_id) {
- mHaptics.remove(j);
- break;
+ if (removedDevices != null) {
+ for (int device_id : removedDevices) {
+ SDLControllerManager.nativeRemoveHaptic(device_id);
+ for (int i = 0; i < mHaptics.size(); i++) {
+ if (mHaptics.get(i).device_id == device_id) {
+ mHaptics.remove(i);
+ break;
+ }
}
}
}
}
protected SDLHaptic getHaptic(int device_id) {
- for(int i=0; i < mHaptics.size(); i++) {
- if (mHaptics.get(i).device_id == device_id) {
- return mHaptics.get(i);
+ for (SDLHaptic haptic : mHaptics) {
+ if (haptic.device_id == device_id) {
+ return haptic;
}
}
return null;