Loading core/api/current.txt +2 −5 Original line number Diff line number Diff line Loading @@ -13675,11 +13675,8 @@ package android.content.res { @FlaggedApi("android.content.res.font_scale_converter_public") public interface FontScaleConverter { method public float convertDpToSp(float); method public float convertSpToDp(float); } @FlaggedApi("android.content.res.font_scale_converter_public") public class FontScaleConverterFactory { method @FlaggedApi("android.content.res.font_scale_converter_public") @AnyThread @Nullable public static android.content.res.FontScaleConverter forScale(float); method @FlaggedApi("android.content.res.font_scale_converter_public") @AnyThread public static boolean isNonLinearFontScalingActive(float); method @AnyThread @Nullable public static android.content.res.FontScaleConverter forScale(float); method @AnyThread public static boolean isNonLinearFontScalingActive(float); } public class ObbInfo implements android.os.Parcelable { core/java/android/content/res/FontScaleConverter.java +33 −0 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ package android.content.res; import android.annotation.AnyThread; import android.annotation.FlaggedApi; import android.annotation.Nullable; /** * A converter for non-linear font scaling. Converts font sizes given in "sp" dimensions to a Loading @@ -40,4 +42,35 @@ public interface FontScaleConverter { * Converts a dimension in "dp" back to "sp". */ float convertDpToSp(float dp); /** * Returns true if non-linear font scaling curves would be in effect for the given scale, false * if the scaling would follow a linear curve or for no scaling. * * <p>Example usage: {@code * isNonLinearFontScalingActive(getResources().getConfiguration().fontScale)} */ @AnyThread static boolean isNonLinearFontScalingActive(float fontScale) { return FontScaleConverterFactory.isNonLinearFontScalingActive(fontScale); } /** * Finds a matching FontScaleConverter for the given fontScale factor. * * Generally you shouldn't need this; you can use {@link * android.util.TypedValue#applyDimension(int, float, DisplayMetrics)} directly and it will do * the scaling conversion for you. Dimens and resources loaded from XML will also be * automatically converted. But for UI frameworks or other situations where you need to do the * conversion without an Android Context, you can use this method. * * @param fontScale the scale factor, usually from {@link Configuration#fontScale}. * * @return a converter for the given scale, or null if non-linear scaling should not be used. */ @Nullable @AnyThread static FontScaleConverter forScale(float fontScale) { return FontScaleConverterFactory.forScale(fontScale); } } core/java/android/content/res/FontScaleConverterFactory.java +2 −4 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ package android.content.res; import android.annotation.AnyThread; import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.Nullable; import android.util.MathUtils; Loading @@ -32,8 +31,9 @@ import com.android.internal.annotations.VisibleForTesting; * android.util.TypedValue#applyDimension(int, float, DisplayMetrics)} directly and it will do the * scaling conversion for you. But for UI frameworks or other situations where you need to do the * conversion without an Android Context, you can use this class. * * @hide */ @FlaggedApi(Flags.FLAG_FONT_SCALE_CONVERTER_PUBLIC) public class FontScaleConverterFactory { private static final float SCALE_KEY_MULTIPLIER = 100f; Loading Loading @@ -124,7 +124,6 @@ public class FontScaleConverterFactory { * <p>Example usage: * <code>isNonLinearFontScalingActive(getResources().getConfiguration().fontScale)</code> */ @FlaggedApi(Flags.FLAG_FONT_SCALE_CONVERTER_PUBLIC) @AnyThread public static boolean isNonLinearFontScalingActive(float fontScale) { return fontScale >= sMinScaleBeforeCurvesApplied; Loading @@ -137,7 +136,6 @@ public class FontScaleConverterFactory { * * @return a converter for the given scale, or null if non-linear scaling should not be used. */ @FlaggedApi(Flags.FLAG_FONT_SCALE_CONVERTER_PUBLIC) @Nullable @AnyThread public static FontScaleConverter forScale(float fontScale) { Loading core/tests/coretests/src/android/content/res/FontScaleConverterFactoryTest.kt +4 −2 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ class FontScaleConverterFactoryTest { @get:Rule val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() private lateinit var defaultLookupTables: SparseArray<FontScaleConverter> private var defaultLookupTables: SparseArray<FontScaleConverter>? = null @Before fun setup() { Loading @@ -58,7 +58,9 @@ class FontScaleConverterFactoryTest { @After fun teardown() { // Restore the default tables (since some tests will have added extras to the cache) FontScaleConverterFactory.sLookupTables = defaultLookupTables if (defaultLookupTables != null) { FontScaleConverterFactory.sLookupTables = defaultLookupTables!! } } @Test Loading Loading
core/api/current.txt +2 −5 Original line number Diff line number Diff line Loading @@ -13675,11 +13675,8 @@ package android.content.res { @FlaggedApi("android.content.res.font_scale_converter_public") public interface FontScaleConverter { method public float convertDpToSp(float); method public float convertSpToDp(float); } @FlaggedApi("android.content.res.font_scale_converter_public") public class FontScaleConverterFactory { method @FlaggedApi("android.content.res.font_scale_converter_public") @AnyThread @Nullable public static android.content.res.FontScaleConverter forScale(float); method @FlaggedApi("android.content.res.font_scale_converter_public") @AnyThread public static boolean isNonLinearFontScalingActive(float); method @AnyThread @Nullable public static android.content.res.FontScaleConverter forScale(float); method @AnyThread public static boolean isNonLinearFontScalingActive(float); } public class ObbInfo implements android.os.Parcelable {
core/java/android/content/res/FontScaleConverter.java +33 −0 Original line number Diff line number Diff line Loading @@ -17,7 +17,9 @@ package android.content.res; import android.annotation.AnyThread; import android.annotation.FlaggedApi; import android.annotation.Nullable; /** * A converter for non-linear font scaling. Converts font sizes given in "sp" dimensions to a Loading @@ -40,4 +42,35 @@ public interface FontScaleConverter { * Converts a dimension in "dp" back to "sp". */ float convertDpToSp(float dp); /** * Returns true if non-linear font scaling curves would be in effect for the given scale, false * if the scaling would follow a linear curve or for no scaling. * * <p>Example usage: {@code * isNonLinearFontScalingActive(getResources().getConfiguration().fontScale)} */ @AnyThread static boolean isNonLinearFontScalingActive(float fontScale) { return FontScaleConverterFactory.isNonLinearFontScalingActive(fontScale); } /** * Finds a matching FontScaleConverter for the given fontScale factor. * * Generally you shouldn't need this; you can use {@link * android.util.TypedValue#applyDimension(int, float, DisplayMetrics)} directly and it will do * the scaling conversion for you. Dimens and resources loaded from XML will also be * automatically converted. But for UI frameworks or other situations where you need to do the * conversion without an Android Context, you can use this method. * * @param fontScale the scale factor, usually from {@link Configuration#fontScale}. * * @return a converter for the given scale, or null if non-linear scaling should not be used. */ @Nullable @AnyThread static FontScaleConverter forScale(float fontScale) { return FontScaleConverterFactory.forScale(fontScale); } }
core/java/android/content/res/FontScaleConverterFactory.java +2 −4 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ package android.content.res; import android.annotation.AnyThread; import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.Nullable; import android.util.MathUtils; Loading @@ -32,8 +31,9 @@ import com.android.internal.annotations.VisibleForTesting; * android.util.TypedValue#applyDimension(int, float, DisplayMetrics)} directly and it will do the * scaling conversion for you. But for UI frameworks or other situations where you need to do the * conversion without an Android Context, you can use this class. * * @hide */ @FlaggedApi(Flags.FLAG_FONT_SCALE_CONVERTER_PUBLIC) public class FontScaleConverterFactory { private static final float SCALE_KEY_MULTIPLIER = 100f; Loading Loading @@ -124,7 +124,6 @@ public class FontScaleConverterFactory { * <p>Example usage: * <code>isNonLinearFontScalingActive(getResources().getConfiguration().fontScale)</code> */ @FlaggedApi(Flags.FLAG_FONT_SCALE_CONVERTER_PUBLIC) @AnyThread public static boolean isNonLinearFontScalingActive(float fontScale) { return fontScale >= sMinScaleBeforeCurvesApplied; Loading @@ -137,7 +136,6 @@ public class FontScaleConverterFactory { * * @return a converter for the given scale, or null if non-linear scaling should not be used. */ @FlaggedApi(Flags.FLAG_FONT_SCALE_CONVERTER_PUBLIC) @Nullable @AnyThread public static FontScaleConverter forScale(float fontScale) { Loading
core/tests/coretests/src/android/content/res/FontScaleConverterFactoryTest.kt +4 −2 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ class FontScaleConverterFactoryTest { @get:Rule val checkFlagsRule: CheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule() private lateinit var defaultLookupTables: SparseArray<FontScaleConverter> private var defaultLookupTables: SparseArray<FontScaleConverter>? = null @Before fun setup() { Loading @@ -58,7 +58,9 @@ class FontScaleConverterFactoryTest { @After fun teardown() { // Restore the default tables (since some tests will have added extras to the cache) FontScaleConverterFactory.sLookupTables = defaultLookupTables if (defaultLookupTables != null) { FontScaleConverterFactory.sLookupTables = defaultLookupTables!! } } @Test Loading