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

Commit 60b08814 authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "[2/n] Add configurable font_scale" into main

parents 50cd1567 fa28ce36
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -56,6 +56,16 @@ public class FontScaleConverterFactory {
        // These were generated by frameworks/base/tools/fonts/font-scaling-array-generator.js and
        // These were generated by frameworks/base/tools/fonts/font-scaling-array-generator.js and
        // manually tweaked for optimum readability.
        // manually tweaked for optimum readability.
        synchronized (LOOKUP_TABLES_WRITE_LOCK) {
        synchronized (LOOKUP_TABLES_WRITE_LOCK) {
            putInto(
                    sLookupTables,
                    /* scaleKey= */ 1.1f,
                    new FontScaleConverterImpl(
                            /* fromSp= */
                            new float[] {   8f,   10f,   12f,   14f,   18f,   20f,   24f,   30f,  100},
                            /* toDp=   */
                            new float[] { 8.8f,   11f, 13.2f, 15.6f, 19.2f, 21.2f, 24.8f,   30f,  100})
            );

            putInto(
            putInto(
                    sLookupTables,
                    sLookupTables,
                    /* scaleKey= */ 1.15f,
                    /* scaleKey= */ 1.15f,
+19 −2
Original line number Original line Diff line number Diff line
@@ -4513,10 +4513,11 @@ public final class Settings {
        /** @hide */
        /** @hide */
        public static void adjustConfigurationForUser(ContentResolver cr, Configuration outConfig,
        public static void adjustConfigurationForUser(ContentResolver cr, Configuration outConfig,
                int userHandle, boolean updateSettingsIfEmpty) {
                int userHandle, boolean updateSettingsIfEmpty) {
            final float defaultFontScale = getDefaultFontScale(cr, userHandle);
            outConfig.fontScale = Settings.System.getFloatForUser(
            outConfig.fontScale = Settings.System.getFloatForUser(
                    cr, FONT_SCALE, DEFAULT_FONT_SCALE, userHandle);
                    cr, FONT_SCALE, defaultFontScale, userHandle);
            if (outConfig.fontScale < 0) {
            if (outConfig.fontScale < 0) {
                outConfig.fontScale = DEFAULT_FONT_SCALE;
                outConfig.fontScale = defaultFontScale;
            }
            }
            outConfig.fontWeightAdjustment = Settings.Secure.getIntForUser(
            outConfig.fontWeightAdjustment = Settings.Secure.getIntForUser(
                    cr, Settings.Secure.FONT_WEIGHT_ADJUSTMENT, DEFAULT_FONT_WEIGHT, userHandle);
                    cr, Settings.Secure.FONT_WEIGHT_ADJUSTMENT, DEFAULT_FONT_WEIGHT, userHandle);
@@ -4541,6 +4542,12 @@ public final class Settings {
            }
            }
        }
        }
        private static float getDefaultFontScale(ContentResolver cr, int userHandle) {
            return com.android.window.flags.Flags.configurableFontScaleDefault()
                    ? Settings.System.getFloatForUser(cr, DEFAULT_DEVICE_FONT_SCALE,
                    DEFAULT_FONT_SCALE, userHandle) : DEFAULT_FONT_SCALE;
        }
        /**
        /**
         * @hide Erase the fields in the Configuration that should be applied
         * @hide Erase the fields in the Configuration that should be applied
         * by the settings.
         * by the settings.
@@ -4906,6 +4913,15 @@ public final class Settings {
        @Readable
        @Readable
        public static final String FONT_SCALE = "font_scale";
        public static final String FONT_SCALE = "font_scale";
        /**
         * Default scaling factor for fonts for the specific device, float.
         * The value is read from the {@link R.dimen.def_device_font_scale}
         * configuration property.
         *
         * @hide
         */
        public static final String DEFAULT_DEVICE_FONT_SCALE = "device_font_scale";
        /**
        /**
         * The serialized system locale value.
         * The serialized system locale value.
         *
         *
@@ -6245,6 +6261,7 @@ public final class Settings {
            PRIVATE_SETTINGS.add(CAMERA_FLASH_NOTIFICATION);
            PRIVATE_SETTINGS.add(CAMERA_FLASH_NOTIFICATION);
            PRIVATE_SETTINGS.add(SCREEN_FLASH_NOTIFICATION);
            PRIVATE_SETTINGS.add(SCREEN_FLASH_NOTIFICATION);
            PRIVATE_SETTINGS.add(SCREEN_FLASH_NOTIFICATION_COLOR);
            PRIVATE_SETTINGS.add(SCREEN_FLASH_NOTIFICATION_COLOR);
            PRIVATE_SETTINGS.add(DEFAULT_DEVICE_FONT_SCALE);
        }
        }
        /**
        /**
+1 −2
Original line number Original line Diff line number Diff line
@@ -145,7 +145,6 @@ class FontScaleConverterFactoryTest {
    fun unnecessaryFontScalesReturnsNull() {
    fun unnecessaryFontScalesReturnsNull() {
        assertThat(FontScaleConverterFactory.forScale(0F)).isNull()
        assertThat(FontScaleConverterFactory.forScale(0F)).isNull()
        assertThat(FontScaleConverterFactory.forScale(1F)).isNull()
        assertThat(FontScaleConverterFactory.forScale(1F)).isNull()
        assertThat(FontScaleConverterFactory.forScale(1.1F)).isNull()
        assertThat(FontScaleConverterFactory.forScale(0.85F)).isNull()
        assertThat(FontScaleConverterFactory.forScale(0.85F)).isNull()
    }
    }


@@ -176,7 +175,7 @@ class FontScaleConverterFactoryTest {
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(-1f)).isFalse()
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(-1f)).isFalse()
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(0.85f)).isFalse()
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(0.85f)).isFalse()
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(1.02f)).isFalse()
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(1.02f)).isFalse()
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(1.10f)).isFalse()
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(1.10f)).isTrue()
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(1.15f)).isTrue()
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(1.15f)).isTrue()
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(1.1499999f))
        assertThat(FontScaleConverterFactory.isNonLinearFontScalingActive(1.1499999f))
                .isTrue()
                .isTrue()
+3 −0
Original line number Original line Diff line number Diff line
@@ -335,4 +335,7 @@
    <!-- Default for Settings.BATTERY_CHARGING_STATE_ENFORCE_LEVEL.
    <!-- Default for Settings.BATTERY_CHARGING_STATE_ENFORCE_LEVEL.
        -1 means system internal default value is used. -->
        -1 means system internal default value is used. -->
    <integer name="def_battery_charging_state_enforce_level">-1</integer>
    <integer name="def_battery_charging_state_enforce_level">-1</integer>

    <!-- Value to use as default scale for fonts -->
    <item name="def_device_font_scale" format="float" type="dimen">1.0</item>
</resources>
</resources>
+1 −0
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ public class SystemSettings {
                Settings.System.WIFI_STATIC_DNS2,
                Settings.System.WIFI_STATIC_DNS2,
                Settings.System.BLUETOOTH_DISCOVERABILITY,
                Settings.System.BLUETOOTH_DISCOVERABILITY,
                Settings.System.BLUETOOTH_DISCOVERABILITY_TIMEOUT,
                Settings.System.BLUETOOTH_DISCOVERABILITY_TIMEOUT,
                Settings.System.DEFAULT_DEVICE_FONT_SCALE,
                Settings.System.FONT_SCALE,
                Settings.System.FONT_SCALE,
                Settings.System.DIM_SCREEN,
                Settings.System.DIM_SCREEN,
                Settings.System.SCREEN_OFF_TIMEOUT,
                Settings.System.SCREEN_OFF_TIMEOUT,
Loading