16c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chenpackage com.android.incallui; 26c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen 36c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chenimport android.content.res.Resources; 46c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chenimport android.content.res.TypedArray; 56c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chenimport android.telecom.PhoneAccount; 66c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen 76c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chenimport com.android.contacts.common.util.MaterialColorMapUtils; 86c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chenimport com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette; 96c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen 106c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chenpublic class InCallUIMaterialColorMapUtils extends MaterialColorMapUtils { 116c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen private final TypedArray sPrimaryColors; 126c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen private final TypedArray sSecondaryColors; 136c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen private final Resources mResources; 146c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen 156c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen public InCallUIMaterialColorMapUtils(Resources resources) { 166c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen super(resources); 176c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen sPrimaryColors = resources.obtainTypedArray( 186c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen com.android.incallui.R.array.background_colors); 196c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen sSecondaryColors = resources.obtainTypedArray( 20a312c8e4b9a010407085dbaea69c10aacfb6945cNancy Chen com.android.incallui.R.array.background_colors_dark); 216c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen mResources = resources; 226c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen } 236c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen 246c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen /** 256c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen * Currently the InCallUI color will only vary by SIM color which is a list of colors 266c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen * defined in the background_colors array, so first search the list for the matching color and 276c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen * fall back to the closest matching color if an exact match does not exist. 286c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen */ 296c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen @Override 306c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen public MaterialPalette calculatePrimaryAndSecondaryColor(int color) { 31737f56760b617688aac7218021a5e615ed750810Ihab Awad if (color == PhoneAccount.NO_HIGHLIGHT_COLOR) { 326c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen return getDefaultPrimaryAndSecondaryColors(mResources); 336c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen } 346c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen 356c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen for (int i = 0; i < sPrimaryColors.length(); i++) { 366c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen if (sPrimaryColors.getColor(i, 0) == color) { 376c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen return new MaterialPalette( 386c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen sPrimaryColors.getColor(i, 0), 396c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen sSecondaryColors.getColor(i, 0)); 406c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen } 416c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen } 426c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen 436c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen // The color isn't in the list, so use the superclass to find an approximate color. 446c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen return super.calculatePrimaryAndSecondaryColor(color); 456c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen } 466c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen 476c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen public static MaterialPalette getDefaultPrimaryAndSecondaryColors(Resources resources) { 486c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen final int primaryColor = resources.getColor(R.color.dialer_theme_color); 496c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen final int secondaryColor = resources.getColor(R.color.dialer_theme_color_dark); 506c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen return new MaterialPalette(primaryColor, secondaryColor); 516c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen } 526c1e0d8809bc084bd081a23b48d09e095a615348Nancy Chen}