MediaRouter: Use the bluetooth icon for bluetooth audio devices

Bug: 23116379
Change-Id: I851770d578ce2c4e30e829f7a2d65b27ca50384e
diff --git a/v7/mediarouter/res/drawable-hdpi/ic_bluetooth_grey.png b/v7/mediarouter/res/drawable-hdpi/ic_bluetooth_grey.png
new file mode 100644
index 0000000..0493c80
--- /dev/null
+++ b/v7/mediarouter/res/drawable-hdpi/ic_bluetooth_grey.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-hdpi/ic_bluetooth_white.png b/v7/mediarouter/res/drawable-hdpi/ic_bluetooth_white.png
new file mode 100644
index 0000000..fce1884
--- /dev/null
+++ b/v7/mediarouter/res/drawable-hdpi/ic_bluetooth_white.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-mdpi/ic_bluetooth_grey.png b/v7/mediarouter/res/drawable-mdpi/ic_bluetooth_grey.png
new file mode 100644
index 0000000..ddc8789
--- /dev/null
+++ b/v7/mediarouter/res/drawable-mdpi/ic_bluetooth_grey.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-mdpi/ic_bluetooth_white.png b/v7/mediarouter/res/drawable-mdpi/ic_bluetooth_white.png
new file mode 100644
index 0000000..27a8a71
--- /dev/null
+++ b/v7/mediarouter/res/drawable-mdpi/ic_bluetooth_white.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xhdpi/ic_bluetooth_grey.png b/v7/mediarouter/res/drawable-xhdpi/ic_bluetooth_grey.png
new file mode 100644
index 0000000..c57b9d6
--- /dev/null
+++ b/v7/mediarouter/res/drawable-xhdpi/ic_bluetooth_grey.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xhdpi/ic_bluetooth_white.png b/v7/mediarouter/res/drawable-xhdpi/ic_bluetooth_white.png
new file mode 100644
index 0000000..920f5ca
--- /dev/null
+++ b/v7/mediarouter/res/drawable-xhdpi/ic_bluetooth_white.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xxhdpi/ic_bluetooth_grey.png b/v7/mediarouter/res/drawable-xxhdpi/ic_bluetooth_grey.png
new file mode 100644
index 0000000..8e9aa70
--- /dev/null
+++ b/v7/mediarouter/res/drawable-xxhdpi/ic_bluetooth_grey.png
Binary files differ
diff --git a/v7/mediarouter/res/drawable-xxhdpi/ic_bluetooth_white.png b/v7/mediarouter/res/drawable-xxhdpi/ic_bluetooth_white.png
new file mode 100644
index 0000000..860c758
--- /dev/null
+++ b/v7/mediarouter/res/drawable-xxhdpi/ic_bluetooth_white.png
Binary files differ
diff --git a/v7/mediarouter/res/values/attrs.xml b/v7/mediarouter/res/values/attrs.xml
index fe01948..3a5f333 100644
--- a/v7/mediarouter/res/values/attrs.xml
+++ b/v7/mediarouter/res/values/attrs.xml
@@ -38,6 +38,7 @@
     <attr name="mediaRouteDefaultIconDrawable" format="reference" />
     <attr name="mediaRouteSpeakerIconDrawable" format="reference" />
     <attr name="mediaRouteSpeakerGroupIconDrawable" format="reference" />
+    <attr name="mediaRouteBluetoothIconDrawable" format="reference" />
     <attr name="mediaRouteChooserPrimaryTextStyle" format="reference" />
     <attr name="mediaRouteChooserSecondaryTextStyle" format="reference" />
     <attr name="mediaRouteControllerTitleTextStyle" format="reference" />
diff --git a/v7/mediarouter/res/values/themes.xml b/v7/mediarouter/res/values/themes.xml
index 490e04e..da21998 100644
--- a/v7/mediarouter/res/values/themes.xml
+++ b/v7/mediarouter/res/values/themes.xml
@@ -31,6 +31,7 @@
         <item name="mediaRouteDefaultIconDrawable">@drawable/ic_tv_dark</item>
         <item name="mediaRouteSpeakerIconDrawable">@drawable/ic_speaker_dark</item>
         <item name="mediaRouteSpeakerGroupIconDrawable">@drawable/ic_speaker_group_dark</item>
+        <item name="mediaRouteBluetoothIconDrawable">@drawable/ic_bluetooth_white</item>
         <item name="mediaRouteChooserPrimaryTextStyle">@style/Widget.MediaRouter.ChooserText.Primary.Dark</item>
         <item name="mediaRouteChooserSecondaryTextStyle">@style/Widget.MediaRouter.ChooserText.Secondary.Dark</item>
         <item name="mediaRouteControllerTitleTextStyle">@style/Widget.MediaRouter.ControllerText.Title.Dark</item>
@@ -54,6 +55,7 @@
         <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>
+        <item name="mediaRouteBluetoothIconDrawable">@drawable/ic_bluetooth_grey</item>
         <item name="mediaRouteChooserPrimaryTextStyle">@style/Widget.MediaRouter.ChooserText.Primary.Light</item>
         <item name="mediaRouteChooserSecondaryTextStyle">@style/Widget.MediaRouter.ChooserText.Secondary.Light</item>
         <item name="mediaRouteControllerTitleTextStyle">@style/Widget.MediaRouter.ControllerText.Title.Light</item>
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java
index 8b5d6fc..b1e3d82 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteChooserDialog.java
@@ -65,6 +65,9 @@
 public class MediaRouteChooserDialog extends Dialog {
     private static final String TAG = "MediaRouteChooserDialog";
 
+    // Should match to SystemMediaRouteProvider.PACKAGE_NAME.
+    static final String SYSTEM_MEDIA_ROUTE_PROVIDER_PACKAGE_NAME = "android";
+
     private final MediaRouter mRouter;
     private final MediaRouterCallback mCallback;
 
@@ -203,6 +206,7 @@
         private final Drawable mDefaultIcon;
         private final Drawable mSpeakerIcon;
         private final Drawable mSpeakerGroupIcon;
+        private final Drawable mBluetoothIcon;
 
         public RouteAdapter(Context context, List<MediaRouter.RouteInfo> routes) {
             super(context, 0, routes);
@@ -210,10 +214,12 @@
             TypedArray styledAttributes = getContext().obtainStyledAttributes(new int[] {
                     R.attr.mediaRouteDefaultIconDrawable,
                     R.attr.mediaRouteSpeakerIconDrawable,
-                    R.attr.mediaRouteSpeakerGroupIconDrawable });
+                    R.attr.mediaRouteSpeakerGroupIconDrawable,
+                    R.attr.mediaRouteBluetoothIconDrawable });
             mDefaultIcon = styledAttributes.getDrawable(0);
             mSpeakerIcon = styledAttributes.getDrawable(1);
             mSpeakerGroupIcon = styledAttributes.getDrawable(2);
+            mBluetoothIcon = styledAttributes.getDrawable(3);
             styledAttributes.recycle();
         }
 
@@ -292,6 +298,9 @@
                 // Only speakers can be grouped for now.
                 return mSpeakerGroupIcon;
             }
+            if (isSystemLiveAudioOnlyRoute(route)) {
+                return mBluetoothIcon;
+            }
             if (route.supportsControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
                     && !route.supportsControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)) {
                 return mSpeakerIcon;
@@ -331,9 +340,6 @@
         private static final float MIN_USAGE_SCORE = 0.1f;
         private static final float USAGE_SCORE_DECAY_FACTOR = 0.95f;
 
-        // Should match to SystemMediaRouteProvider.PACKAGE_NAME.
-        static final String SYSTEM_MEDIA_ROUTE_PROVIDER_PACKAGE_NAME = "android";
-
         public static final RouteComparator sInstance = new RouteComparator();
         public static final HashMap<String, Float> sRouteUsageScoreMap = new HashMap();
 
@@ -360,17 +366,6 @@
             return lhs.getName().compareTo(rhs.getName());
         }
 
-        private boolean isSystemLiveAudioOnlyRoute(MediaRouter.RouteInfo route) {
-            return isSystemMediaRouteProvider(route)
-                    && route.supportsControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
-                    && !route.supportsControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO);
-        }
-
-        private boolean isSystemMediaRouteProvider(MediaRouter.RouteInfo route) {
-            return TextUtils.equals(route.getProviderInstance().getMetadata().getPackageName(),
-                    SYSTEM_MEDIA_ROUTE_PROVIDER_PACKAGE_NAME);
-        }
-
         private static void loadRouteUsageScores(
                 Context context, List<MediaRouter.RouteInfo> routes) {
             sRouteUsageScoreMap.clear();
@@ -415,4 +410,17 @@
             prefEditor.commit();
         }
     }
+
+    // Used to determine whether the route represents a bluetooth device.
+    // TODO: Find a better way to precisely detect bluetooth routes.
+    private static boolean isSystemLiveAudioOnlyRoute(MediaRouter.RouteInfo route) {
+        return isSystemMediaRouteProvider(route)
+                && route.supportsControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
+                && !route.supportsControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO);
+    }
+
+    private static boolean isSystemMediaRouteProvider(MediaRouter.RouteInfo route) {
+        return TextUtils.equals(route.getProviderInstance().getMetadata().getPackageName(),
+                SYSTEM_MEDIA_ROUTE_PROVIDER_PACKAGE_NAME);
+    }
 }