MediaRouter: Use volume slider thumb provided by AppCompatSeekBar

Appcompat uses its own thumb only for pre-API 21 (Lollipop, before
material) which doesn't have touch animation support while material has
it. Follow AppCompatSeekBar to keep consistency.

After this CL, disabled volume sliders may look differently per API
levels.

Bug: 24212201, Bug: 24553329
Change-Id: I1eca61baf735246f38db5f5b1bff5354c88ff407
diff --git a/v7/mediarouter/res/drawable/mr_seekbar_thumb.xml b/v7/mediarouter/res/drawable/mr_seekbar_thumb.xml
deleted file mode 100644
index dc1a194..0000000
--- a/v7/mediarouter/res/drawable/mr_seekbar_thumb.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?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.
--->
-
-<selector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:constantSize="true">
-    <!-- Place fake item to keep the ripple animation size which is determined by thumb's size. -->
-    <item android:state_enabled="false" android:state_pressed="true">
-        <bitmap android:src="@drawable/abc_scrubber_control_off_mtrl_alpha"
-            android:gravity="center"/>
-    </item>
-    <item android:state_pressed="true">
-        <bitmap android:src="@drawable/abc_scrubber_control_to_pressed_mtrl_005"
-            android:gravity="center" />
-    </item>
-    <item>
-        <bitmap android:src="@drawable/abc_scrubber_control_to_pressed_mtrl_000"
-            android:gravity="center" />
-    </item>
-</selector>
\ No newline at end of file
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
index d235026..629b1f2 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
@@ -894,7 +894,7 @@
                 MediaRouteVolumeSlider volumeSlider =
                         (MediaRouteVolumeSlider) v.findViewById(R.id.mr_volume_slider);
                 volumeSlider.setTag(VOLUME_SLIDER_TAG_BASE + position);
-                volumeSlider.setShowThumb(isEnabled);
+                volumeSlider.setHideThumb(!isEnabled);
                 if (isEnabled) {
                     if (isVolumeControlAvailable(route)) {
                         volumeSlider.setMax(route.getVolumeMax());
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteVolumeSlider.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteVolumeSlider.java
index 7fa2c5c..c5f7a29 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteVolumeSlider.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteVolumeSlider.java
@@ -18,11 +18,8 @@
 
 import android.content.Context;
 import android.content.res.TypedArray;
-import android.graphics.ColorFilter;
 import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
 import android.graphics.drawable.Drawable;
-import android.support.v4.content.ContextCompat;
 import android.support.v7.mediarouter.R;
 import android.support.v7.widget.AppCompatSeekBar;
 import android.util.AttributeSet;
@@ -31,8 +28,9 @@
  * Volume slider with showing, hiding, and applying alpha supports to the thumb.
  */
 class MediaRouteVolumeSlider extends AppCompatSeekBar {
-    private boolean mShowThumb = true;
+    private boolean mHideThumb;
     private Drawable mThumb;
+    private int mColor;
     private float mDisabledAlpha;
 
     public MediaRouteVolumeSlider(Context context) {
@@ -45,32 +43,39 @@
 
     public MediaRouteVolumeSlider(Context context, AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
-        mThumb = ContextCompat.getDrawable(context, R.drawable.mr_seekbar_thumb);
-        setThumb(mThumb);
-        int color = MediaRouterThemeHelper.getControllerColor(context);
-        ColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
-        getProgressDrawable().setColorFilter(colorFilter);
-        mThumb.setColorFilter(colorFilter);
+        mColor = MediaRouterThemeHelper.getControllerColor(context);
         TypedArray ta = context.obtainStyledAttributes(
                 attrs, new int[] {android.R.attr.disabledAlpha}, defStyleAttr, 0);
         mDisabledAlpha = ta.getFloat(0, 0.5f);
         ta.recycle();
     }
 
-    /**
-     * Sets whether to show/hide thumb.
-     */
-    public void setShowThumb(boolean showThumb) {
-        if (mShowThumb == showThumb) {
-            return;
-        }
-        mShowThumb = showThumb;
-        setThumb(mShowThumb ? mThumb : null);
+    @Override
+    public void setThumb(Drawable thumb) {
+        mThumb = thumb;
+        super.setThumb(mHideThumb ? null : mThumb);
     }
 
     @Override
     protected void drawableStateChanged() {
-        mThumb.setAlpha(isEnabled() ? 0xFF : (int)(0xFF * mDisabledAlpha));
         super.drawableStateChanged();
+        int alpha = isEnabled() ? 0xFF : (int)(mDisabledAlpha * 0xFF);
+        getProgressDrawable().setAlpha(alpha);
+        mThumb.setAlpha(alpha);
+        // Thumb drawable is collections of drawables which is changed per state changes.
+        // We need to manually apply color filters whenever the current drawable is changed.
+        getProgressDrawable().setColorFilter(mColor, PorterDuff.Mode.SRC_IN);
+        mThumb.setColorFilter(mColor, PorterDuff.Mode.SRC_IN);
+    }
+
+    /**
+     * Sets whether to show/hide thumb.
+     */
+    public void setHideThumb(boolean hideThumb) {
+        if (mHideThumb == hideThumb) {
+            return;
+        }
+        mHideThumb = hideThumb;
+        super.setThumb(mHideThumb ? null : mThumb);
     }
 }