Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 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 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 26 | private final TypedArray primaryColors; |
| 27 | private final TypedArray secondaryColors; |
| 28 | private final Resources resources; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 29 | |
| 30 | public InCallUIMaterialColorMapUtils(Resources resources) { |
| 31 | super(resources); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 32 | primaryColors = resources.obtainTypedArray(R.array.background_colors); |
| 33 | secondaryColors = resources.obtainTypedArray(R.array.background_colors_dark); |
| 34 | this.resources = resources; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 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) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 55 | return getDefaultPrimaryAndSecondaryColors(resources); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 56 | } |
| 57 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 58 | 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 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 | } |