New feature “Text and reading options” for SetupWizard, Wallpaper, and Settings (14/n).

- Link-up between the ResetPreference and the FontWeightAdjustmentPreference.

Bug: 211503117
Test: atest FontWeightAdjustmentPreferenceControllerTest
Change-Id: Iabf585660ff2c67f063198391bd68724190ba54d
This commit is contained in:
Peter_Liang
2022-02-06 23:31:27 +08:00
parent f71050b515
commit 618508c0c4
4 changed files with 26 additions and 3 deletions

View File

@@ -49,8 +49,7 @@
android:key="toggle_force_bold_text"
android:persistent="false"
android:title="@string/force_bold_text"
settings:keywords="@string/keywords_bold_text"
settings:controller="com.android.settings.accessibility.FontWeightAdjustmentPreferenceController"/>
settings:keywords="@string/keywords_bold_text" />
<SwitchPreference
android:key="toggle_high_text_contrast_preference"

View File

@@ -24,7 +24,8 @@ import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
/** PreferenceController for displaying all text in bold. */
public class FontWeightAdjustmentPreferenceController extends TogglePreferenceController {
public class FontWeightAdjustmentPreferenceController extends TogglePreferenceController implements
TextReadingResetController.ResetStateListener {
static final int BOLD_TEXT_ADJUSTMENT =
FontStyle.FONT_WEIGHT_BOLD - FontStyle.FONT_WEIGHT_NORMAL;
@@ -53,4 +54,9 @@ public class FontWeightAdjustmentPreferenceController extends TogglePreferenceCo
public int getSliceHighlightMenuRes() {
return R.string.menu_key_accessibility;
}
@Override
public void resetState() {
setChecked(false);
}
}

View File

@@ -42,6 +42,7 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
private static final String DISPLAY_SIZE_KEY = "display_size";
private static final String PREVIEW_KEY = "preview";
private static final String RESET_KEY = "reset";
private static final String BOLD_TEXT_KEY = "toggle_force_bold_text";
@Override
protected int getPreferenceScreenResId() {
@@ -78,6 +79,10 @@ public class TextReadingPreferenceFragment extends DashboardFragment {
displaySizeController.setInteractionListener(previewController);
controllers.add(displaySizeController);
final FontWeightAdjustmentPreferenceController fontWeightController =
new FontWeightAdjustmentPreferenceController(context, BOLD_TEXT_KEY);
controllers.add(fontWeightController);
final List<ResetStateListener> resetStateListeners =
controllers.stream().filter(c -> c instanceof ResetStateListener).map(
c -> (ResetStateListener) c).collect(Collectors.toList());

View File

@@ -31,6 +31,9 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests for {@link FontWeightAdjustmentPreferenceController}.
*/
@RunWith(AndroidJUnit4.class)
public class FontWeightAdjustmentPreferenceControllerTest {
private static final int ON = FontWeightAdjustmentPreferenceController.BOLD_TEXT_ADJUSTMENT;
@@ -91,4 +94,14 @@ public class FontWeightAdjustmentPreferenceControllerTest {
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(OFF);
}
@Test
public void resetState_shouldDisableBoldText() {
mController.setChecked(true);
mController.resetState();
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(OFF);
}
}