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

@@ -97,6 +97,8 @@ public class AccessibilitySettings extends DashboardFragment {
"magnification_preference_screen";
private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
"daltonizer_preference";
private static final String DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN =
"reduce_bright_colors_preference";
// Extras passed to sub-fragments.
static final String EXTRA_PREFERENCE_KEY = "preference_key";
@@ -170,6 +172,8 @@ public class AccessibilitySettings extends DashboardFragment {
private Preference mDisplayMagnificationPreferenceScreen;
private Preference mDisplayDaltonizerPreferenceScreen;
private Preference mToggleInversionPreference;
private Preference mReduceBrightColorsPreference;
/**
* 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.
mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
// Reduce brightness.
mReduceBrightColorsPreference =
findPreference(DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN);
}
private void updateAllPreferences() {
@@ -488,6 +496,7 @@ public class AccessibilitySettings extends DashboardFragment {
mCategoryToPrefCategoryMap.get(CATEGORY_DISPLAY);
experimentalCategory.removePreference(mToggleInversionPreference);
experimentalCategory.removePreference(mDisplayDaltonizerPreferenceScreen);
experimentalCategory.removePreference(mReduceBrightColorsPreference);
mDisplayMagnificationPreferenceScreen.setSummary(
ToggleScreenMagnificationPreferenceFragment.getServiceSummary(getContext()));
mDisplayDaltonizerPreferenceScreen.setOrder(
@@ -502,8 +511,13 @@ public class AccessibilitySettings extends DashboardFragment {
mToggleLargePointerIconPreference.getOrder() + 1);
mToggleInversionPreference.setSummary(AccessibilityUtil.getSummary(
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(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;
}
};
}