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

Commit 80c5b8ff authored by Sally Yuen's avatar Sally Yuen Committed by Android (Google) Code Review
Browse files

Merge "Add Bold Text to Accessibility settings screen"

parents 2927d0b9 904a8fa3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2970,6 +2970,8 @@
    <string name="doze_always_on_title">Always show time and info</string>
    <!-- [CHAR LIMIT=NONE] Display settings screen, setting description for the always-on ambient display feature. -->
    <string name="doze_always_on_summary">Increased battery usage</string>
    <!-- [CHAR LIMIT=30] Display and accessibility settings screens, setting option name to force bold text. -->
    <string name="force_bold_text">Bold Text</string>
    <!-- [CHAR LIMIT=30] Sound & display settings screen, setting option name to change font size -->
    <string name="title_font_size">Font size</string>
    <!-- Summary for Font size. Lets the user know that this will make text larger or smaller. Appears in the accessibility portion of setup wizard. [CHAR LIMIT=NONE] -->
+5 −0
Original line number Diff line number Diff line
@@ -86,6 +86,11 @@
            android:title="@string/accessibility_disable_animations"
            settings:controller="com.android.settings.accessibility.DisableAnimationsPreferenceController"/>

        <SwitchPreference
            android:key="toggle_force_bold_text"
            android:persistent="false"
            android:title="@string/force_bold_text"
            settings:controller="com.android.settings.accessibility.ForceBoldTextPreferenceController"/>
    </PreferenceCategory>

    <PreferenceCategory
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.accessibility;

import android.content.Context;
import android.content.res.Configuration;
import android.provider.Settings;

import com.android.settings.core.TogglePreferenceController;

/** PreferenceController for displaying all text in bold. */
public class ForceBoldTextPreferenceController extends TogglePreferenceController {

    public ForceBoldTextPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
    }

    @Override
    public int getAvailabilityStatus() {
        return AVAILABLE;
    }

    @Override
    public boolean isChecked() {
        return Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.FORCE_BOLD_TEXT, Configuration.FORCE_BOLD_TEXT_NO)
                == Configuration.FORCE_BOLD_TEXT_YES;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        return Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.FORCE_BOLD_TEXT,
                (isChecked ? Configuration.FORCE_BOLD_TEXT_YES : Configuration.FORCE_BOLD_TEXT_NO));
    }
}
+95 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.accessibility;

import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import android.provider.Settings;

import androidx.preference.SwitchPreference;

import com.android.settings.core.BasePreferenceController;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

@RunWith(RobolectricTestRunner.class)
public class ForceBoldTextPreferenceControllerTest {
    private static final int ON = 2;
    private static final int OFF = 1;
    private static final int UNKNOWN = 0;

    private Context mContext;
    private SwitchPreference mPreference;
    private ForceBoldTextPreferenceController mController;

    @Before
    public void setUp() {
        mContext = RuntimeEnvironment.application;
        mPreference = new SwitchPreference(mContext);
        mController = new ForceBoldTextPreferenceController(mContext, "force_bold_text");
    }

    @Test
    public void getAvailabilityStatus_byDefault_shouldReturnAvailable() {
        assertThat(mController.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.AVAILABLE);
    }

    @Test
    public void isChecked_enabledTextContrast_shouldReturnTrue() {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.FORCE_BOLD_TEXT, ON);

        mController.updateState(mPreference);

        assertThat(mController.isChecked()).isTrue();
        assertThat(mPreference.isChecked()).isTrue();
    }

    @Test
    public void isChecked_disabledTextContrast_shouldReturnFalse() {
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.FORCE_BOLD_TEXT, OFF);

        mController.updateState(mPreference);

        assertThat(mController.isChecked()).isFalse();
        assertThat(mPreference.isChecked()).isFalse();
    }

    @Test
    public void setChecked_setTrue_shouldEnableTextContrast() {
        mController.setChecked(true);

        assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.FORCE_BOLD_TEXT, UNKNOWN)).isEqualTo(ON);

    }

    @Test
    public void setChecked_setFalse_shouldDisableTextContrast() {
        mController.setChecked(false);

        assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.FORCE_BOLD_TEXT, UNKNOWN)).isEqualTo(OFF);
    }
}