Add ability to show/hide Color Correction and Color Inversion.

This adds two new boolean flags:
config_show_color_inversion_preference
config_show_color_correction_preference

Which whent set to false, will hide the color inversion and color
correction preference items, respectively.

Bug: 62378109
Test: make RunSettingsRoboTests
ROBOTEST_FILTER=AccessibilitySettingsTest

Change-Id: I06eac8e141bd6564495298c6c6544a7b059a4e73
This commit is contained in:
Ben Lin
2017-12-18 15:46:44 -08:00
parent b1f6f24dcc
commit f1346930bc
4 changed files with 73 additions and 4 deletions

View File

@@ -99,6 +99,12 @@
<!-- Whether default_home should be shown or not. -->
<bool name="config_show_default_home">true</bool>
<!-- Whether color correction preference should be shown or not. -->
<bool name="config_show_color_correction_preference">true</bool>
<!-- Whether color inversion preference should be shown or not. -->
<bool name="config_show_color_inversion_preference">true</bool>
<!-- Whether accessibility shortcut preference should be shown or not. -->
<bool name="config_show_accessibility_shortcut_preference">true</bool>

View File

@@ -90,8 +90,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
// Preferences
private static final String TOGGLE_HIGH_TEXT_CONTRAST_PREFERENCE =
"toggle_high_text_contrast_preference";
private static final String TOGGLE_INVERSION_PREFERENCE =
"toggle_inversion_preference";
private static final String TOGGLE_POWER_BUTTON_ENDS_CALL_PREFERENCE =
"toggle_power_button_ends_call_preference";
private static final String TOGGLE_LOCK_SCREEN_ROTATION_PREFERENCE =
@@ -113,9 +111,11 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
"tts_settings_preference";
private static final String AUTOCLICK_PREFERENCE_SCREEN =
"autoclick_preference_screen";
private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
"daltonizer_preference_screen";
@VisibleForTesting static final String TOGGLE_INVERSION_PREFERENCE =
"toggle_inversion_preference";
@VisibleForTesting static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
"daltonizer_preference_screen";
@VisibleForTesting static final String ACCESSIBILITY_SHORTCUT_PREFERENCE =
"accessibility_shortcut_preference";
@@ -619,6 +619,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
displayCategory.addPreference(mToggleInversionPreference);
displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
}
checkColorCorrectionVisibility(mDisplayDaltonizerPreferenceScreen);
checkColorInversionVisibility(mToggleInversionPreference);
// Text contrast.
mToggleHighTextContrastPreference.setChecked(
@@ -769,6 +771,20 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
}
}
@VisibleForTesting void checkColorCorrectionVisibility(Preference preference) {
if (!getContext().getResources().getBoolean(
R.bool.config_show_color_correction_preference)) {
removePreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
}
}
@VisibleForTesting void checkColorInversionVisibility(Preference preference) {
if (!getContext().getResources().getBoolean(
R.bool.config_show_color_inversion_preference)) {
removePreference(TOGGLE_INVERSION_PREFERENCE);
}
}
@VisibleForTesting void checkAccessibilityShortcutVisibility(Preference preference) {
if (!getContext().getResources().getBoolean(
R.bool.config_show_accessibility_shortcut_preference)) {

View File

@@ -37,4 +37,6 @@
<bool name="config_show_tts_settings_summary">false</bool>
<bool name="config_show_pointer_speed">false</bool>
<bool name="config_show_vibrate_input_devices">false</bool>
<bool name="config_show_color_correction_preference">false</bool>
<bool name="config_show_color_inversion_preference">false</bool>
</resources>

View File

@@ -45,6 +45,8 @@ public class AccessibilitySettingsTest {
private Context mContext;
private AccessibilitySettings mFragment;
private boolean mAccessibilityShortcutPreferenceRemoved;
private boolean mColorInversionPreferenceRemoved;
private boolean mColorCorrectionPreferenceRemoved;
@Before
public void setUp() {
@@ -60,7 +62,16 @@ public class AccessibilitySettingsTest {
protected boolean removePreference(String key) {
if (AccessibilitySettings.ACCESSIBILITY_SHORTCUT_PREFERENCE.equals(key)) {
mAccessibilityShortcutPreferenceRemoved = true;
return true;
}
if (AccessibilitySettings.TOGGLE_INVERSION_PREFERENCE.equals(key)) {
mColorInversionPreferenceRemoved = true;
return true;
}
if (AccessibilitySettings.DISPLAY_DALTONIZER_PREFERENCE_SCREEN.equals(key)) {
mColorCorrectionPreferenceRemoved = true;
return true;
}
return false;
@@ -104,4 +115,38 @@ public class AccessibilitySettingsTest {
assertThat(niks).contains(AccessibilitySettings.ACCESSIBILITY_SHORTCUT_PREFERENCE);
}
@Test
public void testColorInversionPreference_byDefault_shouldBeShown() {
final Preference preference = new Preference(mContext);
mFragment.checkColorInversionVisibility(preference);
assertThat(mColorInversionPreferenceRemoved).isEqualTo(false);
}
@Test
@Config(qualifiers = "mcc999")
public void testColorInversionPreference_ifDisabled_shouldNotBeShown() {
final Preference preference = new Preference(mContext);
mFragment.checkColorInversionVisibility(preference);
assertThat(mColorInversionPreferenceRemoved).isEqualTo(true);
}
@Test
public void testColorCorrectionPreference_byDefault_shouldBeShown() {
final Preference preference = new Preference(mContext);
mFragment.checkColorCorrectionVisibility(preference);
assertThat(mColorCorrectionPreferenceRemoved).isEqualTo(false);
}
@Test
@Config(qualifiers = "mcc999")
public void testColorCorrectionPreference_ifDisabled_shouldNotBeShown() {
final Preference preference = new Preference(mContext);
mFragment.checkColorCorrectionVisibility(preference);
assertThat(mColorCorrectionPreferenceRemoved).isEqualTo(true);
}
}