[Accessibility] Add contrast control screen UI and setup entry point

Bug: 241805782
Test: atest, local raven device
Screenshot: attached on bug
Flag: aconfig
com.android.settings.accessibility.enable_color_contrast_control

Change-Id: I7fcc01b822b460c6585c41a5831575ba0ffbcc93
This commit is contained in:
marcusge
2024-02-09 00:03:00 +00:00
parent 7d58a1f3e8
commit cddd7b3660
40 changed files with 1639 additions and 0 deletions

View File

@@ -117,6 +117,8 @@ public class Settings extends SettingsActivity {
public static class TextReadingSettingsActivity extends SettingsActivity { /* empty */ }
/** Activity for text color and motion settings. */
public static class ColorAndMotionActivity extends SettingsActivity { /* empty */ }
/** Activity for color contrast settings. */
public static class ColorContrastActivity extends SettingsActivity { /* empty */ }
/** Activity for the security dashboard. */
public static class SecurityDashboardActivity extends SettingsActivity {

View File

@@ -0,0 +1,49 @@
/*
* Copyright (C) 2024 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 com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
/** Accessibility settings for color contrast. */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class ColorContrastFragment extends DashboardFragment {
private static final String TAG = "ColorContrastFragment";
@Override
protected int getPreferenceScreenResId() {
return R.xml.accessibility_color_contrast;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public int getMetricsCategory() {
// TODO(b/326539398): Add metrics tracking for color contrast.
return 0;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.accessibility_color_contrast);
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 2024 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 androidx.annotation.NonNull;
import com.android.settings.core.BasePreferenceController;
/**
* Controller for {@link ColorContrastFragment}.
*/
public class ContrastPreferenceController extends BasePreferenceController {
public ContrastPreferenceController(@NonNull Context context, @NonNull String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return Flags.enableColorContrastControl() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
}

View File

@@ -0,0 +1,122 @@
/*
* Copyright (C) 2024 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 android.app.UiModeManager.ContrastUtils.CONTRAST_LEVEL_HIGH;
import static android.app.UiModeManager.ContrastUtils.CONTRAST_LEVEL_MEDIUM;
import static android.app.UiModeManager.ContrastUtils.CONTRAST_LEVEL_STANDARD;
import static android.app.UiModeManager.ContrastUtils.fromContrastLevel;
import static android.app.UiModeManager.ContrastUtils.toContrastLevel;
import android.app.UiModeManager;
import android.content.Context;
import android.provider.Settings;
import android.view.View;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.widget.LayoutPreference;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
/**
* Controller for contrast selector.
*/
public class ContrastSelectorPreferenceController extends BasePreferenceController
implements LifecycleObserver, OnStart, OnStop, UiModeManager.ContrastChangeListener {
private static final String KEY_COLOR_CONTRAST_SELECTOR = "color_contrast_selector";
private final Executor mMainExecutor;
private final UiModeManager mUiModeManager;
private Map<Integer, FrameLayout> mContrastButtons = new HashMap<>();
public ContrastSelectorPreferenceController(@NonNull Context context,
@NonNull String preferenceKey) {
super(context, preferenceKey);
mMainExecutor = mContext.getMainExecutor();
mUiModeManager = mContext.getSystemService(UiModeManager.class);
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
final LayoutPreference mLayoutPreference =
screen.findPreference(KEY_COLOR_CONTRAST_SELECTOR);
mContrastButtons = Map.ofEntries(
Map.entry(CONTRAST_LEVEL_STANDARD,
mLayoutPreference.findViewById(R.id.contrast_button_default)),
Map.entry(CONTRAST_LEVEL_MEDIUM,
mLayoutPreference.findViewById(R.id.contrast_button_medium)),
Map.entry(CONTRAST_LEVEL_HIGH,
mLayoutPreference.findViewById(R.id.contrast_button_high))
);
mContrastButtons.forEach((contrastLevel, contrastButton) -> {
contrastButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(@Nullable View v) {
Settings.Secure.putFloat(mContext.getContentResolver(),
Settings.Secure.CONTRAST_LEVEL,
fromContrastLevel(contrastLevel));
}
});
});
highlightContrast(toContrastLevel(mUiModeManager.getContrast()));
}
@Override
public int getAvailabilityStatus() {
// The main preferences screen is feature guarded, so this always returns AVAILABLE.
return AVAILABLE;
}
@Override
public void onStart() {
mUiModeManager.addContrastChangeListener(mMainExecutor, this);
}
@Override
public void onStop() {
mUiModeManager.removeContrastChangeListener(this);
}
@Override
public void onContrastChanged(float contrast) {
highlightContrast(toContrastLevel(contrast));
}
private void highlightContrast(int contrast) {
mContrastButtons.forEach((level, button) -> {
button.setSelected(level == contrast);
});
}
}

View File

@@ -29,6 +29,7 @@ import com.android.settings.accessibility.AccessibilitySettings;
import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
import com.android.settings.accessibility.CaptioningPropertiesFragment;
import com.android.settings.accessibility.ColorAndMotionFragment;
import com.android.settings.accessibility.ColorContrastFragment;
import com.android.settings.accessibility.TextReadingPreferenceFragment;
import com.android.settings.accessibility.TextReadingPreferenceFragmentForSetupWizard;
import com.android.settings.accessibility.ToggleColorInversionPreferenceFragment;
@@ -381,6 +382,7 @@ public class SettingsGateway {
TurnScreenOnDetails.class.getName(),
NfcAndPaymentFragment.class.getName(),
ColorAndMotionFragment.class.getName(),
ColorContrastFragment.class.getName(),
LongBackgroundTasksDetails.class.getName(),
RegionalPreferencesEntriesFragment.class.getName(),
BatteryInfoFragment.class.getName(),