MediaRouter: Fix colors

- Modified the criteria for picking up the controller color based on
  similar implementation in v7 Palette so that text colors roughly match
  up to the material design standard colors from
  http://www.google.com/design/spec/style/color.html#color-color-palette
- Corrected opacity values on a light background for various drawables.

Bug: 24336474, Bug: 24674278, Bug: 24683845
Change-Id: Idc8658af841aa9856a1ef58a3a1d2928b4cbb5a0
diff --git a/v7/mediarouter/res/drawable-hdpi/ic_close_light.png b/v7/mediarouter/res/drawable-hdpi/ic_close_light.png
index 9ab350e..1a9cd75 100644
--- a/v7/mediarouter/res/drawable-hdpi/ic_close_light.png
+++ b/v7/mediarouter/res/drawable-hdpi/ic_close_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-hdpi/ic_pause_light.png b/v7/mediarouter/res/drawable-hdpi/ic_pause_light.png
index aeb13eb..bb707ea 100644
--- a/v7/mediarouter/res/drawable-hdpi/ic_pause_light.png
+++ b/v7/mediarouter/res/drawable-hdpi/ic_pause_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-hdpi/ic_play_light.png b/v7/mediarouter/res/drawable-hdpi/ic_play_light.png
index 0648523..5345ee3 100644
--- a/v7/mediarouter/res/drawable-hdpi/ic_play_light.png
+++ b/v7/mediarouter/res/drawable-hdpi/ic_play_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-mdpi/ic_close_light.png b/v7/mediarouter/res/drawable-mdpi/ic_close_light.png
index 73faf52..40a1a84 100644
--- a/v7/mediarouter/res/drawable-mdpi/ic_close_light.png
+++ b/v7/mediarouter/res/drawable-mdpi/ic_close_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-mdpi/ic_pause_light.png b/v7/mediarouter/res/drawable-mdpi/ic_pause_light.png
index 6708b41..74068ea 100644
--- a/v7/mediarouter/res/drawable-mdpi/ic_pause_light.png
+++ b/v7/mediarouter/res/drawable-mdpi/ic_pause_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-mdpi/ic_play_light.png b/v7/mediarouter/res/drawable-mdpi/ic_play_light.png
index 8f6a725..f208795 100644
--- a/v7/mediarouter/res/drawable-mdpi/ic_play_light.png
+++ b/v7/mediarouter/res/drawable-mdpi/ic_play_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xhdpi/ic_close_light.png b/v7/mediarouter/res/drawable-xhdpi/ic_close_light.png
index a3896c5..6bc4372 100644
--- a/v7/mediarouter/res/drawable-xhdpi/ic_close_light.png
+++ b/v7/mediarouter/res/drawable-xhdpi/ic_close_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xhdpi/ic_pause_light.png b/v7/mediarouter/res/drawable-xhdpi/ic_pause_light.png
index 239b5a8..792104f 100644
--- a/v7/mediarouter/res/drawable-xhdpi/ic_pause_light.png
+++ b/v7/mediarouter/res/drawable-xhdpi/ic_pause_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xhdpi/ic_play_light.png b/v7/mediarouter/res/drawable-xhdpi/ic_play_light.png
index 4be0ef3..d12d495 100644
--- a/v7/mediarouter/res/drawable-xhdpi/ic_play_light.png
+++ b/v7/mediarouter/res/drawable-xhdpi/ic_play_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xxhdpi/ic_close_light.png b/v7/mediarouter/res/drawable-xxhdpi/ic_close_light.png
index 22d7aa5..51b4401 100644
--- a/v7/mediarouter/res/drawable-xxhdpi/ic_close_light.png
+++ b/v7/mediarouter/res/drawable-xxhdpi/ic_close_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xxhdpi/ic_pause_light.png b/v7/mediarouter/res/drawable-xxhdpi/ic_pause_light.png
index 78456c7..dc63538 100644
--- a/v7/mediarouter/res/drawable-xxhdpi/ic_pause_light.png
+++ b/v7/mediarouter/res/drawable-xxhdpi/ic_pause_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xxhdpi/ic_play_light.png b/v7/mediarouter/res/drawable-xxhdpi/ic_play_light.png
index 27a0dc0..1c57756b 100644
--- a/v7/mediarouter/res/drawable-xxhdpi/ic_play_light.png
+++ b/v7/mediarouter/res/drawable-xxhdpi/ic_play_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xxxhdpi/ic_close_light.png b/v7/mediarouter/res/drawable-xxxhdpi/ic_close_light.png
new file mode 100644
index 0000000..df42fee
--- /dev/null
+++ b/v7/mediarouter/res/drawable-xxxhdpi/ic_close_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xxxhdpi/ic_pause_light.png b/v7/mediarouter/res/drawable-xxxhdpi/ic_pause_light.png
new file mode 100644
index 0000000..66178aa
--- /dev/null
+++ b/v7/mediarouter/res/drawable-xxxhdpi/ic_pause_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xxxhdpi/ic_play_light.png b/v7/mediarouter/res/drawable-xxxhdpi/ic_play_light.png
new file mode 100644
index 0000000..904bbdb
--- /dev/null
+++ b/v7/mediarouter/res/drawable-xxxhdpi/ic_play_light.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable/mr_ic_audiotrack_light.xml b/v7/mediarouter/res/drawable/mr_ic_audiotrack_light.xml
new file mode 100644
index 0000000..05b4a8a
--- /dev/null
+++ b/v7/mediarouter/res/drawable/mr_ic_audiotrack_light.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+    android:src="@drawable/ic_audiotrack_light"
+    android:alpha="0.87" />
diff --git a/v7/mediarouter/res/drawable/mr_ic_close_light.xml b/v7/mediarouter/res/drawable/mr_ic_close_light.xml
index f1dd0cc..c663ae8 100644
--- a/v7/mediarouter/res/drawable/mr_ic_close_light.xml
+++ b/v7/mediarouter/res/drawable/mr_ic_close_light.xml
@@ -15,5 +15,10 @@
 -->
 
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:drawable="@drawable/ic_close_light" />
+    <item>
+        <bitmap
+            android:src="@drawable/ic_close_light"
+            android:alpha="0.87" />
+    </item>
+
 </selector>
diff --git a/v7/mediarouter/res/drawable/mr_ic_pause_light.xml b/v7/mediarouter/res/drawable/mr_ic_pause_light.xml
index 9702be8..0cea425 100644
--- a/v7/mediarouter/res/drawable/mr_ic_pause_light.xml
+++ b/v7/mediarouter/res/drawable/mr_ic_pause_light.xml
@@ -15,5 +15,9 @@
 -->
 
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:drawable="@drawable/ic_pause_light" />
+    <item>
+        <bitmap
+            android:src="@drawable/ic_pause_light"
+            android:alpha="0.87" />
+    </item>
 </selector>
diff --git a/v7/mediarouter/res/drawable/mr_ic_play_light.xml b/v7/mediarouter/res/drawable/mr_ic_play_light.xml
index d18cc12..48a7e03 100644
--- a/v7/mediarouter/res/drawable/mr_ic_play_light.xml
+++ b/v7/mediarouter/res/drawable/mr_ic_play_light.xml
@@ -15,5 +15,9 @@
 -->
 
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:drawable="@drawable/ic_play_light" />
+    <item>
+        <bitmap
+            android:src="@drawable/ic_play_light"
+            android:alpha="0.87" />
+    </item>
 </selector>
diff --git a/v7/mediarouter/res/values/attrs.xml b/v7/mediarouter/res/values/attrs.xml
index 3a5f333..cd6e95b 100644
--- a/v7/mediarouter/res/values/attrs.xml
+++ b/v7/mediarouter/res/values/attrs.xml
@@ -46,5 +46,4 @@
     <attr name="mediaRouteControllerSecondaryTextStyle" format="reference" />
     <attr name="mediaRouteExpandGroupDrawable" format="reference" />
     <attr name="mediaRouteCollapseGroupDrawable" format="reference" />
-    <attr name="mediaRouteControllerTextStyle" format="reference" />
 </resources>
diff --git a/v7/mediarouter/res/values/themes.xml b/v7/mediarouter/res/values/themes.xml
index 4fe12cf..3890199 100644
--- a/v7/mediarouter/res/values/themes.xml
+++ b/v7/mediarouter/res/values/themes.xml
@@ -43,7 +43,7 @@
         <item name="mediaRoutePlayDrawable">@drawable/mr_ic_play_light</item>
         <item name="mediaRoutePauseDrawable">@drawable/mr_ic_pause_light</item>
         <item name="mediaRouteCastDrawable">@drawable/mr_ic_cast_light</item>
-        <item name="mediaRouteAudioTrackDrawable">@drawable/ic_audiotrack_light</item>
+        <item name="mediaRouteAudioTrackDrawable">@drawable/mr_ic_audiotrack_light</item>
         <item name="mediaRouteControllerPrimaryTextStyle">@style/Widget.MediaRouter.ControllerText.Primary.Light</item>
         <item name="mediaRouteControllerSecondaryTextStyle">@style/Widget.MediaRouter.ControllerText.Secondary.Light</item>
     </style>
@@ -58,7 +58,7 @@
         <item name="mediaRoutePlayDrawable">@drawable/mr_ic_play_light</item>
         <item name="mediaRoutePauseDrawable">@drawable/mr_ic_pause_light</item>
         <item name="mediaRouteCastDrawable">@drawable/mr_ic_cast_light</item>
-        <item name="mediaRouteAudioTrackDrawable">@drawable/ic_audiotrack_light</item>
+        <item name="mediaRouteAudioTrackDrawable">@drawable/mr_ic_audiotrack_light</item>
         <item name="mediaRouteDefaultIconDrawable">@drawable/ic_tv_light</item>
         <item name="mediaRouteSpeakerIconDrawable">@drawable/ic_speaker_light</item>
         <item name="mediaRouteSpeakerGroupIconDrawable">@drawable/ic_speaker_group_light</item>
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java b/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java
index 8b72569..0ae3b07 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java
@@ -19,33 +19,41 @@
 import android.content.Context;
 import android.graphics.Color;
 import android.graphics.drawable.Drawable;
+import android.support.annotation.IntDef;
 import android.support.v4.graphics.ColorUtils;
 import android.support.v7.mediarouter.R;
 import android.util.TypedValue;
 import android.view.ContextThemeWrapper;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
 final class MediaRouterThemeHelper {
-
-    // http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html
-    private static final float MIN_CONTRAST = 4.5f;
-
-    private static final float LIGHT_LUMINANCE_THRESHOLD = 0.5f;
+    private static final float MIN_CONTRAST = 3.0f;
+    private static final float MIN_CONTRAST_GROUP_VOLUMES = 4.5f;
 
     private static final float COLOR_LIGHTNESS_MULTIPLIER = 1.15f;
 
+    @IntDef({COLOR_DARK_ON_LIGHT_BACKGROUND, COLOR_WHITE_ON_DARK_BACKGROUND})
+    @Retention(RetentionPolicy.SOURCE)
+    private @interface ControllerColorType {}
+
+    private static final int COLOR_DARK_ON_LIGHT_BACKGROUND = 0xDE000000; /* Opacity of 87% */
+    private static final int COLOR_WHITE_ON_DARK_BACKGROUND = Color.WHITE;
+
     private MediaRouterThemeHelper() {
     }
 
     public static Context createThemedContext(Context context) {
         int style;
         if (isLightTheme(context)) {
-            if (isPrimaryColorLight(context)) {
+            if (getControllerColor(context) == COLOR_DARK_ON_LIGHT_BACKGROUND) {
                 style = R.style.Theme_MediaRouter_Light;
             } else {
                 style = R.style.Theme_MediaRouter_Light_DarkControlPanel;
             }
         } else {
-            if (isPrimaryColorLight(context)) {
+            if (getControllerColor(context) == COLOR_DARK_ON_LIGHT_BACKGROUND) {
                 style = R.style.Theme_MediaRouter_LightControlPanel;
             } else {
                 style = R.style.Theme_MediaRouter;
@@ -64,8 +72,13 @@
         return res != 0 ? context.getResources().getDrawable(res) : null;
     }
 
-    public static int getControllerColor(Context context) {
-        return isPrimaryColorLight(context) ? Color.BLACK : Color.WHITE;
+    public static @ControllerColorType int getControllerColor(Context context) {
+        int primaryColor = getThemeColor(context, R.attr.colorPrimary);
+        if (ColorUtils.calculateContrast(COLOR_WHITE_ON_DARK_BACKGROUND, primaryColor)
+                >= MIN_CONTRAST) {
+            return COLOR_WHITE_ON_DARK_BACKGROUND;
+        }
+        return COLOR_DARK_ON_LIGHT_BACKGROUND;
     }
 
     public static int getButtonTextColor(Context context) {
@@ -81,14 +94,16 @@
     }
 
     public static int getVolumeGroupListBackgroundColor(Context context) {
-        int primaryColor = getThemeColor(context, R.attr.colorPrimary);
         int primaryDarkColor = getThemeColor(context, R.attr.colorPrimaryDark);
-
-        if (ColorUtils.calculateLuminance(primaryColor) >= LIGHT_LUMINANCE_THRESHOLD) {
-            // This means the volume sliders are colored black.
-            double contrast = ColorUtils.calculateContrast(Color.BLACK, primaryDarkColor);
-            if (contrast < MIN_CONTRAST) {
-                // Use a lighter color for better contrast.
+        if (getControllerColor(context) == COLOR_DARK_ON_LIGHT_BACKGROUND) {
+            // We are showing dark volume sliders in a darker background. Check whether they have
+            // sufficient contrast.
+            double contrast = ColorUtils.calculateContrast(
+                    COLOR_DARK_ON_LIGHT_BACKGROUND, primaryDarkColor);
+            if (contrast < MIN_CONTRAST_GROUP_VOLUMES) {
+                // Generate a lighter color based on the 'colorPrimary' and use it instead for
+                // better contrast.
+                int primaryColor = getThemeColor(context, R.attr.colorPrimary);
                 return adjustColorLightness(primaryColor, COLOR_LIGHTNESS_MULTIPLIER);
             }
         }
@@ -101,11 +116,6 @@
                 && value.data != 0;
     }
 
-    private static boolean isPrimaryColorLight(Context context) {
-        int primaryColor = getThemeColor(context, R.attr.colorPrimary);
-        return ColorUtils.calculateLuminance(primaryColor) >= LIGHT_LUMINANCE_THRESHOLD;
-    }
-
     private static int adjustColorLightness(int color, float lightness) {
         float[] hsl = new float[3];
         ColorUtils.colorToHSL(color, hsl);