Update Android SDK required to API level 16 Sylvain Some API 16 methods are used (InputDevice: getDescriptor(), getVibrator()), so we need to compile at least with SDK API 16. Hence default.properties and project.properties have been modified to use android-16. There are also some modification to SDLActivity.java not to use getVibrator() if we run under API 16. And not to check to presence of hasVibrator() if we are under API 11. -some hard-coded constant can be expandend. - rename a local variable (hasVibrator to hasVibratorService)
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
diff --git a/android-project/default.properties b/android-project/default.properties
index 0cdab95..0a69b77 100644
--- a/android-project/default.properties
+++ b/android-project/default.properties
@@ -8,4 +8,4 @@
# project structure.
# Project target.
-target=android-12
+target=android-16
diff --git a/android-project/project.properties b/android-project/project.properties
index 0f507e5..9b84a6b 100644
--- a/android-project/project.properties
+++ b/android-project/project.properties
@@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
-target=android-12
+target=android-16
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index fdddad3..d3da10e 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -355,8 +355,8 @@ public class SDLActivity extends Activity {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ||
keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
keyCode == KeyEvent.KEYCODE_CAMERA ||
- keyCode == 168 || /* API 11: KeyEvent.KEYCODE_ZOOM_IN */
- keyCode == 169 /* API 11: KeyEvent.KEYCODE_ZOOM_OUT */
+ keyCode == KeyEvent.KEYCODE_ZOOM_IN || /* API 11 */
+ keyCode == KeyEvent.KEYCODE_ZOOM_OUT /* API 11 */
) {
return false;
}
@@ -1166,7 +1166,7 @@ public class SDLActivity extends Activity {
mapping.put(KeyEvent.KEYCODE_ENTER, button);
}
if ((buttonFlags[i] & 0x00000002) != 0) {
- mapping.put(111, button); /* API 11: KeyEvent.KEYCODE_ESCAPE */
+ mapping.put(KeyEvent.KEYCODE_ESCAPE, button); /* API 11 */
}
}
button.setText(buttonTexts[i]);
@@ -1688,7 +1688,7 @@ class DummyEdit extends View implements View.OnKeyListener {
outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
- | 33554432 /* API 11: EditorInfo.IME_FLAG_NO_FULLSCREEN */;
+ | EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */;
return ic;
}
@@ -1994,9 +1994,9 @@ class SDLHapticHandler {
}
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
@@ -2004,37 +2004,45 @@ class SDLHapticHandler {
// 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);
- SDLActivity.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);
+ SDLActivity.nativeAddHaptic(haptic.device_id, haptic.name);
+ }
}
}
}
/* Check VIBRATOR_SERVICE */
- {
- Vibrator vib = (Vibrator) SDLActivity.mSingleton.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);
- SDLActivity.nativeAddHaptic(haptic.device_id, haptic.name);
- }
- }
+ Vibrator vib = (Vibrator) SDLActivity.mSingleton.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);
+ SDLActivity.nativeAddHaptic(haptic.device_id, haptic.name);
+ }
+ }
}
/* Check removed devices */
@@ -2046,8 +2054,8 @@ class SDLHapticHandler {
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);
}
diff --git a/docs/README-android.md b/docs/README-android.md
index a68a18b..747bf72 100644
--- a/docs/README-android.md
+++ b/docs/README-android.md
@@ -10,14 +10,14 @@ The rest of this README covers the old style build process.
Requirements
================================================================================
-Android SDK (version 12 or later)
+Android SDK (version 16 or later)
https://developer.android.com/sdk/index.html
Android NDK r7 or later
https://developer.android.com/tools/sdk/ndk/index.html
Minimum API level supported by SDL: 10 (Android 2.3.3)
-Joystick support is available for API level >=12 devices.
+Joystick support is available for API level >= 12 devices.
================================================================================
How the port works