Browse Source

Upgrade source-download SDL to 2.28.5 (#6838)

pull/6839/head
Oleksandr Kalko 2 years ago committed by GitHub
parent
commit
ef69727586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .github/workflows/Android.yml
  2. 4
      .github/workflows/iOS.yml
  3. 4
      3rdParty/SDL2/CMakeLists.txt
  4. 4
      android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java
  5. 8
      android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java
  6. 6
      android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java
  7. 84
      android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
  8. 34
      android-project/app/src/main/java/org/libsdl/app/SDLAudioManager.java
  9. 8
      android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
  10. 4
      android-project/app/src/main/java/org/libsdl/app/SDLSurface.java

4
.github/workflows/Android.yml

@ -40,8 +40,8 @@ jobs:
uses: actions/cache@v3 uses: actions/cache@v3
with: with:
path: android-project/app/.cxx path: android-project/app/.cxx
key: ${{ github.workflow }}-v3-${{ github.sha }} key: ${{ github.workflow }}-v4-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v3- restore-keys: ${{ github.workflow }}-v4-
- name: Build - name: Build
working-directory: ${{github.workspace}} working-directory: ${{github.workspace}}

4
.github/workflows/iOS.yml

@ -39,8 +39,8 @@ jobs:
uses: actions/cache@v3 uses: actions/cache@v3
with: with:
path: build path: build
key: ${{ github.workflow }}-v2-${{ github.sha }} key: ${{ github.workflow }}-v3-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v2- restore-keys: ${{ github.workflow }}-v3-
- name: Configure CMake - name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable # Use a bash shell so we can use the same syntax for environment variable

4
3rdParty/SDL2/CMakeLists.txt vendored

@ -15,7 +15,7 @@ set(SDL_TEST_ENABLED_BY_DEFAULT OFF)
include(functions/FetchContent_MakeAvailableExcludeFromAll) include(functions/FetchContent_MakeAvailableExcludeFromAll)
include(FetchContent) include(FetchContent)
FetchContent_Declare(SDL2 FetchContent_Declare(SDL2
URL https://github.com/libsdl-org/SDL/archive/8b39eb9b1ff885978816dd9663277608187e8676.tar.gz URL https://github.com/libsdl-org/SDL/releases/download/release-2.28.5/SDL2-2.28.5.tar.gz
URL_HASH MD5=3cf9bf5f20375aa5dcc529193c809967 URL_HASH SHA256=332cb37d0be20cb9541739c61f79bae5a477427d79ae85e352089afdaf6666e4
) )
FetchContent_MakeAvailableExcludeFromAll(SDL2) FetchContent_MakeAvailableExcludeFromAll(SDL2)

4
android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java

@ -186,7 +186,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
// Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead // Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead
// of TRANSPORT_LE. Let's force ourselves to connect low energy. // of TRANSPORT_LE. Let's force ourselves to connect low energy.
private BluetoothGatt connectGatt(boolean managed) { private BluetoothGatt connectGatt(boolean managed) {
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23 /* Android 6.0 (M) */) {
try { try {
return mDevice.connectGatt(mManager.getContext(), managed, this, TRANSPORT_LE); return mDevice.connectGatt(mManager.getContext(), managed, this, TRANSPORT_LE);
} catch (Exception e) { } catch (Exception e) {
@ -429,7 +429,7 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
} }
}); });
} }
} }
else if (newState == 0) { else if (newState == 0) {
mIsConnected = false; mIsConnected = false;
} }

8
android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java

@ -252,6 +252,7 @@ public class HIDDeviceManager {
0x24c6, // PowerA 0x24c6, // PowerA
0x2c22, // Qanba 0x2c22, // Qanba
0x2dc8, // 8BitDo 0x2dc8, // 8BitDo
0x9886, // ASTRO Gaming
}; };
if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC && if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC &&
@ -272,6 +273,7 @@ public class HIDDeviceManager {
final int XB1_IFACE_SUBCLASS = 71; final int XB1_IFACE_SUBCLASS = 71;
final int XB1_IFACE_PROTOCOL = 208; final int XB1_IFACE_PROTOCOL = 208;
final int[] SUPPORTED_VENDORS = { final int[] SUPPORTED_VENDORS = {
0x03f0, // HP
0x044f, // Thrustmaster 0x044f, // Thrustmaster
0x045e, // Microsoft 0x045e, // Microsoft
0x0738, // Mad Catz 0x0738, // Mad Catz
@ -356,13 +358,13 @@ public class HIDDeviceManager {
private void initializeBluetooth() { private void initializeBluetooth() {
Log.d(TAG, "Initializing Bluetooth"); Log.d(TAG, "Initializing Bluetooth");
if (Build.VERSION.SDK_INT <= 30 && if (Build.VERSION.SDK_INT <= 30 /* Android 11.0 (R) */ &&
mContext.getPackageManager().checkPermission(android.Manifest.permission.BLUETOOTH, mContext.getPackageName()) != PackageManager.PERMISSION_GRANTED) { mContext.getPackageManager().checkPermission(android.Manifest.permission.BLUETOOTH, mContext.getPackageName()) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Couldn't initialize Bluetooth, missing android.permission.BLUETOOTH"); Log.d(TAG, "Couldn't initialize Bluetooth, missing android.permission.BLUETOOTH");
return; return;
} }
if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) || (Build.VERSION.SDK_INT < 18)) { if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) || (Build.VERSION.SDK_INT < 18 /* Android 4.3 (JELLY_BEAN_MR2) */)) {
Log.d(TAG, "Couldn't initialize Bluetooth, this version of Android does not support Bluetooth LE"); Log.d(TAG, "Couldn't initialize Bluetooth, this version of Android does not support Bluetooth LE");
return; return;
} }
@ -576,7 +578,7 @@ public class HIDDeviceManager {
try { try {
final int FLAG_MUTABLE = 0x02000000; // PendingIntent.FLAG_MUTABLE, but don't require SDK 31 final int FLAG_MUTABLE = 0x02000000; // PendingIntent.FLAG_MUTABLE, but don't require SDK 31
int flags; int flags;
if (Build.VERSION.SDK_INT >= 31) { if (Build.VERSION.SDK_INT >= 31 /* Android 12.0 (S) */) {
flags = FLAG_MUTABLE; flags = FLAG_MUTABLE;
} else { } else {
flags = 0; flags = 0;

6
android-project/app/src/main/java/org/libsdl/app/HIDDeviceUSB.java

@ -52,7 +52,7 @@ class HIDDeviceUSB implements HIDDevice {
@Override @Override
public String getSerialNumber() { public String getSerialNumber() {
String result = null; String result = null;
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
try { try {
result = mDevice.getSerialNumber(); result = mDevice.getSerialNumber();
} }
@ -74,7 +74,7 @@ class HIDDeviceUSB implements HIDDevice {
@Override @Override
public String getManufacturerName() { public String getManufacturerName() {
String result = null; String result = null;
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
result = mDevice.getManufacturerName(); result = mDevice.getManufacturerName();
} }
if (result == null) { if (result == null) {
@ -86,7 +86,7 @@ class HIDDeviceUSB implements HIDDevice {
@Override @Override
public String getProductName() { public String getProductName() {
String result = null; String result = null;
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
result = mDevice.getProductName(); result = mDevice.getProductName();
} }
if (result == null) { if (result == null) {

84
android-project/app/src/main/java/org/libsdl/app/SDLActivity.java

@ -60,8 +60,8 @@ import java.util.Locale;
public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener { public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener {
private static final String TAG = "SDL"; private static final String TAG = "SDL";
private static final int SDL_MAJOR_VERSION = 2; private static final int SDL_MAJOR_VERSION = 2;
private static final int SDL_MINOR_VERSION = 27; private static final int SDL_MINOR_VERSION = 28;
private static final int SDL_MICRO_VERSION = 0; private static final int SDL_MICRO_VERSION = 5;
/* /*
// Display InputType.SOURCE/CLASS of events and devices // Display InputType.SOURCE/CLASS of events and devices
// //
@ -93,7 +93,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
s2 = s_copy & InputDevice.SOURCE_ANY; // keep source only, no class; s2 = s_copy & InputDevice.SOURCE_ANY; // keep source only, no class;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= 23) {
tst = InputDevice.SOURCE_BLUETOOTH_STYLUS; tst = InputDevice.SOURCE_BLUETOOTH_STYLUS;
if ((s & tst) == tst) src += " BLUETOOTH_STYLUS"; if ((s & tst) == tst) src += " BLUETOOTH_STYLUS";
s2 &= ~tst; s2 &= ~tst;
@ -107,7 +107,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
if ((s & tst) == tst) src += " GAMEPAD"; if ((s & tst) == tst) src += " GAMEPAD";
s2 &= ~tst; s2 &= ~tst;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= 21) {
tst = InputDevice.SOURCE_HDMI; tst = InputDevice.SOURCE_HDMI;
if ((s & tst) == tst) src += " HDMI"; if ((s & tst) == tst) src += " HDMI";
s2 &= ~tst; s2 &= ~tst;
@ -146,7 +146,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
if ((s & tst) == tst) src += " TOUCHSCREEN"; if ((s & tst) == tst) src += " TOUCHSCREEN";
s2 &= ~tst; s2 &= ~tst;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (Build.VERSION.SDK_INT >= 18) {
tst = InputDevice.SOURCE_TOUCH_NAVIGATION; tst = InputDevice.SOURCE_TOUCH_NAVIGATION;
if ((s & tst) == tst) src += " TOUCH_NAVIGATION"; if ((s & tst) == tst) src += " TOUCH_NAVIGATION";
s2 &= ~tst; s2 &= ~tst;
@ -170,7 +170,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
*/ */
public static boolean mIsResumedCalled, mHasFocus; public static boolean mIsResumedCalled, mHasFocus;
public static final boolean mHasMultiWindow = (Build.VERSION.SDK_INT >= 24); public static final boolean mHasMultiWindow = (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */);
// Cursor types // Cursor types
// private static final int SDL_SYSTEM_CURSOR_NONE = -1; // private static final int SDL_SYSTEM_CURSOR_NONE = -1;
@ -224,9 +224,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
protected static SDLGenericMotionListener_API12 getMotionListener() { protected static SDLGenericMotionListener_API12 getMotionListener() {
if (mMotionListener == null) { if (mMotionListener == null) {
if (Build.VERSION.SDK_INT >= 26) { if (Build.VERSION.SDK_INT >= 26 /* Android 8.0 (O) */) {
mMotionListener = new SDLGenericMotionListener_API26(); mMotionListener = new SDLGenericMotionListener_API26();
} else if (Build.VERSION.SDK_INT >= 24) { } else if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
mMotionListener = new SDLGenericMotionListener_API24(); mMotionListener = new SDLGenericMotionListener_API24();
} else { } else {
mMotionListener = new SDLGenericMotionListener_API12(); mMotionListener = new SDLGenericMotionListener_API12();
@ -404,7 +404,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
SDLActivity.onNativeOrientationChanged(mCurrentOrientation); SDLActivity.onNativeOrientationChanged(mCurrentOrientation);
try { try {
if (Build.VERSION.SDK_INT < 24) { if (Build.VERSION.SDK_INT < 24 /* Android 7.0 (N) */) {
mCurrentLocale = getContext().getResources().getConfiguration().locale; mCurrentLocale = getContext().getResources().getConfiguration().locale;
} else { } else {
mCurrentLocale = getContext().getResources().getConfiguration().getLocales().get(0); mCurrentLocale = getContext().getResources().getConfiguration().getLocales().get(0);
@ -768,7 +768,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
} }
break; break;
case COMMAND_CHANGE_WINDOW_STYLE: case COMMAND_CHANGE_WINDOW_STYLE:
if (Build.VERSION.SDK_INT >= 19) { if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) {
if (context instanceof Activity) { if (context instanceof Activity) {
Window window = ((Activity) context).getWindow(); Window window = ((Activity) context).getWindow();
if (window != null) { if (window != null) {
@ -843,7 +843,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
msg.obj = data; msg.obj = data;
boolean result = commandHandler.sendMessage(msg); boolean result = commandHandler.sendMessage(msg);
if (Build.VERSION.SDK_INT >= 19) { if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) {
if (command == COMMAND_CHANGE_WINDOW_STYLE) { if (command == COMMAND_CHANGE_WINDOW_STYLE) {
// Ensure we don't return until the resize has actually happened, // Ensure we don't return until the resize has actually happened,
// or 500ms have passed. // or 500ms have passed.
@ -1095,7 +1095,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
// thus SDK version 27. If we are in DeX mode and not API 27 or higher, as a result, // thus SDK version 27. If we are in DeX mode and not API 27 or higher, as a result,
// we should stick to relative mode. // we should stick to relative mode.
// //
if ((Build.VERSION.SDK_INT < 27) && isDeXMode()) { if (Build.VERSION.SDK_INT < 27 /* Android 8.1 (O_MR1) */ && isDeXMode()) {
return false; return false;
} }
@ -1185,7 +1185,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static boolean isDeXMode() { public static boolean isDeXMode() {
if (Build.VERSION.SDK_INT < 24) { if (Build.VERSION.SDK_INT < 24 /* Android 7.0 (N) */) {
return false; return false;
} }
try { try {
@ -1345,23 +1345,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
} }
} }
if ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (isTextInputEvent(event)) {
if (ic != null) {
ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
} else {
SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1);
}
}
onNativeKeyDown(keyCode);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
onNativeKeyUp(keyCode);
return true;
}
}
if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) { if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) {
// on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses
// they are ignored here because sending them as mouse input to SDL is messy // they are ignored here because sending them as mouse input to SDL is messy
@ -1376,6 +1359,21 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
} }
} }
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (isTextInputEvent(event)) {
if (ic != null) {
ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
} else {
SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1);
}
}
onNativeKeyDown(keyCode);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
onNativeKeyUp(keyCode);
return true;
}
return false; return false;
} }
@ -1622,7 +1620,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
private final Runnable rehideSystemUi = new Runnable() { private final Runnable rehideSystemUi = new Runnable() {
@Override @Override
public void run() { public void run() {
if (Build.VERSION.SDK_INT >= 19) { if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) {
int flags = View.SYSTEM_UI_FLAG_FULLSCREEN | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
@ -1675,7 +1673,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888); Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
++mLastCursorID; ++mLastCursorID;
if (Build.VERSION.SDK_INT >= 24) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
try { try {
mCursors.put(mLastCursorID, PointerIcon.create(bitmap, hotSpotX, hotSpotY)); mCursors.put(mLastCursorID, PointerIcon.create(bitmap, hotSpotX, hotSpotY));
} catch (Exception e) { } catch (Exception e) {
@ -1691,7 +1689,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static void destroyCustomCursor(int cursorID) { public static void destroyCustomCursor(int cursorID) {
if (Build.VERSION.SDK_INT >= 24) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
try { try {
mCursors.remove(cursorID); mCursors.remove(cursorID);
} catch (Exception e) { } catch (Exception e) {
@ -1705,7 +1703,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
*/ */
public static boolean setCustomCursor(int cursorID) { public static boolean setCustomCursor(int cursorID) {
if (Build.VERSION.SDK_INT >= 24) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
try { try {
mSurface.setPointerIcon(mCursors.get(cursorID)); mSurface.setPointerIcon(mCursors.get(cursorID));
} catch (Exception e) { } catch (Exception e) {
@ -1760,7 +1758,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
cursor_type = 1002; //PointerIcon.TYPE_HAND; cursor_type = 1002; //PointerIcon.TYPE_HAND;
break; break;
} }
if (Build.VERSION.SDK_INT >= 24) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
try { try {
mSurface.setPointerIcon(PointerIcon.getSystemIcon(SDL.getContext(), cursor_type)); mSurface.setPointerIcon(PointerIcon.getSystemIcon(SDL.getContext(), cursor_type));
} catch (Exception e) { } catch (Exception e) {
@ -1774,7 +1772,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static void requestPermission(String permission, int requestCode) { public static void requestPermission(String permission, int requestCode) {
if (Build.VERSION.SDK_INT < 23) { if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) {
nativePermissionResult(requestCode, true); nativePermissionResult(requestCode, true);
return; return;
} }
@ -1803,7 +1801,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
i.setData(Uri.parse(url)); i.setData(Uri.parse(url));
int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK; int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT; flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
} else { } else {
flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET; flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
@ -2007,6 +2005,18 @@ class SDLInputConnection extends BaseInputConnection {
@Override @Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) { public boolean deleteSurroundingText(int beforeLength, int afterLength) {
if (Build.VERSION.SDK_INT <= 29 /* Android 10.0 (Q) */) {
// Workaround to capture backspace key. Ref: http://stackoverflow.com/questions>/14560344/android-backspace-in-webview-baseinputconnection
// and https://bugzilla.libsdl.org/show_bug.cgi?id=2265
if (beforeLength > 0 && afterLength == 0) {
// backspace(s)
while (beforeLength-- > 0) {
nativeGenerateScancodeForUnichar('\b');
}
return true;
}
}
if (!super.deleteSurroundingText(beforeLength, afterLength)) { if (!super.deleteSurroundingText(beforeLength, afterLength)) {
return false; return false;
} }

34
android-project/app/src/main/java/org/libsdl/app/SDLAudioManager.java

@ -29,7 +29,7 @@ public class SDLAudioManager {
mAudioRecord = null; mAudioRecord = null;
mAudioDeviceCallback = null; mAudioDeviceCallback = null;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if(Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */)
{ {
mAudioDeviceCallback = new AudioDeviceCallback() { mAudioDeviceCallback = new AudioDeviceCallback() {
@Override @Override
@ -79,14 +79,14 @@ public class SDLAudioManager {
Log.v(TAG, "Opening " + (isCapture ? "capture" : "playback") + ", requested " + desiredFrames + " frames of " + desiredChannels + " channel " + getAudioFormatString(audioFormat) + " audio at " + sampleRate + " Hz"); Log.v(TAG, "Opening " + (isCapture ? "capture" : "playback") + ", requested " + desiredFrames + " frames of " + desiredChannels + " channel " + getAudioFormatString(audioFormat) + " audio at " + sampleRate + " Hz");
/* On older devices let's use known good settings */ /* On older devices let's use known good settings */
if (Build.VERSION.SDK_INT < 21) { if (Build.VERSION.SDK_INT < 21 /* Android 5.0 (LOLLIPOP) */) {
if (desiredChannels > 2) { if (desiredChannels > 2) {
desiredChannels = 2; desiredChannels = 2;
} }
} }
/* AudioTrack has sample rate limitation of 48000 (fixed in 5.0.2) */ /* AudioTrack has sample rate limitation of 48000 (fixed in 5.0.2) */
if (Build.VERSION.SDK_INT < 22) { if (Build.VERSION.SDK_INT < 22 /* Android 5.1 (LOLLIPOP_MR1) */) {
if (sampleRate < 8000) { if (sampleRate < 8000) {
sampleRate = 8000; sampleRate = 8000;
} else if (sampleRate > 48000) { } else if (sampleRate > 48000) {
@ -95,7 +95,7 @@ public class SDLAudioManager {
} }
if (audioFormat == AudioFormat.ENCODING_PCM_FLOAT) { if (audioFormat == AudioFormat.ENCODING_PCM_FLOAT) {
int minSDKVersion = (isCapture ? 23 : 21); int minSDKVersion = (isCapture ? 23 /* Android 6.0 (M) */ : 21 /* Android 5.0 (LOLLIPOP) */);
if (Build.VERSION.SDK_INT < minSDKVersion) { if (Build.VERSION.SDK_INT < minSDKVersion) {
audioFormat = AudioFormat.ENCODING_PCM_16BIT; audioFormat = AudioFormat.ENCODING_PCM_16BIT;
} }
@ -156,7 +156,7 @@ public class SDLAudioManager {
channelConfig = AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_BACK_CENTER; channelConfig = AudioFormat.CHANNEL_OUT_5POINT1 | AudioFormat.CHANNEL_OUT_BACK_CENTER;
break; break;
case 8: case 8:
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23 /* Android 6.0 (M) */) {
channelConfig = AudioFormat.CHANNEL_OUT_7POINT1_SURROUND; channelConfig = AudioFormat.CHANNEL_OUT_7POINT1_SURROUND;
} else { } else {
Log.v(TAG, "Requested " + desiredChannels + " channels, getting 5.1 surround"); Log.v(TAG, "Requested " + desiredChannels + " channels, getting 5.1 surround");
@ -237,7 +237,7 @@ public class SDLAudioManager {
return null; return null;
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && deviceId != 0) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */ && deviceId != 0) {
mAudioRecord.setPreferredDevice(getOutputAudioDeviceInfo(deviceId)); mAudioRecord.setPreferredDevice(getOutputAudioDeviceInfo(deviceId));
} }
@ -264,7 +264,7 @@ public class SDLAudioManager {
return null; return null;
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && deviceId != 0) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */ && deviceId != 0) {
mAudioTrack.setPreferredDevice(getInputAudioDeviceInfo(deviceId)); mAudioTrack.setPreferredDevice(getInputAudioDeviceInfo(deviceId));
} }
@ -283,7 +283,7 @@ public class SDLAudioManager {
} }
private static AudioDeviceInfo getInputAudioDeviceInfo(int deviceId) { private static AudioDeviceInfo getInputAudioDeviceInfo(int deviceId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)) return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS))
.filter(deviceInfo -> deviceInfo.getId() == deviceId) .filter(deviceInfo -> deviceInfo.getId() == deviceId)
@ -295,7 +295,7 @@ public class SDLAudioManager {
} }
private static AudioDeviceInfo getOutputAudioDeviceInfo(int deviceId) { private static AudioDeviceInfo getOutputAudioDeviceInfo(int deviceId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)) return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS))
.filter(deviceInfo -> deviceInfo.getId() == deviceId) .filter(deviceInfo -> deviceInfo.getId() == deviceId)
@ -307,14 +307,14 @@ public class SDLAudioManager {
} }
private static void registerAudioDeviceCallback() { private static void registerAudioDeviceCallback() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
audioManager.registerAudioDeviceCallback(mAudioDeviceCallback, null); audioManager.registerAudioDeviceCallback(mAudioDeviceCallback, null);
} }
} }
private static void unregisterAudioDeviceCallback(Context context) { private static void unregisterAudioDeviceCallback(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.unregisterAudioDeviceCallback(mAudioDeviceCallback); audioManager.unregisterAudioDeviceCallback(mAudioDeviceCallback);
} }
@ -324,7 +324,7 @@ public class SDLAudioManager {
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static int[] getAudioOutputDevices() { public static int[] getAudioOutputDevices() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)).mapToInt(AudioDeviceInfo::getId).toArray(); return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)).mapToInt(AudioDeviceInfo::getId).toArray();
} else { } else {
@ -336,7 +336,7 @@ public class SDLAudioManager {
* This method is called by SDL using JNI. * This method is called by SDL using JNI.
*/ */
public static int[] getAudioInputDevices() { public static int[] getAudioInputDevices() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)).mapToInt(AudioDeviceInfo::getId).toArray(); return Arrays.stream(audioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)).mapToInt(AudioDeviceInfo::getId).toArray();
} else { } else {
@ -360,7 +360,7 @@ public class SDLAudioManager {
return; return;
} }
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { if (android.os.Build.VERSION.SDK_INT < 21 /* Android 5.0 (LOLLIPOP) */) {
Log.e(TAG, "Attempted to make an incompatible audio call with uninitialized audio! (floating-point output is supported since Android 5.0 Lollipop)"); Log.e(TAG, "Attempted to make an incompatible audio call with uninitialized audio! (floating-point output is supported since Android 5.0 Lollipop)");
return; return;
} }
@ -443,7 +443,7 @@ public class SDLAudioManager {
/** This method is called by SDL using JNI. */ /** This method is called by SDL using JNI. */
public static int captureReadFloatBuffer(float[] buffer, boolean blocking) { public static int captureReadFloatBuffer(float[] buffer, boolean blocking) {
if (Build.VERSION.SDK_INT < 23) { if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) {
return 0; return 0;
} else { } else {
return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING);
@ -452,7 +452,7 @@ public class SDLAudioManager {
/** This method is called by SDL using JNI. */ /** This method is called by SDL using JNI. */
public static int captureReadShortBuffer(short[] buffer, boolean blocking) { public static int captureReadShortBuffer(short[] buffer, boolean blocking) {
if (Build.VERSION.SDK_INT < 23) { if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) {
return mAudioRecord.read(buffer, 0, buffer.length); return mAudioRecord.read(buffer, 0, buffer.length);
} else { } else {
return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING);
@ -461,7 +461,7 @@ public class SDLAudioManager {
/** This method is called by SDL using JNI. */ /** This method is called by SDL using JNI. */
public static int captureReadByteBuffer(byte[] buffer, boolean blocking) { public static int captureReadByteBuffer(byte[] buffer, boolean blocking) {
if (Build.VERSION.SDK_INT < 23) { if (Build.VERSION.SDK_INT < 23 /* Android 6.0 (M) */) {
return mAudioRecord.read(buffer, 0, buffer.length); return mAudioRecord.read(buffer, 0, buffer.length);
} else { } else {
return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING); return mAudioRecord.read(buffer, 0, buffer.length, blocking ? AudioRecord.READ_BLOCKING : AudioRecord.READ_NON_BLOCKING);

8
android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java

@ -42,7 +42,7 @@ public class SDLControllerManager
public static void initialize() { public static void initialize() {
if (mJoystickHandler == null) { if (mJoystickHandler == null) {
if (Build.VERSION.SDK_INT >= 19) { if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) {
mJoystickHandler = new SDLJoystickHandler_API19(); mJoystickHandler = new SDLJoystickHandler_API19();
} else { } else {
mJoystickHandler = new SDLJoystickHandler_API16(); mJoystickHandler = new SDLJoystickHandler_API16();
@ -50,7 +50,7 @@ public class SDLControllerManager
} }
if (mHapticHandler == null) { if (mHapticHandler == null) {
if (Build.VERSION.SDK_INT >= 26) { if (Build.VERSION.SDK_INT >= 26 /* Android 8.0 (O) */) {
mHapticHandler = new SDLHapticHandler_API26(); mHapticHandler = new SDLHapticHandler_API26();
} else { } else {
mHapticHandler = new SDLHapticHandler(); mHapticHandler = new SDLHapticHandler();
@ -809,7 +809,7 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
@Override @Override
public boolean supportsRelativeMouse() { public boolean supportsRelativeMouse() {
return (!SDLActivity.isDeXMode() || (Build.VERSION.SDK_INT >= 27)); return (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */);
} }
@Override @Override
@ -819,7 +819,7 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 {
@Override @Override
public boolean setRelativeMouseEnabled(boolean enabled) { public boolean setRelativeMouseEnabled(boolean enabled) {
if (!SDLActivity.isDeXMode() || (Build.VERSION.SDK_INT >= 27)) { if (!SDLActivity.isDeXMode() || Build.VERSION.SDK_INT >= 27 /* Android 8.1 (O_MR1) */) {
if (enabled) { if (enabled) {
SDLActivity.getContentView().requestPointerCapture(); SDLActivity.getContentView().requestPointerCapture();
} else { } else {

4
android-project/app/src/main/java/org/libsdl/app/SDLSurface.java

@ -116,7 +116,7 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
int nDeviceHeight = height; int nDeviceHeight = height;
try try
{ {
if (Build.VERSION.SDK_INT >= 17) { if (Build.VERSION.SDK_INT >= 17 /* Android 4.2 (JELLY_BEAN_MR1) */) {
DisplayMetrics realMetrics = new DisplayMetrics(); DisplayMetrics realMetrics = new DisplayMetrics();
mDisplay.getRealMetrics( realMetrics ); mDisplay.getRealMetrics( realMetrics );
nDeviceWidth = realMetrics.widthPixels; nDeviceWidth = realMetrics.widthPixels;
@ -163,7 +163,7 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
// Don't skip in MultiWindow. // Don't skip in MultiWindow.
if (skip) { if (skip) {
if (Build.VERSION.SDK_INT >= 24) { if (Build.VERSION.SDK_INT >= 24 /* Android 7.0 (N) */) {
if (SDLActivity.mSingleton.isInMultiWindowMode()) { if (SDLActivity.mSingleton.isInMultiWindowMode()) {
Log.v("SDL", "Don't skip in Multi-Window"); Log.v("SDL", "Don't skip in Multi-Window");
skip = false; skip = false;

Loading…
Cancel
Save