blob: 945e9fb5a684f5e384b8b088db9856539380708f [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
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
17package com.android.incallui;
18
19import android.content.res.Resources;
20import android.content.res.TypedArray;
21import android.telecom.PhoneAccount;
22import com.android.contacts.common.util.MaterialColorMapUtils;
23
24public class InCallUIMaterialColorMapUtils extends MaterialColorMapUtils {
25
linyuh183cb712017-12-27 17:02:37 -080026 private final TypedArray primaryColors;
27 private final TypedArray secondaryColors;
28 private final Resources resources;
Eric Erfanianccca3152017-02-22 16:32:36 -080029
30 public InCallUIMaterialColorMapUtils(Resources resources) {
31 super(resources);
linyuh183cb712017-12-27 17:02:37 -080032 primaryColors = resources.obtainTypedArray(R.array.background_colors);
33 secondaryColors = resources.obtainTypedArray(R.array.background_colors_dark);
34 this.resources = resources;
Eric Erfanianccca3152017-02-22 16:32:36 -080035 }
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) {
linyuh183cb712017-12-27 17:02:37 -080055 return getDefaultPrimaryAndSecondaryColors(resources);
Eric Erfanianccca3152017-02-22 16:32:36 -080056 }
57
linyuh183cb712017-12-27 17:02:37 -080058 for (int i = 0; i < primaryColors.length(); i++) {
59 if (primaryColors.getColor(i, 0) == color) {
60 return new MaterialPalette(primaryColors.getColor(i, 0), secondaryColors.getColor(i, 0));
Eric Erfanianccca3152017-02-22 16:32:36 -080061 }
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}