Skip to content

Commit

Permalink
fix(android): add custom display metrics (Tencent#3965)
Browse files Browse the repository at this point in the history
Co-authored-by: maxli <[email protected]>
Co-authored-by: OpenHippy <[email protected]>
  • Loading branch information
3 people committed Aug 6, 2024
1 parent 7ca089c commit 0fe0be4
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 0fe0be4

Please sign in to comment.