Android: get screen resolution from Irrlicht
parent
dcd0b57f85
commit
c8497db807
|
@ -24,7 +24,6 @@ import android.app.ActivityManager;
|
|||
import android.app.NativeActivity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -68,7 +67,6 @@ public class GameActivity extends NativeActivity {
|
|||
|
||||
private int messageReturnCode = -1;
|
||||
private String messageReturnValue = "";
|
||||
private int height, width;
|
||||
private boolean consent, isMultiPlayer;
|
||||
private PreferencesHelper pf;
|
||||
private Disposable adInitSub;
|
||||
|
@ -84,12 +82,9 @@ public class GameActivity extends NativeActivity {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
Resources resources = getResources();
|
||||
height = bundle != null ? bundle.getInt("height", 0) : resources.getDisplayMetrics().heightPixels;
|
||||
width = bundle != null ? bundle.getInt("width", 0) : resources.getDisplayMetrics().widthPixels;
|
||||
consent = bundle == null || bundle.getBoolean("consent", true);
|
||||
consent = bundle.getBoolean("consent", true);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
hasKeyboard = !(resources.getConfiguration().hardKeyboardHidden == KEYBOARD_QWERTY);
|
||||
hasKeyboard = !(getResources().getConfiguration().hardKeyboardHidden == KEYBOARD_QWERTY);
|
||||
keyboardEvent(hasKeyboard);
|
||||
pf = getInstance(this);
|
||||
if (pf.isAdsEnable()) {
|
||||
|
@ -194,14 +189,6 @@ public class GameActivity extends NativeActivity {
|
|||
return getResources().getDisplayMetrics().density;
|
||||
}
|
||||
|
||||
public int getDisplayHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getDisplayWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public float getMemoryMax() {
|
||||
ActivityManager actManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
|
||||
|
|
|
@ -30,7 +30,6 @@ import android.content.IntentFilter;
|
|||
import android.graphics.BlendMode;
|
||||
import android.graphics.BlendModeColorFilter;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
|
@ -41,7 +40,6 @@ import android.os.Environment;
|
|||
import android.provider.Settings;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
@ -105,7 +103,6 @@ public class MainActivity extends AppCompatActivity implements CallBackListener,
|
|||
private static String FILES, WORLDS, GAMES;
|
||||
private final String versionName = BuildConfig.VERSION_NAME;
|
||||
private String unzipLocation, appData;
|
||||
private int height, width;
|
||||
private boolean consent;
|
||||
private ProgressBar mProgressBar, mProgressBarIndeterminate;
|
||||
private TextView mLoading;
|
||||
|
@ -219,18 +216,6 @@ public class MainActivity extends AppCompatActivity implements CallBackListener,
|
|||
}
|
||||
}
|
||||
|
||||
// real screen resolution
|
||||
private void getDefaultResolution() {
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
Point size = new Point();
|
||||
if (isGreaterOrEqual(Build.VERSION_CODES.JELLY_BEAN_MR1))
|
||||
display.getRealSize(size);
|
||||
else
|
||||
display.getSize(size);
|
||||
height = Math.min(size.x, size.y);
|
||||
width = Math.max(size.x, size.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
|
@ -304,10 +289,7 @@ public class MainActivity extends AppCompatActivity implements CallBackListener,
|
|||
}
|
||||
|
||||
private void startNative() {
|
||||
getDefaultResolution();
|
||||
Intent intent = new Intent(this, GameActivity.class);
|
||||
intent.putExtra("height", height);
|
||||
intent.putExtra("width", width);
|
||||
intent.putExtra("consent", consent);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
|
|
|
@ -7,7 +7,7 @@ buildscript {
|
|||
maven { url 'https://plugins.gradle.org/m2/' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.2.0'
|
||||
classpath 'com.android.tools.build:gradle:4.2.1'
|
||||
//noinspection GradleDynamicVersion
|
||||
/*classpath 'com.bugsnag:bugsnag-android-gradle-plugin:5.+'*/
|
||||
classpath 'de.undercouch:gradle-download-task:4.1.1'
|
||||
|
|
|
@ -537,12 +537,6 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
|
|||
|
||||
bool ClientLauncher::create_engine_device()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
// set correct resolution
|
||||
g_settings->setU16("screenW", porting::getDisplaySize().X);
|
||||
g_settings->setU16("screenH", porting::getDisplaySize().Y);
|
||||
#endif
|
||||
|
||||
// Resolution selection
|
||||
bool fullscreen = g_settings->getBool("fullscreen");
|
||||
u16 screenW = g_settings->getU16("screenW");
|
||||
|
@ -592,18 +586,43 @@ bool ClientLauncher::create_engine_device()
|
|||
|
||||
device = createDeviceEx(params);
|
||||
|
||||
if (device)
|
||||
if (device) {
|
||||
porting::initIrrlicht(device);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// Apply settings according to screen size
|
||||
// We can get real screen size only after device initialization finished
|
||||
float x_inches = porting::getWindowSize().X /
|
||||
(160.f * porting::getDisplayDensity());
|
||||
if (x_inches <= 3.7) {
|
||||
// small 4" phones
|
||||
g_settings->setFloat("hud_scaling", 0.55);
|
||||
g_settings->setU16("font_size", TTF_DEFAULT_FONT_SIZE - 1);
|
||||
g_settings->setFloat("mouse_sensitivity", 0.3);
|
||||
} else if (x_inches > 3.7 && x_inches <= 4.5) {
|
||||
// medium phones
|
||||
g_settings->setFloat("hud_scaling", 0.6);
|
||||
g_settings->setU16("font_size", TTF_DEFAULT_FONT_SIZE - 1);
|
||||
g_settings->setS16("selectionbox_width", 6);
|
||||
} else if (x_inches > 4.5 && x_inches <= 5.5) {
|
||||
// large 6" phones
|
||||
g_settings->setFloat("hud_scaling", 0.7);
|
||||
g_settings->setFloat("mouse_sensitivity", 0.15);
|
||||
g_settings->setS16("selectionbox_width", 6);
|
||||
} else if (x_inches > 5.5 && x_inches <= 6.5) {
|
||||
// 7" tablets
|
||||
g_settings->setFloat("hud_scaling", 0.9);
|
||||
g_settings->setS16("selectionbox_width", 6);
|
||||
}
|
||||
#endif
|
||||
#ifdef __IOS__
|
||||
if (device) {
|
||||
CIrrDeviceiOS* dev = (CIrrDeviceiOS*) device;
|
||||
porting::setViewController(dev->getViewController());
|
||||
#ifdef ADS
|
||||
ads_startup(dev->getViewController());
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return device != NULL;
|
||||
}
|
||||
|
|
|
@ -510,32 +510,6 @@ void set_default_settings(Settings *settings) {
|
|||
// Set font_path
|
||||
settings->setDefault("mono_font_path", "/system/fonts/DroidSansMono.ttf");
|
||||
settings->setDefault("fallback_font_path", "/system/fonts/DroidSans.ttf");
|
||||
|
||||
// Apply settings according to screen size
|
||||
float x_inches = (float) porting::getDisplaySize().X /
|
||||
(160.f * porting::getDisplayDensity());
|
||||
std::string font_size_str_small = std::to_string(TTF_DEFAULT_FONT_SIZE - 1);
|
||||
|
||||
if (x_inches <= 3.7) {
|
||||
// small 4" phones
|
||||
settings->setDefault("hud_scaling", "0.55");
|
||||
settings->setDefault("font_size", font_size_str_small);
|
||||
settings->setDefault("mouse_sensitivity", "0.3");
|
||||
} else if (x_inches > 3.7 && x_inches <= 4.5) {
|
||||
// medium phones
|
||||
settings->setDefault("hud_scaling", "0.6");
|
||||
settings->setDefault("font_size", font_size_str_small);
|
||||
settings->setDefault("selectionbox_width", "6");
|
||||
} else if (x_inches > 4.5 && x_inches <= 5.5) {
|
||||
// large 6" phones
|
||||
settings->setDefault("hud_scaling", "0.7");
|
||||
settings->setDefault("mouse_sensitivity", "0.15");
|
||||
settings->setDefault("selectionbox_width", "6");
|
||||
} else if (x_inches > 5.5 && x_inches <= 6.5) {
|
||||
// 7" tablets
|
||||
settings->setDefault("hud_scaling", "0.9");
|
||||
settings->setDefault("selectionbox_width", "6");
|
||||
}
|
||||
#endif // Android
|
||||
|
||||
// iOS Settings
|
||||
|
|
|
@ -298,7 +298,7 @@ void notifyExitGame()
|
|||
"notifyExitGame", "()V");
|
||||
|
||||
FATAL_ERROR_IF(notifyExit == nullptr,
|
||||
"porting::notifyExit unable to find java getDensity method");
|
||||
"porting::notifyExit unable to find java notifyExitGame method");
|
||||
|
||||
jnienv->CallVoidMethod(app_global->activity->clazz, notifyExit);
|
||||
}
|
||||
|
@ -321,32 +321,7 @@ float getDisplayDensity()
|
|||
return value;
|
||||
}
|
||||
|
||||
v2u32 getDisplaySize()
|
||||
{
|
||||
static bool firstrun = true;
|
||||
static v2u32 retval;
|
||||
|
||||
if (firstrun) {
|
||||
jmethodID getDisplayWidth = jnienv->GetMethodID(nativeActivity,
|
||||
"getDisplayWidth", "()I");
|
||||
|
||||
FATAL_ERROR_IF(getDisplayWidth == nullptr,
|
||||
"porting::getDisplayWidth unable to find java getDisplayWidth method");
|
||||
|
||||
retval.X = jnienv->CallIntMethod(app_global->activity->clazz,
|
||||
getDisplayWidth);
|
||||
|
||||
jmethodID getDisplayHeight = jnienv->GetMethodID(nativeActivity,
|
||||
"getDisplayHeight", "()I");
|
||||
|
||||
FATAL_ERROR_IF(getDisplayHeight == nullptr,
|
||||
"porting::getDisplayHeight unable to find java getDisplayHeight method");
|
||||
|
||||
retval.Y = jnienv->CallIntMethod(app_global->activity->clazz,
|
||||
getDisplayHeight);
|
||||
|
||||
firstrun = false;
|
||||
}
|
||||
return retval;
|
||||
v2u32 getDisplaySize() {
|
||||
return v2u32(0, 0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue