diff options
author | Brian Attwell <brianattwell@google.com> | 2014-07-15 13:46:25 -0700 |
---|---|---|
committer | Brian Attwell <brianattwell@google.com> | 2014-07-15 14:48:04 -0700 |
commit | d4d290d39d14e17683ec86b07a150c9df35505ae (patch) | |
tree | e3e85e453563950d694878ef61bc2371d33a69d4 /src/com/android/contacts/common/util | |
parent | e0337eb6a02c8c36d7c136737c29ed6e95f31e1c (diff) | |
download | android_packages_apps_ContactsCommon-d4d290d39d14e17683ec86b07a150c9df35505ae.tar.gz android_packages_apps_ContactsCommon-d4d290d39d14e17683ec86b07a150c9df35505ae.tar.bz2 android_packages_apps_ContactsCommon-d4d290d39d14e17683ec86b07a150c9df35505ae.zip |
Updated LetterTileDrawable colors.
Now that LetterTileDrawable colors are the same as the colors used by
MaterialColorMapUtils, I unified the colors inside colors.xml and was
able to delete some MaterialColorMapUtils code.
BUG: 15889179
BUG: 16159407
Change-Id: I02b96011a30def913fb1de589aeb7a8c336e2154
Diffstat (limited to 'src/com/android/contacts/common/util')
-rw-r--r-- | src/com/android/contacts/common/util/MaterialColorMapUtils.java | 65 |
1 files changed, 26 insertions, 39 deletions
diff --git a/src/com/android/contacts/common/util/MaterialColorMapUtils.java b/src/com/android/contacts/common/util/MaterialColorMapUtils.java index 33d5087a..9c8862c3 100644 --- a/src/com/android/contacts/common/util/MaterialColorMapUtils.java +++ b/src/com/android/contacts/common/util/MaterialColorMapUtils.java @@ -16,26 +16,23 @@ package com.android.contacts.common.util; -import android.graphics.Color; +import com.android.contacts.common.R; + +import android.content.res.Resources; +import android.content.res.TypedArray; import android.os.Trace; public class MaterialColorMapUtils { - /** - * Values from the extended Material color palette. 500 values are chosen when they meet - * GAR accessibility requirements as a background for white text. Darker versions from the - * extended palette are chosen when the 500 values don't meet GAR requirements (see b/16159407). - */ - private static final int PRIMARY_COLORS[] = {0xFFDB4437, 0xFFE91E63, 0xFF9C27B0, 0xFF673AB7, - 0xFF3F51B5, 0xFF4285F4, 0xFF039BE5, 0xFF0097A7, 0xFF009688, 0xFF0F9D58, 0xFF689F38, - 0xFFEF6C00, 0xFFFF5722, 0xFF757575, 0xFF607D8B}; + private final TypedArray sPrimaryColors; + private final TypedArray sSecondaryColors; - /** - * Darker versions of the colors in PRIMARY_COLORS. Two shades darker. - */ - private static final int SECONDARY_COLORS[] = {0xFFC53929, 0xFFC2185B, 0xFF7B1FA2, - 0xFF512DA8, 0xFF303F9F, 0xFF3367D6, 0xFF0277BD, 0xFF006064, 0xFF00796B, 0xFF0B8043, - 0xFF33691E, 0xFFE65100, 0xFFE64A19, 0xFF424242, 0xFF455A64}; + public MaterialColorMapUtils(Resources resources) { + sPrimaryColors = resources.obtainTypedArray( + com.android.contacts.common.R.array.letter_tile_colors); + sSecondaryColors = resources.obtainTypedArray( + com.android.contacts.common.R.array.letter_tile_colors_dark); + } public static class MaterialPalette { public MaterialPalette(int primaryColor, int secondaryColor) { @@ -47,19 +44,18 @@ public class MaterialColorMapUtils { } /** - * Return primary and secondary colors from the Material color - * palette that are similar to {@param color}. + * Return primary and secondary colors from the Material color palette that are similar to + * {@param color}. */ - public static MaterialPalette calculatePrimaryAndSecondaryColor(int color) { + public MaterialPalette calculatePrimaryAndSecondaryColor(int color) { Trace.beginSection("calculatePrimaryAndSecondaryColor"); - // TODO: check matches with known LetterTileDrawable colors, once they are material colors - final float colorHue = hue(color); float minimumDistance = Float.MAX_VALUE; int indexBestMatch = 0; - for (int i = 0; i < PRIMARY_COLORS.length; i++) { - final float comparedHue = hue(PRIMARY_COLORS[i]); + for (int i = 0; i < sPrimaryColors.length(); i++) { + final int primaryColor = sPrimaryColors.getColor(i, 0); + final float comparedHue = hue(primaryColor); // No need to be perceptually accurate when calculating color distances since // we are only mapping to 15 colors. Being slightly inaccurate isn't going to change // the mapping very often. @@ -71,25 +67,16 @@ public class MaterialColorMapUtils { } Trace.endSection(); - return new MaterialPalette(PRIMARY_COLORS[indexBestMatch], - SECONDARY_COLORS[indexBestMatch]); + return new MaterialPalette(sPrimaryColors.getColor(indexBestMatch, 0), + sSecondaryColors.getColor(indexBestMatch, 0)); } - /** - * Given a primary color, output a secondary color. Ideally, this function would use the exact - * Material palette secondary color that corresponds with {@param primaryColor}. - */ - // TODO: update to use a LUT, once primaryColor is gauranteed to be from Material palette - public static MaterialPalette calculateSecondaryColor(int primaryColor) { - // Arbitrarily chosen constant. - final float hsv[] = new float[3]; - final float SYSTEM_BAR_BRIGHTNESS_FACTOR = 0.8f; - // Create a darker version of the actionbar color. HSV is device dependent - // and not perceptually-linear. Therefore, we can't say mStatusBarColor is - // 70% as bright as the action bar color. We can only say: it is a bit darker. - Color.colorToHSV(primaryColor, hsv); - hsv[2] *= SYSTEM_BAR_BRIGHTNESS_FACTOR; - return new MaterialPalette(primaryColor, Color.HSVToColor(hsv)); + public static MaterialPalette getDefaultPrimaryAndSecondaryColors(Resources resources) { + final int primaryColor = resources.getColor( + R.color.quickcontact_default_photo_tint_color); + final int secondaryColor = resources.getColor( + R.color.quickcontact_default_photo_tint_color_dark); + return new MaterialPalette(primaryColor, secondaryColor); } /** |