mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 19:38:14 +00:00
Android: simplification since min API supported is 21
This commit is contained in:
@@ -52,13 +52,11 @@ 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,39 +908,37 @@ 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) {
|
if ((msg.obj instanceof Integer) && ((Integer) msg.obj != 0)) {
|
||||||
if ((msg.obj instanceof Integer) && ((Integer) msg.obj != 0)) {
|
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 |
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
|
window.getDecorView().setSystemUiVisibility(flags);
|
||||||
window.getDecorView().setSystemUiVisibility(flags);
|
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||||
window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
SDLActivity.mFullscreenModeActive = true;
|
||||||
SDLActivity.mFullscreenModeActive = true;
|
} else {
|
||||||
} else {
|
int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_VISIBLE;
|
||||||
int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_VISIBLE;
|
window.getDecorView().setSystemUiVisibility(flags);
|
||||||
window.getDecorView().setSystemUiVisibility(flags);
|
window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
SDLActivity.mFullscreenModeActive = false;
|
||||||
SDLActivity.mFullscreenModeActive = false;
|
}
|
||||||
}
|
if (Build.VERSION.SDK_INT >= 28 /* Android 9 (Pie) */) {
|
||||||
if (Build.VERSION.SDK_INT >= 28 /* Android 9 (Pie) */) {
|
window.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||||
window.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
}
|
||||||
}
|
if (Build.VERSION.SDK_INT >= 30 /* Android 11 (R) */ &&
|
||||||
if (Build.VERSION.SDK_INT >= 30 /* Android 11 (R) */ &&
|
Build.VERSION.SDK_INT < 35 /* Android 15 */) {
|
||||||
Build.VERSION.SDK_INT < 35 /* Android 15 */) {
|
SDLActivity.onNativeInsetsChanged(0, 0, 0, 0);
|
||||||
SDLActivity.onNativeInsetsChanged(0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Log.e(TAG, "error handling message, getContext() returned no Activity");
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "error handling message, getContext() returned no Activity");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case COMMAND_TEXTEDIT_HIDE:
|
case COMMAND_TEXTEDIT_HIDE:
|
||||||
@@ -994,53 +988,51 @@ 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.
|
|
||||||
|
|
||||||
boolean bShouldWait = false;
|
boolean bShouldWait = false;
|
||||||
|
|
||||||
if (data instanceof Integer) {
|
if (data instanceof Integer) {
|
||||||
// Let's figure out if we're already laid out fullscreen or not.
|
// Let's figure out if we're already laid out fullscreen or not.
|
||||||
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||||
DisplayMetrics realMetrics = new DisplayMetrics();
|
DisplayMetrics realMetrics = new DisplayMetrics();
|
||||||
display.getRealMetrics(realMetrics);
|
display.getRealMetrics(realMetrics);
|
||||||
|
|
||||||
boolean bFullscreenLayout = ((realMetrics.widthPixels == mSurface.getWidth()) &&
|
boolean bFullscreenLayout = ((realMetrics.widthPixels == mSurface.getWidth()) &&
|
||||||
(realMetrics.heightPixels == mSurface.getHeight()));
|
(realMetrics.heightPixels == mSurface.getHeight()));
|
||||||
|
|
||||||
if ((Integer) data == 1) {
|
if ((Integer) data == 1) {
|
||||||
// If we aren't laid out fullscreen or actively in fullscreen mode already, we're going
|
// If we aren't laid out fullscreen or actively in fullscreen mode already, we're going
|
||||||
// to change size and should wait for surfaceChanged() before we return, so the size
|
// to change size and should wait for surfaceChanged() before we return, so the size
|
||||||
// is right back in native code. If we're already laid out fullscreen, though, we're
|
// is right back in native code. If we're already laid out fullscreen, though, we're
|
||||||
// not going to change size even if we change decor modes, so we shouldn't wait for
|
// not going to change size even if we change decor modes, so we shouldn't wait for
|
||||||
// surfaceChanged() -- which may not even happen -- and should return immediately.
|
// surfaceChanged() -- which may not even happen -- and should return immediately.
|
||||||
bShouldWait = !bFullscreenLayout;
|
bShouldWait = !bFullscreenLayout;
|
||||||
} else {
|
} else {
|
||||||
// If we're laid out fullscreen (even if the status bar and nav bar are present),
|
// If we're laid out fullscreen (even if the status bar and nav bar are present),
|
||||||
// or are actively in fullscreen, we're going to change size and should wait for
|
// or are actively in fullscreen, we're going to change size and should wait for
|
||||||
// surfaceChanged before we return, so the size is right back in native code.
|
// surfaceChanged before we return, so the size is right back in native code.
|
||||||
bShouldWait = bFullscreenLayout;
|
bShouldWait = bFullscreenLayout;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bShouldWait && (SDLActivity.getContext() != null)) {
|
if (bShouldWait && (SDLActivity.getContext() != null)) {
|
||||||
// We'll wait for the surfaceChanged() method, which will notify us
|
// We'll wait for the surfaceChanged() method, which will notify us
|
||||||
// when called. That way, we know our current size is really the
|
// when called. That way, we know our current size is really the
|
||||||
// size we need, instead of grabbing a size that's still got
|
// size we need, instead of grabbing a size that's still got
|
||||||
// the navigation and/or status bars before they're hidden.
|
// the navigation and/or status bars before they're hidden.
|
||||||
//
|
//
|
||||||
// We'll wait for up to half a second, because some devices
|
// We'll wait for up to half a second, because some devices
|
||||||
// take a surprisingly long time for the surface resize, but
|
// take a surprisingly long time for the surface resize, but
|
||||||
// then we'll just give up and return.
|
// then we'll just give up and return.
|
||||||
//
|
//
|
||||||
synchronized (SDLActivity.getContext()) {
|
synchronized (SDLActivity.getContext()) {
|
||||||
try {
|
try {
|
||||||
SDLActivity.getContext().wait(500);
|
SDLActivity.getContext().wait(500);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
ie.printStackTrace();
|
ie.printStackTrace();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1774,16 +1766,14 @@ 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 |
|
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.INVISIBLE;
|
|
||||||
|
|
||||||
SDLActivity.this.getWindow().getDecorView().setSystemUiVisibility(flags);
|
SDLActivity.this.getWindow().getDecorView().setSystemUiVisibility(flags);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -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