Merge "Change on/off values for Force Bold Text"

This commit is contained in:
Sally Yuen
2020-11-16 16:55:48 +00:00
committed by Android (Google) Code Review
3 changed files with 22 additions and 23 deletions

View File

@@ -90,7 +90,7 @@
android:key="toggle_force_bold_text" android:key="toggle_force_bold_text"
android:persistent="false" android:persistent="false"
android:title="@string/force_bold_text" android:title="@string/force_bold_text"
settings:controller="com.android.settings.accessibility.ForceBoldTextPreferenceController"/> settings:controller="com.android.settings.accessibility.FontWeightAdjustmentPreferenceController"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory

View File

@@ -17,15 +17,17 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration; import android.graphics.fonts.FontStyle;
import android.provider.Settings; import android.provider.Settings;
import com.android.settings.core.TogglePreferenceController; import com.android.settings.core.TogglePreferenceController;
/** PreferenceController for displaying all text in bold. */ /** PreferenceController for displaying all text in bold. */
public class ForceBoldTextPreferenceController extends TogglePreferenceController { public class FontWeightAdjustmentPreferenceController extends TogglePreferenceController {
static final int BOLD_TEXT_ADJUSTMENT =
FontStyle.FONT_WEIGHT_BOLD - FontStyle.FONT_WEIGHT_NORMAL;
public ForceBoldTextPreferenceController(Context context, String preferenceKey) { public FontWeightAdjustmentPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey); super(context, preferenceKey);
} }
@@ -37,14 +39,12 @@ public class ForceBoldTextPreferenceController extends TogglePreferenceControlle
@Override @Override
public boolean isChecked() { public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(), return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.FORCE_BOLD_TEXT, Configuration.FORCE_BOLD_TEXT_NO) Settings.Secure.FONT_WEIGHT_ADJUSTMENT, 0) == BOLD_TEXT_ADJUSTMENT;
== Configuration.FORCE_BOLD_TEXT_YES;
} }
@Override @Override
public boolean setChecked(boolean isChecked) { public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(), return Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.FORCE_BOLD_TEXT, Settings.Secure.FONT_WEIGHT_ADJUSTMENT, (isChecked ? BOLD_TEXT_ADJUSTMENT : 0));
(isChecked ? Configuration.FORCE_BOLD_TEXT_YES : Configuration.FORCE_BOLD_TEXT_NO));
} }
} }

View File

@@ -32,20 +32,20 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment; import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
public class ForceBoldTextPreferenceControllerTest { public class FontWeightAdjustmentPreferenceControllerTest {
private static final int ON = 2; private static final int ON = FontWeightAdjustmentPreferenceController.BOLD_TEXT_ADJUSTMENT;
private static final int OFF = 1; private static final int OFF = 0;
private static final int UNKNOWN = 0;
private Context mContext; private Context mContext;
private SwitchPreference mPreference; private SwitchPreference mPreference;
private ForceBoldTextPreferenceController mController; private FontWeightAdjustmentPreferenceController mController;
@Before @Before
public void setUp() { public void setUp() {
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mPreference = new SwitchPreference(mContext); mPreference = new SwitchPreference(mContext);
mController = new ForceBoldTextPreferenceController(mContext, "force_bold_text"); mController = new FontWeightAdjustmentPreferenceController(
mContext, "font_weight_adjustment");
} }
@Test @Test
@@ -55,9 +55,9 @@ public class ForceBoldTextPreferenceControllerTest {
} }
@Test @Test
public void isChecked_enabledTextContrast_shouldReturnTrue() { public void isChecked_enabledBoldText_shouldReturnTrue() {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.FORCE_BOLD_TEXT, ON); Settings.Secure.FONT_WEIGHT_ADJUSTMENT, ON);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -66,9 +66,9 @@ public class ForceBoldTextPreferenceControllerTest {
} }
@Test @Test
public void isChecked_disabledTextContrast_shouldReturnFalse() { public void isChecked_disabledBoldText_shouldReturnFalse() {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.FORCE_BOLD_TEXT, OFF); Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -77,19 +77,18 @@ public class ForceBoldTextPreferenceControllerTest {
} }
@Test @Test
public void setChecked_setTrue_shouldEnableTextContrast() { public void setChecked_setTrue_shouldEnableBoldText() {
mController.setChecked(true); mController.setChecked(true);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(), assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.FORCE_BOLD_TEXT, UNKNOWN)).isEqualTo(ON); Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(ON);
} }
@Test @Test
public void setChecked_setFalse_shouldDisableTextContrast() { public void setChecked_setFalse_shouldDisableBoldText() {
mController.setChecked(false); mController.setChecked(false);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(), assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.FORCE_BOLD_TEXT, UNKNOWN)).isEqualTo(OFF); Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(OFF);
} }
} }