add alternate method

This commit is contained in:
Anthony Calosa
2022-08-01 15:57:15 +08:00
committed by GitHub
parent f840bd118f
commit 9505657e30

View File

@@ -449,13 +449,24 @@ public class Main extends AndroidApplication {
WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay(); Display display = windowManager.getDefaultDisplay();
Point size = new Point(); Point size = new Point();
/*if (real) if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size); if (real)
else display.getRealSize(size);
display.getSize(size); else
//real size display.getSize(size);
return Pair.of(size.x, size.y);*/ //method works only on Build.VERSION.SDK_INT >= 17 (4.2), need to update android dependency from 4.1.1.4 to at least 8.0 } else if (Build.VERSION.SDK_INT >= 14) {
return Pair.of(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); try {
size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
} catch (Exception e) {
size.x = Gdx.graphics.getWidth();
size.y = Gdx.graphics.getHeight();
}
} else {
size.x = Gdx.graphics.getWidth();
size.y = Gdx.graphics.getHeight();
}
return Pair.of(size.x, size.y);
} }
} }