Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 007cee95 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "fix(non linear font scaling): move factory APIs into FontScaleConverter interface" into main

parents 63e18c96 2d05430b
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -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 {
+33 −0
Original line number Diff line number Diff line
@@ -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
@@ -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);
    }
}
+2 −4
Original line number Diff line number Diff line
@@ -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;
@@ -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;

@@ -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;
@@ -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) {
+4 −2
Original line number Diff line number Diff line
@@ -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() {
@@ -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