Skip to content

Commit

Permalink
fix(android): add custom display metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 committed Jul 23, 2024
1 parent b5c2d1d commit 76890b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 76890b3

Please sign in to comment.