From 76890b34290125041494f4bd9b5e68bc49528d46 Mon Sep 17 00:00:00 2001 From: maxli Date: Tue, 23 Jul 2024 11:57:08 +0800 Subject: [PATCH] fix(android): add custom display metrics --- .../tencent/mtt/hippy/utils/DimensionsUtil.java | 2 +- .../com/tencent/mtt/hippy/utils/PixelUtil.java | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 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 d2c60f438f2..c60c1505476 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 @@ -173,7 +173,7 @@ public static HippyMap getDimensions(int ww, int wh, Context context) { if (context == null) { return null; } - DisplayMetrics windowDisplayMetrics = PixelUtil.getMetrics(); + DisplayMetrics windowDisplayMetrics = PixelUtil.getCustomDisplayMetrics(); if (windowDisplayMetrics == null) { windowDisplayMetrics = context.getResources().getDisplayMetrics(); } 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 79db244b180..3141b06fb57 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 @@ -21,12 +21,18 @@ import android.util.TypedValue; import android.view.Display; import android.view.WindowManager; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; public class PixelUtil { private static DisplayMetrics sDisplayMetrics = null; + private static DisplayMetrics sCustomDisplayMetrics = null; public static DisplayMetrics getMetrics() { + if (sCustomDisplayMetrics != null) { + return sCustomDisplayMetrics; + } if (sDisplayMetrics == null) { sDisplayMetrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) ContextHolder.getAppContext() @@ -37,12 +43,17 @@ public static DisplayMetrics getMetrics() { return sDisplayMetrics; } + @Nullable + public static DisplayMetrics getCustomDisplayMetrics() { + return sCustomDisplayMetrics; + } + /** * Set display metrics, call by host app */ @SuppressWarnings("unused") - public static void setDisplayMetrics(DisplayMetrics metrics) { - sDisplayMetrics = metrics; + public static void setDisplayMetrics(@NonNull DisplayMetrics metrics) { + sCustomDisplayMetrics = metrics; } /**