Skip to content

Commit f32a663

Browse files
Improve Java code
* call `context.getResources().getDisplayMetrics()` once * build `maui.aar`
1 parent 12d9c14 commit f32a663

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Core/AndroidNative/maui/src/main/java/com/microsoft/maui/PlatformInterop.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.os.Build;
2020
import android.text.Editable;
2121
import android.text.InputFilter;
22+
import android.util.DisplayMetrics;
2223
import android.util.TypedValue;
2324
import android.view.Gravity;
2425
import android.view.View;
@@ -598,13 +599,17 @@ public static Rect getCurrentWindowMetrics(Activity activity) {
598599
* @return FontMetrics object or null if context or display metrics is null
599600
*/
600601
public static Paint.FontMetrics getFontMetrics(Context context, double defaultFontSize) {
601-
if (context != null && context.getResources().getDisplayMetrics() != null) {
602+
if (context == null)
603+
return null;
604+
605+
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
606+
if (metrics != null) {
602607
return new Paint() {{
603608
setTextSize(
604609
TypedValue.applyDimension(
605610
TypedValue.COMPLEX_UNIT_SP,
606611
(float) defaultFontSize,
607-
context.getResources().getDisplayMetrics()
612+
metrics
608613
));
609614
}}.getFontMetrics();
610615
} else {

src/Core/src/maui.aar

821 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)