mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-06 06:34:35 +00:00
Android get the display Density
This commit is contained in:
parent
6a27188023
commit
73dc327c84
5 changed files with 13 additions and 9 deletions
|
|
@ -311,7 +311,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||
mNextNativeState = NativeState.INIT;
|
||||
mCurrentNativeState = NativeState.INIT;
|
||||
}
|
||||
|
||||
|
||||
protected SDLSurface createSDLSurface(Context context) {
|
||||
return new SDLSurface(context);
|
||||
}
|
||||
|
|
@ -909,7 +909,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||
public static native void nativeResume();
|
||||
public static native void nativeFocusChanged(boolean hasFocus);
|
||||
public static native void onNativeDropFile(String filename);
|
||||
public static native void nativeSetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float rate);
|
||||
public static native void nativeSetScreenResolution(int surfaceWidth, int surfaceHeight, int deviceWidth, int deviceHeight, float density, float rate);
|
||||
public static native void onNativeResize();
|
||||
public static native void onNativeKeyDown(int keycode);
|
||||
public static native void onNativeKeyUp(int keycode);
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||
mHeight = height;
|
||||
int nDeviceWidth = width;
|
||||
int nDeviceHeight = height;
|
||||
float density = 1.0f;
|
||||
try
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
|
|
@ -121,6 +122,7 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||
mDisplay.getRealMetrics( realMetrics );
|
||||
nDeviceWidth = realMetrics.widthPixels;
|
||||
nDeviceHeight = realMetrics.heightPixels;
|
||||
density = realMetrics.density;
|
||||
}
|
||||
} catch(Exception ignored) {
|
||||
}
|
||||
|
|
@ -132,7 +134,7 @@ public class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
|
|||
|
||||
Log.v("SDL", "Window size: " + width + "x" + height);
|
||||
Log.v("SDL", "Device size: " + nDeviceWidth + "x" + nDeviceHeight);
|
||||
SDLActivity.nativeSetScreenResolution(width, height, nDeviceWidth, nDeviceHeight, mDisplay.getRefreshRate());
|
||||
SDLActivity.nativeSetScreenResolution(width, height, nDeviceWidth, nDeviceHeight, density, mDisplay.getRefreshRate());
|
||||
SDLActivity.onNativeResize();
|
||||
|
||||
// Prevent a screen distortion glitch,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue