1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 package com.android.settings.display; 15 16 import android.content.Context; 17 import android.hardware.display.ColorDisplayManager; 18 19 import androidx.annotation.VisibleForTesting; 20 21 import com.android.settings.R; 22 import com.android.settings.core.BasePreferenceController; 23 24 public class ColorModePreferenceController extends BasePreferenceController { 25 26 private ColorDisplayManager mColorDisplayManager; 27 ColorModePreferenceController(Context context, String key)28 public ColorModePreferenceController(Context context, String key) { 29 super(context, key); 30 } 31 32 @Override getAvailabilityStatus()33 public int getAvailabilityStatus() { 34 return mContext.getSystemService(ColorDisplayManager.class) 35 .isDeviceColorManaged() 36 && !ColorDisplayManager.areAccessibilityTransformsEnabled(mContext) ? 37 AVAILABLE_UNSEARCHABLE : DISABLED_FOR_USER; 38 } 39 40 @Override getSummary()41 public CharSequence getSummary() { 42 final int colorMode = getColorDisplayManager().getColorMode(); 43 if (colorMode == ColorDisplayManager.COLOR_MODE_AUTOMATIC) { 44 return mContext.getText(R.string.color_mode_option_automatic); 45 } 46 if (colorMode == ColorDisplayManager.COLOR_MODE_SATURATED) { 47 return mContext.getText(R.string.color_mode_option_saturated); 48 } 49 if (colorMode == ColorDisplayManager.COLOR_MODE_BOOSTED) { 50 return mContext.getText(R.string.color_mode_option_boosted); 51 } 52 return mContext.getText(R.string.color_mode_option_natural); 53 } 54 55 @VisibleForTesting getColorDisplayManager()56 ColorDisplayManager getColorDisplayManager() { 57 if (mColorDisplayManager == null) { 58 mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class); 59 } 60 return mColorDisplayManager; 61 } 62 } 63