Add a setting page for Reduce Bright Colors under A11y

This is essentially a copy page of ToggleDaltonizerPreferenceFragment.
We extend ToggleFeaturePreferenceFragment to maintain consistency with
other shortcut assignable a11y feature.

UI is a draft

This CL:
1) allows users to enabled/disable RBC with the a11y shortcut (button,
gestures, volume keys), if assigned
2) adds a slider and persist switch to the template
ToggleFeaturePreferenceFragment page (which already contains a feature
switch, shortcut preference, and footer description)
3) enables/disables the intensity slider when RBC is on/off
4) sets placeholders for calling into ColorDisplayService in
controllers and tests
5) follows convention set by other color transformations settings and
places feature under Experimental section in A11y settings page if
transformations can't be efficiently performed by hardware

Test: A11y setting and page appears, tested activation with shortcut,
preference controller tests
Bug: b/128465252

Change-Id: I291bb86ce3d855ce052ca70dc7a941a888e2c723
This commit is contained in:
Sally
2020-10-14 18:46:17 +00:00
parent ac76152a6b
commit b9ff672a31
12 changed files with 633 additions and 0 deletions

View File

@@ -5239,6 +5239,18 @@
<!-- Summary shown for tritanomaly (blue-yellow color blindness) [CHAR LIMIT=45] --> <!-- Summary shown for tritanomaly (blue-yellow color blindness) [CHAR LIMIT=45] -->
<string name="daltonizer_mode_tritanomaly_summary">Blue-yellow</string> <string name="daltonizer_mode_tritanomaly_summary">Blue-yellow</string>
<!-- TODO(b/170970602): remove translatable=false when RBC has official name and strings -->
<!-- Title for the accessibility preference to configure Reduce Bright Colors feature. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_preference_title" translatable="false">Reduce Bright Colors</string>
<!-- Used in the accessibility service settings to control switching Reduce Bright Colors on/off. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_switch_title" translatable="false">Use Reduce Bright Colors</string>
<!-- Subtitle that describes Reduce Bright Colors. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_preference_subtitle" translatable="false">Reduce Bright Colors reduces screen brightness.</string>
<!-- Title for setting the brightness intensity of the display using Reduce Bright Colors. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_intensity_preference_title" translatable="false">Intensity</string>
<!-- Title for setting whether the Reduce Bright Colors activation state persists across reboots. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_persist_preference_title" translatable="false">Keeps feature on after a restart</string>
<!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] --> <!-- Subtitle for the accessibility preference to configure feature that performs click action soon after mouse/trackpad pointer stops moving, in case delay before click is extremely short. Placeholder will be set to the number of milliseconds to which the delay amounts. [CHAR LIMIT=NONE] -->
<plurals name="accessibilty_autoclick_preference_subtitle_short_delay"> <plurals name="accessibilty_autoclick_preference_subtitle_short_delay">
<item quantity="one">Short (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item> <item quantity="one">Short (<xliff:g id="click_delay_label" example="200">%1$s</xliff:g> second)</item>

View File

@@ -231,6 +231,14 @@
android:summary="@string/accessibility_shortcut_description" android:summary="@string/accessibility_shortcut_description"
settings:controller="com.android.settings.accessibility.AccessibilityShortcutPreferenceController"/> settings:controller="com.android.settings.accessibility.AccessibilityShortcutPreferenceController"/>
<!--TODO(b/170973645): Get icon-->
<Preference
android:fragment="com.android.settings.accessibility.ToggleReduceBrightColorsPreferenceFragment"
android:key="reduce_bright_colors_preference"
android:persistent="false"
android:title="@string/reduce_bright_colors_preference_title"
settings:controller="com.android.settings.accessibility.ReduceBrightColorsPreferenceController"/>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:persistent="false"
android:title="@string/reduce_bright_colors_preference_title">
<com.android.settings.widget.SeekBarPreference
android:key="rbc_intensity"
android:persistent="false"
android:title="@string/reduce_bright_colors_intensity_preference_title"/>
<SwitchPreference
android:key="rbc_persist"
android:persistent="false"
android:title="@string/reduce_bright_colors_persist_preference_title" />
</PreferenceScreen>

View File

@@ -97,6 +97,8 @@ public class AccessibilitySettings extends DashboardFragment {
"magnification_preference_screen"; "magnification_preference_screen";
private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN = private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
"daltonizer_preference"; "daltonizer_preference";
private static final String DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN =
"reduce_bright_colors_preference";
// Extras passed to sub-fragments. // Extras passed to sub-fragments.
static final String EXTRA_PREFERENCE_KEY = "preference_key"; static final String EXTRA_PREFERENCE_KEY = "preference_key";
@@ -170,6 +172,8 @@ public class AccessibilitySettings extends DashboardFragment {
private Preference mDisplayMagnificationPreferenceScreen; private Preference mDisplayMagnificationPreferenceScreen;
private Preference mDisplayDaltonizerPreferenceScreen; private Preference mDisplayDaltonizerPreferenceScreen;
private Preference mToggleInversionPreference; private Preference mToggleInversionPreference;
private Preference mReduceBrightColorsPreference;
/** /**
* Check if the color transforms are color accelerated. Some transforms are experimental only * Check if the color transforms are color accelerated. Some transforms are experimental only
@@ -335,6 +339,10 @@ public class AccessibilitySettings extends DashboardFragment {
// Display color adjustments. // Display color adjustments.
mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN); mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
// Reduce brightness.
mReduceBrightColorsPreference =
findPreference(DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN);
} }
private void updateAllPreferences() { private void updateAllPreferences() {
@@ -488,6 +496,7 @@ public class AccessibilitySettings extends DashboardFragment {
mCategoryToPrefCategoryMap.get(CATEGORY_DISPLAY); mCategoryToPrefCategoryMap.get(CATEGORY_DISPLAY);
experimentalCategory.removePreference(mToggleInversionPreference); experimentalCategory.removePreference(mToggleInversionPreference);
experimentalCategory.removePreference(mDisplayDaltonizerPreferenceScreen); experimentalCategory.removePreference(mDisplayDaltonizerPreferenceScreen);
experimentalCategory.removePreference(mReduceBrightColorsPreference);
mDisplayMagnificationPreferenceScreen.setSummary( mDisplayMagnificationPreferenceScreen.setSummary(
ToggleScreenMagnificationPreferenceFragment.getServiceSummary(getContext())); ToggleScreenMagnificationPreferenceFragment.getServiceSummary(getContext()));
mDisplayDaltonizerPreferenceScreen.setOrder( mDisplayDaltonizerPreferenceScreen.setOrder(
@@ -502,8 +511,13 @@ public class AccessibilitySettings extends DashboardFragment {
mToggleLargePointerIconPreference.getOrder() + 1); mToggleLargePointerIconPreference.getOrder() + 1);
mToggleInversionPreference.setSummary(AccessibilityUtil.getSummary( mToggleInversionPreference.setSummary(AccessibilityUtil.getSummary(
getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)); getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED));
mReduceBrightColorsPreference.setOrder(
mToggleDisableAnimationsPreference.getOrder() + 1);
mReduceBrightColorsPreference.setSummary(AccessibilityUtil.getSummary(
getContext(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED));
displayCategory.addPreference(mToggleInversionPreference); displayCategory.addPreference(mToggleInversionPreference);
displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen); displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
displayCategory.addPreference(mReduceBrightColorsPreference);
} }
} }

View File

@@ -0,0 +1,82 @@
/*
* 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.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.SliderPreferenceController;
import com.android.settings.widget.SeekBarPreference;
/** PreferenceController for feature intensity. */
public class ReduceBrightColorsIntensityPreferenceController extends SliderPreferenceController {
public ReduceBrightColorsIntensityPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
// TODO(b/170970675): Call into ColorDisplayService (CDS) to get availability/config status
return AVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
final SeekBarPreference preference = screen.findPreference(getPreferenceKey());
preference.setContinuousUpdates(true);
preference.setMax(getMax());
preference.setMin(getMin());
updateState(preference);
}
@Override
public final void updateState(Preference preference) {
super.updateState(preference);
preference.setEnabled(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0) == 1);
}
@Override
public int getSliderPosition() {
// TODO(b/170970675): Call into CDS to get intensity
return 0;
}
@Override
public boolean setSliderPosition(int position) {
// TODO(b/170970675): Call into CDS to set intensity
return true;
}
@Override
public int getMax() {
// TODO(b/170970675): Call into CDS to get config max intensity
return 100;
}
@Override
public int getMin() {
// TODO(b/170970675): Call into CDS to get config min intensity
return 0;
}
}

View File

@@ -0,0 +1,49 @@
/*
* 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.provider.Settings;
import com.android.settings.core.TogglePreferenceController;
/** PreferenceController for persisting feature activation state after a restart. */
public class ReduceBrightColorsPersistencePreferenceController extends TogglePreferenceController {
public ReduceBrightColorsPersistencePreferenceController(
Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
// TODO(b/170970675): call into CDS to get availability/config status
return AVAILABLE;
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.REDUCE_BRIGHT_COLORS_PERSIST_ACROSS_REBOOTS, 0) == 1;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.REDUCE_BRIGHT_COLORS_PERSIST_ACROSS_REBOOTS, (isChecked ? 1 : 0));
}
}

View File

@@ -0,0 +1,43 @@
/*
* 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.provider.Settings;
import com.android.settings.core.BasePreferenceController;
/** PreferenceController that shows the Reduce Bright Colors summary */
public class ReduceBrightColorsPreferenceController extends BasePreferenceController {
public ReduceBrightColorsPreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey);
}
@Override
public CharSequence getSummary() {
return AccessibilityUtil.getSummary(mContext,
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED);
}
@Override
public int getAvailabilityStatus() {
// TODO(b/170970675): call into CDS to get availability/config status
return AVAILABLE;
}
}

View File

@@ -0,0 +1,200 @@
/*
* 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.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.internal.accessibility.AccessibilityShortcutController;
import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.List;
/** Settings for reducing brightness. */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePreferenceFragment {
private static final String REDUCE_BRIGHT_COLORS_ACTIVATED_KEY =
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED;
private static final String KEY_INTENSITY = "rbc_intensity";
private static final String KEY_PERSIST = "rbc_persist";
private final Handler mHandler = new Handler();
private SettingsContentObserver mSettingsContentObserver;
private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController;
private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO(b/170973645): Add banner
mComponentName = AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_COMPONENT_NAME;
mPackageName = getText(R.string.reduce_bright_colors_preference_title);
mHtmlDescription = getText(R.string.reduce_bright_colors_preference_subtitle);
final List<String> enableServiceFeatureKeys = new ArrayList<>(/* initialCapacity= */ 1);
enableServiceFeatureKeys.add(REDUCE_BRIGHT_COLORS_ACTIVATED_KEY);
mRbcIntensityPreferenceController =
new ReduceBrightColorsIntensityPreferenceController(getContext(), KEY_INTENSITY);
mRbcPersistencePreferenceController =
new ReduceBrightColorsPersistencePreferenceController(getContext(), KEY_PERSIST);
mRbcIntensityPreferenceController.displayPreference(getPreferenceScreen());
mRbcPersistencePreferenceController.displayPreference(getPreferenceScreen());
mSettingsContentObserver = new SettingsContentObserver(mHandler, enableServiceFeatureKeys) {
@Override
public void onChange(boolean selfChange, Uri uri) {
updateSwitchBarToggleSwitch();
}
};
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
updatePreferenceOrder();
}
/** Customizes the order by preference key. */
private List<String> getPreferenceOrderList() {
final List<String> lists = new ArrayList<>();
lists.add(KEY_USE_SERVICE_PREFERENCE);
lists.add(KEY_INTENSITY);
lists.add(KEY_PERSIST);
lists.add(KEY_GENERAL_CATEGORY);
lists.add(KEY_INTRODUCTION_CATEGORY);
return lists;
}
private void updatePreferenceOrder() {
final List<String> lists = getPreferenceOrderList();
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.setOrderingAsAdded(false);
final int size = lists.size();
for (int i = 0; i < size; i++) {
final Preference preference = preferenceScreen.findPreference(lists.get(i));
if (preference != null) {
preference.setOrder(i);
}
}
}
@Override
public void onResume() {
super.onResume();
updateSwitchBarToggleSwitch();
mSettingsContentObserver.register(getContentResolver());
}
@Override
public void onPause() {
mSettingsContentObserver.unregister(getContentResolver());
super.onPause();
}
@Override
public int getMetricsCategory() {
return SettingsEnums.REDUCE_BRIGHT_COLORS_SETTINGS;
}
@Override
public int getHelpResource() {
// TODO(170973645): Link to help support page
return 0;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.reduce_bright_colors_settings;
}
@Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(mComponentName, enabled);
Settings.Secure.putInt(getContentResolver(),
REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, enabled ? ON : OFF);
}
@Override
protected void onRemoveSwitchPreferenceToggleSwitch() {
super.onRemoveSwitchPreferenceToggleSwitch();
mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(
/* onPreferenceClickListener= */ null);
}
@Override
protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
switchPreference.setTitle(R.string.reduce_bright_colors_switch_title);
}
@Override
protected void onInstallSwitchPreferenceToggleSwitch() {
super.onInstallSwitchPreferenceToggleSwitch();
updateSwitchBarToggleSwitch();
mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
boolean checked = ((SwitchPreference) preference).isChecked();
onPreferenceToggled(mPreferenceKey, checked);
return false;
});
}
@Override
int getUserShortcutTypes() {
return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
mComponentName);
}
private void updateSwitchBarToggleSwitch() {
final boolean checked = Settings.Secure.getInt(getContentResolver(),
REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, OFF) == ON;
mRbcIntensityPreferenceController.updateState(getPreferenceScreen()
.findPreference(KEY_INTENSITY));
mRbcPersistencePreferenceController.updateState(getPreferenceScreen()
.findPreference(KEY_PERSIST));
if (mToggleServiceDividerSwitchPreference.isChecked() != checked) {
mToggleServiceDividerSwitchPreference.setChecked(checked);
}
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.reduce_bright_colors_settings) {
@Override
protected boolean isPageSearchEnabled(Context context) {
// TODO(b/170970675): call into CDS to get availability/config status
return true;
}
};
}

View File

@@ -8,4 +8,6 @@ com.android.settings.testutils.FakeToggleController
com.android.settings.testutils.FakeSliderController com.android.settings.testutils.FakeSliderController
com.android.settings.testutils.FakeInvalidSliderController com.android.settings.testutils.FakeInvalidSliderController
com.android.settings.wifi.details2.WifiAutoConnectPreferenceController2 com.android.settings.wifi.details2.WifiAutoConnectPreferenceController2
com.android.settings.accessibility.ReduceBrightColorsIntensityPreferenceController
com.android.settings.accessibility.ReduceBrightColorsPersistencePreferenceController

View File

@@ -0,0 +1,49 @@
/*
* 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 androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
/** TODO(b/170970675): Update and add tests after ColorDisplayService work is integrated */
public class ReduceBrightColorsIntensityPreferenceControllerTest {
private final Context mContext = ApplicationProvider.getApplicationContext();
private final ReduceBrightColorsIntensityPreferenceController mPreferenceController =
new ReduceBrightColorsIntensityPreferenceController(mContext,
"rbc_intensity");
@Test
public void isAvailable_configuredRbcAvailable_enabledRbc_shouldReturnTrue() {
assertThat(mPreferenceController.isAvailable()).isTrue();
}
@Test
public void isAvailable_configuredRbcAvailable_disabledRbc_shouldReturnFalse() {
assertThat(mPreferenceController.isAvailable()).isTrue();
}
@Test
public void isAvailable_configuredRbcUnavailable_enabledRbc_shouldReturnFalse() {
assertThat(mPreferenceController.isAvailable()).isTrue();
}
}

View File

@@ -0,0 +1,82 @@
/*
* 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 androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class ReduceBrightColorsPersistencePreferenceControllerTest {
private static final String PREF_KEY = "rbc_persist";
private static final String RBC_PERSIST =
Settings.Secure.REDUCE_BRIGHT_COLORS_PERSIST_ACROSS_REBOOTS;
private static final int ON = 1;
private static final int OFF = 0;
private static final int UNKNOWN = -1;
private final Context mContext = ApplicationProvider.getApplicationContext();
private final SwitchPreference mPreference = new SwitchPreference(mContext);
private final ReduceBrightColorsPersistencePreferenceController mController =
new ReduceBrightColorsPersistencePreferenceController(mContext, PREF_KEY);
@Test
public void isChecked_enabledRbc_shouldReturnTrue() {
Settings.Secure.putInt(mContext.getContentResolver(), RBC_PERSIST, ON);
mController.updateState(mPreference);
assertThat(mController.isChecked()).isTrue();
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void isChecked_disabledRbc_shouldReturnFalse() {
Settings.Secure.putInt(mContext.getContentResolver(), RBC_PERSIST, OFF);
mController.updateState(mPreference);
assertThat(mController.isChecked()).isFalse();
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void setChecked_setTrue_shouldEnableRbc() {
mController.setChecked(true);
assertThat(
Settings.Secure.getInt(mContext.getContentResolver(), RBC_PERSIST, UNKNOWN))
.isEqualTo(ON);
}
@Test
public void setChecked_setFalse_shouldDisableRbc() {
mController.setChecked(false);
assertThat(
Settings.Secure.getInt(mContext.getContentResolver(), RBC_PERSIST, UNKNOWN))
.isEqualTo(OFF);
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.R;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class ReduceBrightColorsPreferenceControllerTest {
private static final String PREF_KEY = "rbc_preference";
private static final String RBC_ACTIVATED =
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED;
private static final int ON = 1;
private static final int OFF = 0;
private final Context mContext = ApplicationProvider.getApplicationContext();
private final ReduceBrightColorsPreferenceController mController =
new ReduceBrightColorsPreferenceController(mContext, PREF_KEY);
@Test
public void getSummary_enabledRbc_shouldReturnOnSummary() {
Settings.Secure.putInt(mContext.getContentResolver(),
RBC_ACTIVATED, ON);
assertThat(mController.getSummary().toString().contains(
mContext.getText(R.string.accessibility_feature_state_on))).isTrue();
}
@Test
public void getSummary_disabledRbc_shouldReturnOffSummary() {
Settings.Secure.putInt(mContext.getContentResolver(),
RBC_ACTIVATED, OFF);
assertThat(mController.getSummary().toString().contains(
mContext.getText(R.string.accessibility_feature_state_off))).isTrue();
}
}