mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-07 20:08:13 +00:00
Android: simplification since min API supported is 21
This commit is contained in:
@@ -52,14 +52,12 @@ class HIDDeviceUSB implements HIDDevice {
|
|||||||
@Override
|
@Override
|
||||||
public String getSerialNumber() {
|
public String getSerialNumber() {
|
||||||
String result = null;
|
String result = null;
|
||||||
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
|
|
||||||
try {
|
try {
|
||||||
result = mDevice.getSerialNumber();
|
result = mDevice.getSerialNumber();
|
||||||
}
|
}
|
||||||
catch (SecurityException exception) {
|
catch (SecurityException exception) {
|
||||||
//Log.w(TAG, "App permissions mean we cannot get serial number for device " + getDeviceName() + " message: " + exception.getMessage());
|
//Log.w(TAG, "App permissions mean we cannot get serial number for device " + getDeviceName() + " message: " + exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = "";
|
result = "";
|
||||||
}
|
}
|
||||||
@@ -73,10 +71,8 @@ class HIDDeviceUSB implements HIDDevice {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getManufacturerName() {
|
public String getManufacturerName() {
|
||||||
String result = null;
|
String result;
|
||||||
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
|
|
||||||
result = mDevice.getManufacturerName();
|
result = mDevice.getManufacturerName();
|
||||||
}
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = String.format("%x", getVendorId());
|
result = String.format("%x", getVendorId());
|
||||||
}
|
}
|
||||||
@@ -85,10 +81,8 @@ class HIDDeviceUSB implements HIDDevice {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProductName() {
|
public String getProductName() {
|
||||||
String result = null;
|
String result;
|
||||||
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
|
|
||||||
result = mDevice.getProductName();
|
result = mDevice.getProductName();
|
||||||
}
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
result = String.format("%x", getProductId());
|
result = String.format("%x", getProductId());
|
||||||
}
|
}
|
||||||
|
@@ -107,11 +107,9 @@ 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 >= 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;
|
||||||
}
|
|
||||||
|
|
||||||
tst = InputDevice.SOURCE_JOYSTICK;
|
tst = InputDevice.SOURCE_JOYSTICK;
|
||||||
if ((s & tst) == tst) src += " JOYSTICK";
|
if ((s & tst) == tst) src += " JOYSTICK";
|
||||||
@@ -146,11 +144,9 @@ 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 >= 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;
|
||||||
}
|
|
||||||
|
|
||||||
tst = InputDevice.SOURCE_TRACKBALL;
|
tst = InputDevice.SOURCE_TRACKBALL;
|
||||||
if ((s & tst) == tst) src += " TRACKBALL";
|
if ((s & tst) == tst) src += " TRACKBALL";
|
||||||
@@ -912,7 +908,6 @@ 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 /* 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) {
|
||||||
@@ -945,7 +940,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "error handling message, getContext() returned no Activity");
|
Log.e(TAG, "error handling message, getContext() returned no Activity");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case COMMAND_TEXTEDIT_HIDE:
|
case COMMAND_TEXTEDIT_HIDE:
|
||||||
if (mTextEdit != null) {
|
if (mTextEdit != null) {
|
||||||
@@ -994,7 +988,6 @@ 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 /* 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.
|
||||||
@@ -1044,7 +1037,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1774,7 +1766,6 @@ 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 /* 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 |
|
||||||
@@ -1784,7 +1775,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||||||
|
|
||||||
SDLActivity.this.getWindow().getDecorView().setSystemUiVisibility(flags);
|
SDLActivity.this.getWindow().getDecorView().setSystemUiVisibility(flags);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public void onSystemUiVisibilityChange(int visibility) {
|
public void onSystemUiVisibilityChange(int visibility) {
|
||||||
@@ -1978,12 +1968,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||||
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
|
||||||
if (Build.VERSION.SDK_INT >= 21 /* Android 5.0 (LOLLIPOP) */) {
|
| Intent.FLAG_ACTIVITY_MULTIPLE_TASK
|
||||||
flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
|
| Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
|
||||||
} else {
|
|
||||||
flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
|
|
||||||
}
|
|
||||||
i.addFlags(flags);
|
i.addFlags(flags);
|
||||||
|
|
||||||
mSingleton.startActivity(i);
|
mSingleton.startActivity(i);
|
||||||
|
@@ -43,11 +43,7 @@ public class SDLControllerManager
|
|||||||
|
|
||||||
static void initialize() {
|
static void initialize() {
|
||||||
if (mJoystickHandler == null) {
|
if (mJoystickHandler == null) {
|
||||||
if (Build.VERSION.SDK_INT >= 19 /* Android 4.4 (KITKAT) */) {
|
mJoystickHandler = new SDLJoystickHandler();
|
||||||
mJoystickHandler = new SDLJoystickHandler_API19();
|
|
||||||
} else {
|
|
||||||
mJoystickHandler = new SDLJoystickHandler_API16();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHapticHandler == null) {
|
if (mHapticHandler == null) {
|
||||||
@@ -133,27 +129,10 @@ public class SDLControllerManager
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Actual joystick functionality available for API >= 19 devices */
|
||||||
class SDLJoystickHandler {
|
class SDLJoystickHandler {
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles given MotionEvent.
|
|
||||||
* @param event the event to be handled.
|
|
||||||
* @return if given event was processed.
|
|
||||||
*/
|
|
||||||
boolean handleMotionEvent(MotionEvent event) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles adding and removing of input devices.
|
|
||||||
*/
|
|
||||||
void pollInputDevices() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Actual joystick functionality available for API >= 12 devices */
|
|
||||||
class SDLJoystickHandler_API16 extends SDLJoystickHandler {
|
|
||||||
|
|
||||||
static class SDLJoystick {
|
static class SDLJoystick {
|
||||||
int device_id;
|
int device_id;
|
||||||
String name;
|
String name;
|
||||||
@@ -210,12 +189,14 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
|
|||||||
|
|
||||||
private final ArrayList<SDLJoystick> mJoysticks;
|
private final ArrayList<SDLJoystick> mJoysticks;
|
||||||
|
|
||||||
SDLJoystickHandler_API16() {
|
SDLJoystickHandler() {
|
||||||
|
|
||||||
mJoysticks = new ArrayList<SDLJoystick>();
|
mJoysticks = new ArrayList<SDLJoystick>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Handles adding and removing of input devices.
|
||||||
|
*/
|
||||||
void pollInputDevices() {
|
void pollInputDevices() {
|
||||||
int[] deviceIds = InputDevice.getDeviceIds();
|
int[] deviceIds = InputDevice.getDeviceIds();
|
||||||
|
|
||||||
@@ -298,7 +279,11 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Handles given MotionEvent.
|
||||||
|
* @param event the event to be handled.
|
||||||
|
* @return if given event was processed.
|
||||||
|
*/
|
||||||
boolean handleMotionEvent(MotionEvent event) {
|
boolean handleMotionEvent(MotionEvent event) {
|
||||||
int actionPointerIndex = event.getActionIndex();
|
int actionPointerIndex = event.getActionIndex();
|
||||||
int action = event.getActionMasked();
|
int action = event.getActionMasked();
|
||||||
@@ -330,33 +315,15 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
|
|||||||
|
|
||||||
return joystickDevice.getName();
|
return joystickDevice.getName();
|
||||||
}
|
}
|
||||||
int getProductId(InputDevice joystickDevice) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int getVendorId(InputDevice joystickDevice) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int getAxisMask(List<InputDevice.MotionRange> ranges) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
int getButtonMask(InputDevice joystickDevice) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SDLJoystickHandler_API19 extends SDLJoystickHandler_API16 {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
int getProductId(InputDevice joystickDevice) {
|
int getProductId(InputDevice joystickDevice) {
|
||||||
return joystickDevice.getProductId();
|
return joystickDevice.getProductId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
int getVendorId(InputDevice joystickDevice) {
|
int getVendorId(InputDevice joystickDevice) {
|
||||||
return joystickDevice.getVendorId();
|
return joystickDevice.getVendorId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
int getAxisMask(List<InputDevice.MotionRange> ranges) {
|
int getAxisMask(List<InputDevice.MotionRange> ranges) {
|
||||||
// For compatibility, keep computing the axis mask like before,
|
// For compatibility, keep computing the axis mask like before,
|
||||||
// only really distinguishing 2, 4 and 6 axes.
|
// only really distinguishing 2, 4 and 6 axes.
|
||||||
@@ -393,7 +360,6 @@ class SDLJoystickHandler_API19 extends SDLJoystickHandler_API16 {
|
|||||||
return axis_mask;
|
return axis_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
int getButtonMask(InputDevice joystickDevice) {
|
int getButtonMask(InputDevice joystickDevice) {
|
||||||
int button_mask = 0;
|
int button_mask = 0;
|
||||||
int[] keys = new int[] {
|
int[] keys = new int[] {
|
||||||
|
@@ -121,14 +121,12 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||||||
float density = 1.0f;
|
float density = 1.0f;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
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;
|
||||||
nDeviceHeight = realMetrics.heightPixels;
|
nDeviceHeight = realMetrics.heightPixels;
|
||||||
// Use densityDpi instead of density to more closely match what the UI scale is
|
// Use densityDpi instead of density to more closely match what the UI scale is
|
||||||
density = (float)realMetrics.densityDpi / 160.0f;
|
density = (float)realMetrics.densityDpi / 160.0f;
|
||||||
}
|
|
||||||
} catch(Exception ignored) {
|
} catch(Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user