Android: fix incorrect screen sizes
@@ -75,22 +75,42 @@ public class BaseActivity extends Activity implements ServiceConnection {
public void reread(Context context) {
Logger.T(TAG, "Updating screen properties");
- WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
+ Activity actvt = null;
- Display d = wm.getDefaultDisplay();
- float dpr = RhodesActivity.getContext().getResources().getDisplayMetrics().density;
-
- mScreenWidth = d.getWidth();
- mScreenHeight = d.getHeight();
+ try {
+ actvt = RhodesActivity.safeGetInstance();
+ }
+ catch (Exception e) {
+ Logger.E(TAG, "can not get RhodesActivity !");
+ }
- mRealScreenWidth = (int) (d.getWidth() / dpr);
- mRealScreenHeight = (int) (d.getHeight() / dpr);
+ DisplayMetrics displayMetrics = new DisplayMetrics();
+ boolean isOK = false;
- DisplayMetrics metrics = new DisplayMetrics();
- d.getMetrics(metrics);
+ try {
+ if (actvt == null) {
+ displayMetrics = RhodesActivity.getContext().getResources().getDisplayMetrics();
+ isOK = true;
+ }
+ else {
+ actvt.getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
+ isOK = true;
+ }
+ }
+ catch (Exception e) {
+ Logger.E(TAG, "can not get real DisplayMetrics !");
+ }
+ if (!isOK) {
+ displayMetrics = RhodesActivity.getContext().getResources().getDisplayMetrics();
+ }
+ mRealScreenHeight = displayMetrics.heightPixels;
+ mRealScreenWidth = displayMetrics.widthPixels;
+ mScreenPpiX = displayMetrics.xdpi;
+ mScreenPpiY = displayMetrics.ydpi;
+ float density = displayMetrics.density;
+ mScreenWidth = (int)((float)mRealScreenWidth/density + 0.5);
+ mScreenHeight = (int)((float)mRealScreenHeight/density + 0.5);
- mScreenPpiX = metrics.xdpi;
- mScreenPpiY = metrics.ydpi;
mScreenOrientation = AndroidFunctionalityManager.getAndroidFunctionality().getScreenOrientation(context);
