MediaRouter: Set the maxHeight value manually for ListView

maxHeight does not work for ListView. Setting the value manually.
Reference:
https://groups.google.com/forum/#!topic/android-developers/5m5F3uA2OaQ

Bug: 23866372
Change-Id: Ic10b889b9648e44a296376bd17a828032ac9ccdb
diff --git a/v7/mediarouter/res/layout/mr_controller_material_dialog_b.xml b/v7/mediarouter/res/layout/mr_controller_material_dialog_b.xml
index 4e1d927..9d1c412 100644
--- a/v7/mediarouter/res/layout/mr_controller_material_dialog_b.xml
+++ b/v7/mediarouter/res/layout/mr_controller_material_dialog_b.xml
@@ -79,7 +79,6 @@
             <ListView android:id="@+id/mr_volume_group_list"
                       android:layout_width="fill_parent"
                       android:layout_height="wrap_content"
-                      android:maxHeight="256dp"
                       android:background="?attr/colorPrimaryDark"
                       android:visibility="gone" />
         </LinearLayout>
diff --git a/v7/mediarouter/res/values/dimens.xml b/v7/mediarouter/res/values/dimens.xml
index 696c9c2..24585c0 100644
--- a/v7/mediarouter/res/values/dimens.xml
+++ b/v7/mediarouter/res/values/dimens.xml
@@ -21,4 +21,5 @@
     <!-- The platform's desired fixed width for a dialog along the minor axis
          (the screen is in portrait). This may be either a fraction or a dimension.-->
     <dimen name="mr_dialog_fixed_width_minor">320dp</dimen>
+    <dimen name="mr_controller_volume_group_list_max_height">256dp</dimen>
 </resources>
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
index acf3512..b382d60 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
@@ -357,6 +357,10 @@
                     mVolumeGroupList.setVisibility(View.VISIBLE);
                     mVolumeGroupList.setAdapter(
                             new VolumeGroupAdapter(getContext(), getGroup().getRoutes()));
+                    ViewGroup.LayoutParams lp = mVolumeGroupList.getLayoutParams();
+                    lp.height = MediaRouteDialogHelper.getControllerVolumeGroupListHeight(
+                            getContext(), mVolumeGroupList.getAdapter().getCount());
+                    mVolumeGroupList.setLayoutParams(lp);
                 } else {
                     mGroupExpandCollapseButton.setImageDrawable(expandGroupDrawable);
                     mVolumeGroupList.setVisibility(View.GONE);
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteDialogHelper.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteDialogHelper.java
index 57f038a..be2e9e1 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteDialogHelper.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteDialogHelper.java
@@ -21,12 +21,13 @@
 import android.util.DisplayMetrics;
 import android.util.TypedValue;
 import android.view.ViewGroup;
+import android.widget.LinearLayout;
 
-/**
- * The framework should set the dialog width properly, but somehow it doesn't work, hence
- * duplicating a similar logic here to determine the appropriate dialog width.
- */
 final class MediaRouteDialogHelper {
+    /**
+     * The framework should set the dialog width properly, but somehow it doesn't work, hence
+     * duplicating a similar logic here to determine the appropriate dialog width.
+     */
     public static int getDialogWidth(Context context) {
         DisplayMetrics metrics = context.getResources().getDisplayMetrics();
         boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
@@ -41,4 +42,15 @@
         }
         return ViewGroup.LayoutParams.WRAP_CONTENT;
     }
+
+    /**
+     * Returns the height of the volume group list in the controller dialog.
+     */
+    public static int getControllerVolumeGroupListHeight(Context context, int itemCount) {
+        if (itemCount >= 4) {
+            return context.getResources().getDimensionPixelSize(
+                    R.dimen.mr_controller_volume_group_list_max_height);
+        }
+        return LinearLayout.LayoutParams.WRAP_CONTENT;
+    }
 }