android: pick width & height as default constant in portrait orientation

This commit is contained in:
王劲鹏 2020-08-25 17:01:02 +08:00 committed by osborn
parent 4222b8f16c
commit 26103255a0

View File

@ -17,6 +17,7 @@ package pub.doric.utils;
import android.content.Context; import android.content.Context;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
@ -164,8 +165,14 @@ public class DoricUtils {
Display display = manager.getDefaultDisplay(); Display display = manager.getDefaultDisplay();
if (display != null) { if (display != null) {
display.getMetrics(dm); display.getMetrics(dm);
int orientation = context.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
sScreenWidthPixels = dm.widthPixels; sScreenWidthPixels = dm.widthPixels;
sScreenHeightPixels = dm.heightPixels; sScreenHeightPixels = dm.heightPixels;
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
sScreenWidthPixels = dm.heightPixels;
sScreenHeightPixels = dm.widthPixels;
}
} }
return sScreenWidthPixels; return sScreenWidthPixels;
} }
@ -187,8 +194,14 @@ public class DoricUtils {
Display display = manager.getDefaultDisplay(); Display display = manager.getDefaultDisplay();
if (display != null) { if (display != null) {
display.getMetrics(dm); display.getMetrics(dm);
int orientation = context.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
sScreenWidthPixels = dm.widthPixels; sScreenWidthPixels = dm.widthPixels;
sScreenHeightPixels = dm.heightPixels; sScreenHeightPixels = dm.heightPixels;
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
sScreenWidthPixels = dm.heightPixels;
sScreenHeightPixels = dm.widthPixels;
}
} }
return sScreenHeightPixels; return sScreenHeightPixels;
} }