From 26103255a09aee45549ad2c21a6c59296b1cf437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 25 Aug 2020 17:01:02 +0800 Subject: [PATCH] android: pick width & height as default constant in portrait orientation --- .../main/java/pub/doric/utils/DoricUtils.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/utils/DoricUtils.java b/doric-android/doric/src/main/java/pub/doric/utils/DoricUtils.java index b1fa8965..765dee6c 100644 --- a/doric-android/doric/src/main/java/pub/doric/utils/DoricUtils.java +++ b/doric-android/doric/src/main/java/pub/doric/utils/DoricUtils.java @@ -17,6 +17,7 @@ package pub.doric.utils; import android.content.Context; import android.content.res.AssetManager; +import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Rect; import android.util.DisplayMetrics; @@ -164,8 +165,14 @@ public class DoricUtils { Display display = manager.getDefaultDisplay(); if (display != null) { display.getMetrics(dm); - sScreenWidthPixels = dm.widthPixels; - sScreenHeightPixels = dm.heightPixels; + int orientation = context.getResources().getConfiguration().orientation; + if (orientation == Configuration.ORIENTATION_PORTRAIT) { + sScreenWidthPixels = dm.widthPixels; + sScreenHeightPixels = dm.heightPixels; + } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + sScreenWidthPixels = dm.heightPixels; + sScreenHeightPixels = dm.widthPixels; + } } return sScreenWidthPixels; } @@ -187,8 +194,14 @@ public class DoricUtils { Display display = manager.getDefaultDisplay(); if (display != null) { display.getMetrics(dm); - sScreenWidthPixels = dm.widthPixels; - sScreenHeightPixels = dm.heightPixels; + int orientation = context.getResources().getConfiguration().orientation; + if (orientation == Configuration.ORIENTATION_PORTRAIT) { + sScreenWidthPixels = dm.widthPixels; + sScreenHeightPixels = dm.heightPixels; + } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { + sScreenWidthPixels = dm.heightPixels; + sScreenHeightPixels = dm.widthPixels; + } } return sScreenHeightPixels; }