1 /* 2 * Copyright (C) 2016 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.incallui; 18 19 import android.content.res.Resources; 20 import android.content.res.TypedArray; 21 import android.telecom.PhoneAccount; 22 import com.android.contacts.common.util.MaterialColorMapUtils; 23 24 public class InCallUIMaterialColorMapUtils extends MaterialColorMapUtils { 25 26 private final TypedArray mPrimaryColors; 27 private final TypedArray mSecondaryColors; 28 private final Resources mResources; 29 30 public InCallUIMaterialColorMapUtils(Resources resources) { 31 super(resources); 32 mPrimaryColors = resources.obtainTypedArray(R.array.background_colors); 33 mSecondaryColors = resources.obtainTypedArray(R.array.background_colors_dark); 34 mResources = resources; 35 } 36 37 /** 38 * {@link Resources#getColor(int) used for compatibility 39 */ 40 @SuppressWarnings("deprecation") 41 public static MaterialPalette getDefaultPrimaryAndSecondaryColors(Resources resources) { 42 final int primaryColor = resources.getColor(R.color.dialer_theme_color); 43 final int secondaryColor = resources.getColor(R.color.dialer_theme_color_dark); 44 return new MaterialPalette(primaryColor, secondaryColor); 45 } 46 47 /** 48 * Currently the InCallUI color will only vary by SIM color which is a list of colors defined in 49 * the background_colors array, so first search the list for the matching color and fall back to 50 * the closest matching color if an exact match does not exist. 51 */ 52 @Override 53 public MaterialPalette calculatePrimaryAndSecondaryColor(int color) { 54 if (color == PhoneAccount.NO_HIGHLIGHT_COLOR) { 55 return getDefaultPrimaryAndSecondaryColors(mResources); 56 } 57 58 for (int i = 0; i < mPrimaryColors.length(); i++) { 59 if (mPrimaryColors.getColor(i, 0) == color) { 60 return new MaterialPalette(mPrimaryColors.getColor(i, 0), mSecondaryColors.getColor(i, 0)); 61 } 62 } 63 64 // The color isn't in the list, so use the superclass to find an approximate color. 65 return super.calculatePrimaryAndSecondaryColor(color); 66 } 67 } 68