MediaRouter: Set volume slider color properly

Change-Id: Id588ad4c7bf2ef088c62ba3cfdf5420cbe9932c2
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
index f4b1a86..ab14424 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
@@ -25,6 +25,8 @@
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.graphics.PorterDuff;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
@@ -122,6 +124,7 @@
     private ListView mVolumeGroupList;
     private SeekBar mVolumeSlider;
     private boolean mVolumeSliderTouched;
+    private int mVolumeSliderColor;
 
     private MediaControllerCompat mMediaController;
     private MediaControllerCallback mControllerCallback;
@@ -325,6 +328,8 @@
                 }
             }
         });
+        mVolumeSliderColor = MediaRouterThemeHelper.getVolumeSliderColor(getContext());
+        setVolumeSliderColor(mVolumeSlider, mVolumeSliderColor);
 
         TypedArray styledAttributes = getContext().obtainStyledAttributes(new int[] {
                 R.attr.mediaRouteExpandGroupDrawable,
@@ -353,13 +358,14 @@
             }
         });
 
-        mCreated = true;
         mCustomControlView = onCreateMediaControlView(savedInstanceState);
         if (mCustomControlView != null) {
             mCustomControlLayout.addView(mCustomControlView);
             mCustomControlLayout.setVisibility(View.VISIBLE);
             mArtView.setVisibility(View.GONE);
         }
+
+        mCreated = true;
         update();
     }
 
@@ -572,8 +578,8 @@
                 height = mControlLayout.getHeight();
             }
         }
-        mDefaultControlLayout.setLayoutParams(new LinearLayout.LayoutParams(
-                LinearLayout.LayoutParams.FILL_PARENT, height));
+        mDefaultControlLayout.setLayoutParams(
+                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, height));
         mNeedToAdjustControlFrameLayout = false;
     }
 
@@ -615,6 +621,13 @@
         }
     }
 
+    private static void setVolumeSliderColor(SeekBar volumeSlider, int color) {
+        volumeSlider.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
+        if (Build.VERSION.SDK_INT >= 16) {
+            SeekBarJellybean.getThumb(volumeSlider).setColorFilter(color, PorterDuff.Mode.SRC_IN);
+        }
+    }
+
     /**
      * Returns desired art height to fit into controller dialog.
      */
@@ -727,6 +740,8 @@
             if (v == null) {
                 v = LayoutInflater.from(getContext()).inflate(
                         R.layout.mr_controller_volume_item, null);
+                setVolumeSliderColor(
+                        (SeekBar) v.findViewById(R.id.mr_volume_slider), mVolumeSliderColor);
             }
             MediaRouter.RouteInfo route = getItem(position);
             if (route != null) {
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java b/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java
index c881357..ee6a3da 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java
@@ -30,16 +30,16 @@
     public static Context createThemedContext(Context context) {
         int style;
         if (isLightTheme(context)) {
-            if (isPrimaryColorDark(context)) {
-                style = R.style.Theme_MediaRouter_Light_DarkControlPanel;
-            } else {
+            if (isPrimaryColorLight(context)) {
                 style = R.style.Theme_MediaRouter_Light;
+            } else {
+                style = R.style.Theme_MediaRouter_Light_DarkControlPanel;
             }
         } else {
-            if (isPrimaryColorDark(context)) {
-                style = R.style.Theme_MediaRouter;
-            } else {
+            if (isPrimaryColorLight(context)) {
                 style = R.style.Theme_MediaRouter_LightControlPanel;
+            } else {
+                style = R.style.Theme_MediaRouter;
             }
         }
         return new ContextThemeWrapper(context, style);
@@ -55,16 +55,20 @@
         return res != 0 ? context.getResources().getDrawable(res) : null;
     }
 
+    public static int getVolumeSliderColor(Context context) {
+        return isPrimaryColorLight(context) ? Color.BLACK : Color.WHITE;
+    }
+
     private static boolean isLightTheme(Context context) {
         TypedValue value = new TypedValue();
         return context.getTheme().resolveAttribute(R.attr.isLightTheme, value, true)
                 && value.data != 0;
     }
 
-    private static boolean isPrimaryColorDark(Context context) {
+    private static boolean isPrimaryColorLight(Context context) {
         TypedValue value = new TypedValue();
         context.getTheme().resolveAttribute(R.attr.colorPrimary, value, true);
-        return luminance(value.data) < 0.5;
+        return luminance(value.data) >= 0.5;
     }
 
     private static float luminance(int color) {