Home | History | Annotate | Download | only in incallui
      1 package com.android.incallui;
      2 
      3 import android.content.res.Resources;
      4 import android.content.res.TypedArray;
      5 import android.telecom.PhoneAccount;
      6 
      7 import com.android.contacts.common.util.MaterialColorMapUtils;
      8 import com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette;
      9 import com.android.dialer.R;
     10 
     11 public class InCallUIMaterialColorMapUtils extends MaterialColorMapUtils {
     12     private final TypedArray sPrimaryColors;
     13     private final TypedArray sSecondaryColors;
     14     private final Resources mResources;
     15 
     16     public InCallUIMaterialColorMapUtils(Resources resources) {
     17         super(resources);
     18         sPrimaryColors = resources.obtainTypedArray(R.array.background_colors);
     19         sSecondaryColors = resources.obtainTypedArray(R.array.background_colors_dark);
     20         mResources = resources;
     21     }
     22 
     23     /**
     24      * Currently the InCallUI color will only vary by SIM color which is a list of colors
     25      * defined in the background_colors array, so first search the list for the matching color and
     26      * fall back to the closest matching color if an exact match does not exist.
     27      */
     28     @Override
     29     public MaterialPalette calculatePrimaryAndSecondaryColor(int color) {
     30         if (color == PhoneAccount.NO_HIGHLIGHT_COLOR) {
     31             return getDefaultPrimaryAndSecondaryColors(mResources);
     32         }
     33 
     34         for (int i = 0; i < sPrimaryColors.length(); i++) {
     35             if (sPrimaryColors.getColor(i, 0) == color) {
     36                 return new MaterialPalette(
     37                         sPrimaryColors.getColor(i, 0),
     38                         sSecondaryColors.getColor(i, 0));
     39             }
     40         }
     41 
     42         // The color isn't in the list, so use the superclass to find an approximate color.
     43         return super.calculatePrimaryAndSecondaryColor(color);
     44     }
     45 
     46     /**
     47      * {@link Resources#getColor(int) used for compatibility
     48      */
     49     @SuppressWarnings("deprecation")
     50     public static MaterialPalette getDefaultPrimaryAndSecondaryColors(Resources resources) {
     51         final int primaryColor = resources.getColor(R.color.dialer_theme_color);
     52         final int secondaryColor = resources.getColor(R.color.dialer_theme_color_dark);
     53         return new MaterialPalette(primaryColor, secondaryColor);
     54     }
     55 }
     56