MediaRouter: Fix the unmatched color issue in MRCD

The theme of MediaRouteControllerDialog(MRCD) should be determined based
on the 'colorPrimary' value of the current dialog theme because the
value will be used as a background color. However, current
implementation retrieves 'colorPrimary' value from the current context
but not the dialog theme, causing the unmatched color issue between text
color and background color. This change pre-evaluates dialog theme to
make the MRCD have the right theme.

Bug: 25731047
Change-Id: I68b968fe0b03c2602f4c776d6c5682bc0c1b7b89
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
index 3fb69c7..2900e37 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
@@ -195,7 +195,8 @@
     }
 
     public MediaRouteControllerDialog(Context context, int theme) {
-        super(MediaRouterThemeHelper.createThemedContext(context, theme), theme);
+        super(MediaRouterThemeHelper.createThemedContext(context,
+                MediaRouterThemeHelper.getAlertDialogResolvedTheme(context, theme)), theme);
         mContext = getContext();
 
         mControllerCallback = new MediaControllerCallback();
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java b/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java
index 3d55951..e129dd7 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouterThemeHelper.java
@@ -137,6 +137,18 @@
         volumeSlider.setColor(controllerColor);
     }
 
+    // This is copied from {@link AlertDialog#resolveDialogTheme} to pre-evaluate theme in advance.
+    public static int getAlertDialogResolvedTheme(Context context, int themeResId) {
+        if (themeResId >= 0x01000000) {   // start of real resource IDs.
+            return themeResId;
+        } else {
+            TypedValue outValue = new TypedValue();
+            context.getTheme().resolveAttribute(
+                    android.support.v7.appcompat.R.attr.alertDialogTheme, outValue, true);
+            return outValue.resourceId;
+        }
+    }
+
     private static boolean isLightTheme(Context context) {
         TypedValue value = new TypedValue();
         return context.getTheme().resolveAttribute(