MediaRouter: Scale down group member icon size in landscape mode

Bug: 23942540
Change-Id: Id0290eac3c0364c03ae395474b092544ab8a02cb
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 d58a451..0a07a92 100644
--- a/v7/mediarouter/res/layout/mr_controller_material_dialog_b.xml
+++ b/v7/mediarouter/res/layout/mr_controller_material_dialog_b.xml
@@ -80,6 +80,9 @@
             <ListView android:id="@+id/mr_volume_group_list"
                       android:layout_width="fill_parent"
                       android:layout_height="wrap_content"
+                      android:paddingTop="@dimen/mr_controller_volume_group_list_padding_top"
+                      android:scrollbarStyle="outsideInset"
+                      android:clipToPadding="false"
                       android:background="?attr/colorPrimaryDark"
                       android:visibility="gone" />
         </LinearLayout>
diff --git a/v7/mediarouter/res/layout/mr_controller_volume_item.xml b/v7/mediarouter/res/layout/mr_controller_volume_item.xml
index 36f7878..6cd0fd6 100644
--- a/v7/mediarouter/res/layout/mr_controller_volume_item.xml
+++ b/v7/mediarouter/res/layout/mr_controller_volume_item.xml
@@ -19,7 +19,7 @@
               android:layout_height="@dimen/mr_controller_volume_group_list_item_height"
               android:paddingLeft="24dp"
               android:paddingRight="60dp"
-              android:paddingTop="16dp"
+              android:paddingBottom="8dp"
               android:orientation="vertical" >
     <TextView android:id="@+id/mr_name"
               android:layout_width="wrap_content"
@@ -28,12 +28,14 @@
               android:singleLine="true" />
     <LinearLayout android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
-                  android:layout_marginTop="8dp"
                   android:orientation="horizontal"
                   android:gravity="center_vertical">
         <ImageView android:id="@+id/mr_volume_item_icon"
-                   android:layout_width="24dp"
-                   android:layout_height="24dp"
+                   android:layout_width="@dimen/mr_controller_volume_group_list_item_icon_size"
+                   android:layout_height="@dimen/mr_controller_volume_group_list_item_icon_size"
+                   android:layout_marginTop="8dp"
+                   android:layout_marginBottom="8dp"
+                   android:scaleType="fitCenter"
                    android:src="?attr/mediaRouteAudioTrackDrawable" />
         <android.support.v7.app.MediaRouteVolumeSlider android:id="@+id/mr_volume_slider"
                  android:layout_width="fill_parent"
diff --git a/v7/mediarouter/res/values-land/dimens.xml b/v7/mediarouter/res/values-land/dimens.xml
index 0f0e5a1..ee606aa 100644
--- a/v7/mediarouter/res/values-land/dimens.xml
+++ b/v7/mediarouter/res/values-land/dimens.xml
@@ -15,6 +15,12 @@
 -->
 
 <resources>
-    <!-- Maximum height of MediaRouteController's volume group list. -->
+    <!-- MediaRouteController's volume group list -->
+    <eat-comment />
+    <!-- Maximum height of volume group list. -->
     <dimen name="mr_controller_volume_group_list_max_height">132dp</dimen>
+    <!-- Height of volume group item. -->
+    <dimen name="mr_controller_volume_group_list_item_height">61dp</dimen>
+    <!-- Size of an item's icon. -->
+    <dimen name="mr_controller_volume_group_list_item_icon_size">18dp</dimen>
 </resources>
diff --git a/v7/mediarouter/res/values/dimens.xml b/v7/mediarouter/res/values/dimens.xml
index 77656f4..af413a3 100644
--- a/v7/mediarouter/res/values/dimens.xml
+++ b/v7/mediarouter/res/values/dimens.xml
@@ -15,6 +15,8 @@
 -->
 
 <resources>
+    <!-- Dialog size -->
+    <eat-comment />
     <!-- The platform's desired fixed width for a dialog along the major axis
          (the screen is in landscape). This may be either a fraction or a dimension.-->
     <dimen name="mr_dialog_fixed_width_major">320dp</dimen>
@@ -22,11 +24,14 @@
          (the screen is in portrait). This may be either a fraction or a dimension.-->
     <dimen name="mr_dialog_fixed_width_minor">320dp</dimen>
 
-    <!-- Maximum height of MediaRouteController's volume group list. -->
+    <!-- MediaRouteController's volume group list -->
+    <eat-comment />
+    <!-- Maximum height of volume group list. -->
     <dimen name="mr_controller_volume_group_list_max_height">256dp</dimen>
-    <!-- Height of MediaRouteController's volume group item.
-         TODO: Define value for landscape once we know how to adjust SeekBar height. -->
-    <dimen name="mr_controller_volume_group_list_item_height">75dp</dimen>
+    <!-- Height of volume group item. -->
+    <dimen name="mr_controller_volume_group_list_item_height">67dp</dimen>
+    <!-- Size of an item's icon. -->
+    <dimen name="mr_controller_volume_group_list_item_icon_size">24dp</dimen>
 
-    <dimen name="mr_controller_volume_group_list_padding_bottom">8dp</dimen>
+    <dimen name="mr_controller_volume_group_list_padding_top">16dp</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 71bf05b..fea1bcd 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
@@ -20,6 +20,7 @@
 
 import android.content.ContentResolver;
 import android.content.Context;
+import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -124,9 +125,10 @@
     private ListView mVolumeGroupList;
     private SeekBar mVolumeSlider;
     private boolean mVolumeSliderTouched;
-    private final int mVolumeGroupListItemHeight;
-    private final int mVolumeGroupListMaxHeight;
-    private final int mVolumeGroupListPaddingBottom;
+    private int mVolumeGroupListItemIconSize;
+    private int mVolumeGroupListItemHeight;
+    private int mVolumeGroupListMaxHeight;
+    private final int mVolumeGroupListPaddingTop;
 
     private MediaControllerCompat mMediaController;
     private MediaControllerCallback mControllerCallback;
@@ -151,12 +153,8 @@
         mCallback = new MediaRouterCallback();
         mRoute = mRouter.getSelectedRoute();
         setMediaSession(mRouter.getMediaSessionToken());
-        mVolumeGroupListItemHeight = context.getResources().getDimensionPixelSize(
-                R.dimen.mr_controller_volume_group_list_item_height);
-        mVolumeGroupListMaxHeight = context.getResources().getDimensionPixelSize(
-                R.dimen.mr_controller_volume_group_list_max_height);
-        mVolumeGroupListPaddingBottom = context.getResources().getDimensionPixelSize(
-                R.dimen.mr_controller_volume_group_list_padding_bottom);
+        mVolumeGroupListPaddingTop = context.getResources().getDimensionPixelSize(
+                R.dimen.mr_controller_volume_group_list_padding_top);
     }
 
     /**
@@ -394,6 +392,14 @@
         View decorView = getWindow().getDecorView();
         mDialogContentWidth = width - decorView.getPaddingLeft() - decorView.getPaddingRight();
 
+        Resources res = getContext().getResources();
+        mVolumeGroupListItemIconSize = res.getDimensionPixelSize(
+                R.dimen.mr_controller_volume_group_list_item_icon_size);
+        mVolumeGroupListItemHeight = res.getDimensionPixelSize(
+                R.dimen.mr_controller_volume_group_list_item_height);
+        mVolumeGroupListMaxHeight = res.getDimensionPixelSize(
+                R.dimen.mr_controller_volume_group_list_max_height);
+
         // Ensure the mArtView is updated.
         mArtIconBitmap = null;
         mArtIconUri = null;
@@ -533,8 +539,17 @@
         int mainControllerHeight = getMainControllerHeight(isPlaybackControlAvailable());
         int volumeGroupListCount = mVolumeGroupList.getVisibility() == View.VISIBLE
                 ? mVolumeGroupList.getAdapter().getCount() : 0;
+        // Scale down volume group list items in landscape mode.
+        for (int i = 0; i < volumeGroupListCount; i++) {
+            View item = mVolumeGroupList.getChildAt(i);
+            if (item != null) {
+                setLayoutHeight(item, mVolumeGroupListItemHeight);
+                setLayoutHeight(item.findViewById(R.id.mr_volume_item_icon),
+                        mVolumeGroupListItemIconSize);
+            }
+        }
         int volumeGroupHeight = (volumeGroupListCount == 0) ? 0
-                : mVolumeGroupListItemHeight * volumeGroupListCount + mVolumeGroupListPaddingBottom;
+                : mVolumeGroupListItemHeight * volumeGroupListCount + mVolumeGroupListPaddingTop;
         volumeGroupHeight = Math.min(volumeGroupHeight, mVolumeGroupListMaxHeight);
 
         int desiredControlLayoutHeight =
@@ -790,7 +805,6 @@
                 v = LayoutInflater.from(getContext()).inflate(
                         R.layout.mr_controller_volume_item, parent, false);
             }
-            setViewPaddingBottom(v, position == getCount() - 1 ? mVolumeGroupListPaddingBottom : 0);
 
             MediaRouter.RouteInfo route = getItem(position);
             if (route != null) {
@@ -826,21 +840,6 @@
         }
     }
 
-    private static void setViewPaddingBottom(View view, int newBottom) {
-        int left = view.getPaddingLeft();
-        int top = view.getPaddingTop();
-        int right = view.getPaddingRight();
-        int bottom = view.getPaddingBottom();
-        view.setPadding(left, top, right, newBottom);
-
-        ViewGroup.LayoutParams lp = view.getLayoutParams();
-        if (lp.height != ViewGroup.LayoutParams.FILL_PARENT
-                && lp.height != ViewGroup.LayoutParams.WRAP_CONTENT) {
-            lp.height = lp.height - bottom + newBottom;
-            view.setLayoutParams(lp);
-        }
-    }
-
     private class FetchArtTask extends AsyncTask<Void, Void, Bitmap> {
         final Bitmap mIconBitmap;
         final Uri mIconUri;