1 /* 2 * Copyright (C) 2021 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.hardware.display.ColorDisplayManager.COLOR_MODE_AUTOMATIC; 20 import static android.hardware.display.ColorDisplayManager.COLOR_MODE_BOOSTED; 21 import static android.hardware.display.ColorDisplayManager.COLOR_MODE_NATURAL; 22 import static android.hardware.display.ColorDisplayManager.COLOR_MODE_SATURATED; 23 import static android.hardware.display.ColorDisplayManager.VENDOR_COLOR_MODE_RANGE_MAX; 24 import static android.hardware.display.ColorDisplayManager.VENDOR_COLOR_MODE_RANGE_MIN; 25 26 import android.content.res.Resources; 27 import android.util.ArrayMap; 28 29 import com.android.settings.R; 30 31 import java.util.Map; 32 33 final class ColorModeUtils { 34 ColorModeUtils()35 private ColorModeUtils() { 36 // Do not instantiate. 37 } 38 getColorModeMapping(Resources resources)39 static Map<Integer, String> getColorModeMapping(Resources resources) { 40 final String[] colorModeOptionsStrings = resources.getStringArray( 41 R.array.config_color_mode_options_strings); 42 final int[] colorModeOptionsValues = resources.getIntArray( 43 R.array.config_color_mode_options_values); 44 if (colorModeOptionsStrings.length != colorModeOptionsValues.length) { 45 throw new RuntimeException("Color mode options of unequal length"); 46 } 47 48 final Map<Integer, String> colorModesToSummaries = new ArrayMap<>(); 49 for (int i = 0; i < colorModeOptionsValues.length; i++) { 50 final int colorMode = colorModeOptionsValues[i]; 51 if (colorMode == COLOR_MODE_NATURAL 52 || colorMode == COLOR_MODE_BOOSTED 53 || colorMode == COLOR_MODE_SATURATED 54 || colorMode == COLOR_MODE_AUTOMATIC 55 || (colorMode >= VENDOR_COLOR_MODE_RANGE_MIN 56 && colorMode <= VENDOR_COLOR_MODE_RANGE_MAX)) { 57 colorModesToSummaries.put(colorMode, colorModeOptionsStrings[i]); 58 } 59 } 60 return colorModesToSummaries; 61 } 62 } 63