From 7116703d0e35ec24563c1c3a42ccf6b270c96844 Mon Sep 17 00:00:00 2001 From: maxli Date: Fri, 26 Apr 2024 14:56:12 +0800 Subject: [PATCH] fix(android): support use custom DisplayMetrics --- .../java/com/tencent/mtt/hippy/utils/DimensionsUtil.java | 5 ++++- .../src/main/java/com/tencent/mtt/hippy/utils/PixelUtil.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/DimensionsUtil.java b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/DimensionsUtil.java index 842e2eee872..22a6473dcd7 100644 --- a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/DimensionsUtil.java +++ b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/DimensionsUtil.java @@ -174,7 +174,10 @@ public static HippyMap getDimensions(int ww, int wh, Context context, if (context == null) { return null; } - DisplayMetrics windowDisplayMetrics = context.getResources().getDisplayMetrics(); + DisplayMetrics windowDisplayMetrics = PixelUtil.getMetrics(); + if (windowDisplayMetrics == null) { + windowDisplayMetrics = context.getResources().getDisplayMetrics(); + } DisplayMetrics screenDisplayMetrics = new DisplayMetrics(); screenDisplayMetrics.setTo(windowDisplayMetrics); WindowManager windowManager = (WindowManager) context diff --git a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/PixelUtil.java b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/PixelUtil.java index d2e9f249375..4bf17e1aee3 100644 --- a/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/PixelUtil.java +++ b/modules/android/hippy_support/src/main/java/com/tencent/mtt/hippy/utils/PixelUtil.java @@ -23,7 +23,7 @@ public class PixelUtil { private static DisplayMetrics sDisplayMetrics = null; - private static DisplayMetrics getMetrics() { + public static DisplayMetrics getMetrics() { if (sDisplayMetrics == null) { sDisplayMetrics = ContextHolder.getAppContext().getResources().getDisplayMetrics(); }