1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.display; 18 19 import static android.app.UiModeManager.ContrastUtils.CONTRAST_LEVEL_HIGH; 20 import static android.app.UiModeManager.ContrastUtils.CONTRAST_LEVEL_MEDIUM; 21 import static android.app.UiModeManager.ContrastUtils.CONTRAST_LEVEL_STANDARD; 22 import static android.app.UiModeManager.ContrastUtils.toContrastLevel; 23 24 import android.app.UiModeManager; 25 import android.content.Context; 26 27 import androidx.annotation.NonNull; 28 29 import com.android.settings.R; 30 import com.android.settings.accessibility.Flags; 31 import com.android.settings.core.BasePreferenceController; 32 33 import java.util.Map; 34 35 /** 36 * Controller for {@link ColorContrastFragment}. 37 */ 38 public class ContrastPreferenceController extends BasePreferenceController { 39 ContrastPreferenceController(@onNull Context context, @NonNull String preferenceKey)40 public ContrastPreferenceController(@NonNull Context context, @NonNull String preferenceKey) { 41 super(context, preferenceKey); 42 } 43 44 @Override getAvailabilityStatus()45 public int getAvailabilityStatus() { 46 return Flags.enableColorContrastControl() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 47 } 48 49 @Override getSummary()50 public CharSequence getSummary() { 51 Map<Integer, Integer> mContrastLevelToResId = Map.ofEntries( 52 Map.entry(CONTRAST_LEVEL_STANDARD, R.string.contrast_default), 53 Map.entry(CONTRAST_LEVEL_MEDIUM, R.string.contrast_medium), 54 Map.entry(CONTRAST_LEVEL_HIGH, R.string.contrast_high) 55 ); 56 57 float contrastLevel = mContext.getSystemService(UiModeManager.class).getContrast(); 58 return mContext.getString(mContrastLevelToResId.get(toContrastLevel(contrastLevel))); 59 } 60 } 61