From c64189b0c424689d876ed5fcefcc1943077822d7 Mon Sep 17 00:00:00 2001 From: Tyler Freeman Date: Thu, 19 Jan 2023 15:54:51 -0800 Subject: [PATCH] docs(non linear font scaling): deprecate TypedValue.scaledDensity and add warning on Configuration.fontScale These fields are no longer useful for calculating font size, since font size is now derived using a non-linear curve. There is no reason anyone should need to use TypedValue.scaledDensity, so that is deprecated. However, it still could be useful to know the user's font scaling preference for other reasons (e.g. choosing a different layout that fits larger font sizes better), so we leave that one intact, but with a warning clarifying it should not be used in hardcoded equations. Bug: b/237558231 Test: nope Change-Id: I5f61492025d1ac66aee302ca0790cebc422d4f55 --- core/api/current.txt | 2 +- core/java/android/content/res/Configuration.java | 8 ++++++++ core/java/android/util/DisplayMetrics.java | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/api/current.txt b/core/api/current.txt index 653dda3d721fb..e229e2206ee78 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -48613,7 +48613,7 @@ package android.util { field public float density; field public int densityDpi; field public int heightPixels; - field public float scaledDensity; + field @Deprecated public float scaledDensity; field public int widthPixels; field public float xdpi; field public float ydpi; diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java index 0def59f36d80f..335975bae3935 100644 --- a/core/java/android/content/res/Configuration.java +++ b/core/java/android/content/res/Configuration.java @@ -98,6 +98,14 @@ public final class Configuration implements Parcelable, ComparableNote: Please do not use this to hardcode font size equations. The equation for font + * scaling is now non-linear; this coefficient is no longer used as a direct multiplier to + * determine font size. It exists for informational purposes only. + * + *

Please use {@link android.util.TypedValue#applyDimension(int, float, DisplayMetrics)} or + * {@link android.util.TypedValue#deriveDimension(int, float, DisplayMetrics)} to convert + * between scaled font size dimensions and pixels. */ public float fontScale; diff --git a/core/java/android/util/DisplayMetrics.java b/core/java/android/util/DisplayMetrics.java index 101a0714bbf42..25ee6aff6ac4c 100755 --- a/core/java/android/util/DisplayMetrics.java +++ b/core/java/android/util/DisplayMetrics.java @@ -283,7 +283,13 @@ public class DisplayMetrics { * A scaling factor for fonts displayed on the display. This is the same * as {@link #density}, except that it may be adjusted in smaller * increments at runtime based on a user preference for the font size. + * + * @deprecated this scalar factor is no longer accurate due to adaptive non-linear font scaling. + * Please use {@link TypedValue#applyDimension(int, float, DisplayMetrics)} or + * {@link TypedValue#deriveDimension(int, float, DisplayMetrics)} to convert between SP font + * sizes and pixels. */ + @Deprecated public float scaledDensity; /**