Revert "MediaRouter: expand group volume section as much as it can"

This reverts commit 99337632f33b74a4f373f1d96c35cc4ca387736e.

Change-Id: I249606d9b41313d46a8af71e9ca6ab9b64f28ac1
diff --git a/local.properties b/local.properties
index 9e6a7bc..8aea008 100644
--- a/local.properties
+++ b/local.properties
@@ -7,5 +7,5 @@
 # Location of the SDK. This is only used by Gradle.
 # For customization when using a Version Control System, please read the
 # header note.
-#Sun Sep 06 19:18:53 PDT 2015
+#Fri Aug 21 16:47:26 KST 2015
 android.dir=../../
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 e1359c6..6092e4c 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/src/android/support/v7/app/MediaRouteControllerDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
index 5088a5d..4b17d40 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
@@ -110,6 +110,7 @@
 
     private FrameLayout mCustomControlLayout;
     private FrameLayout mDefaultControlLayout;
+    private boolean mNeedToAdjustControlFrameLayout = true;
     private ImageView mArtView;
     private TextView mTitleView;
     private TextView mSubtitleView;
@@ -272,6 +273,13 @@
         mCloseButton.setOnClickListener(listener);
         mCustomControlLayout = (FrameLayout) findViewById(R.id.mr_custom_control);
         mDefaultControlLayout = (FrameLayout) findViewById(R.id.mr_default_control);
+        ViewTreeObserver observer = mDefaultControlLayout.getViewTreeObserver();
+        observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+            @Override
+            public void onGlobalLayout() {
+                updateControlFrameLayout();
+            }
+        });
         mArtView = (ImageView) findViewById(R.id.mr_art);
 
         mControlLayout = (LinearLayout) findViewById(R.id.mr_control);
@@ -346,7 +354,7 @@
                     mGroupExpandCollapseButton.setImageDrawable(expandGroupDrawable);
                     mVolumeGroupList.setVisibility(View.GONE);
                 }
-                updateControlFrameLayout();
+                mNeedToAdjustControlFrameLayout = true;
             }
         });
 
@@ -356,7 +364,6 @@
             mCustomControlLayout.setVisibility(View.VISIBLE);
             mArtView.setVisibility(View.GONE);
         }
-        mOrientation = res.getConfiguration().orientation;
 
         mCreated = true;
         update();
@@ -394,7 +401,6 @@
         mDisconnectButton.setLayoutParams(lp);
 
         updateArtView();
-        updateControlFrameLayout();
     }
 
     @Override
@@ -552,27 +558,27 @@
     }
 
     private void updateControlFrameLayout() {
+        if (!mNeedToAdjustControlFrameLayout) {
+            return;
+        }
         int height;
         if (mArtView.getVisibility() == View.GONE) {
             height = LinearLayout.LayoutParams.WRAP_CONTENT;
+        } else if (!mIsGroupExpanded) {
+            height = mArtView.getHeight() + mControlLayout.getHeight();
         } else {
-            measureDecorView();
-            if (!mIsGroupExpanded) {
-                height = mArtView.getMeasuredHeight() + mControlLayout.getMeasuredHeight();
+            if (mVolumeGroupList.getAdapter().getCount() <= 2) {
+                // Push the controls up and cover the artwork.
+                height = mArtView.getHeight() + mControlLayout.getHeight()
+                        - mVolumeGroupList.getHeight();
             } else {
-                if (mVolumeGroupList.getAdapter().getCount() <= 2
-                        && mArtView.getMeasuredHeight() > mVolumeGroupList.getMeasuredHeight()) {
-                    // Push the controls up and partially cover the artwork.
-                    height = mArtView.getMeasuredHeight() + mControlLayout.getMeasuredHeight()
-                            - mVolumeGroupList.getMeasuredHeight();
-                } else {
-                    // Completely cover the artwork.
-                    height = LinearLayout.LayoutParams.WRAP_CONTENT;
-                }
+                // If there are 3 or more, the controls completely cover the artwork.
+                height = mControlLayout.getHeight();
             }
         }
-        mDefaultControlLayout.setLayoutParams(new LinearLayout.LayoutParams(
-                LinearLayout.LayoutParams.FILL_PARENT, height));
+        mDefaultControlLayout.setLayoutParams(
+                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, height));
+        mNeedToAdjustControlFrameLayout = false;
     }
 
     private boolean isVolumeControlAvailable() {
@@ -580,17 +586,8 @@
                 MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE;
     }
 
-    private View measureDecorView() {
-        DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
-        int dialogWidth = mOrientation == Configuration.ORIENTATION_LANDSCAPE
-                ? mDialogWidthLandscape : mDialogWidthPortrait;
-        View decorView = getWindow().getDecorView();
-        int widthMeasureSpec = MeasureSpec.makeMeasureSpec(dialogWidth, MeasureSpec.EXACTLY);
-        decorView.measure(widthMeasureSpec, MeasureSpec.UNSPECIFIED);
-        return decorView;
-    }
-
     private void updateArtView() {
+        mNeedToAdjustControlFrameLayout = true;
         if (!(mArtView.getDrawable() instanceof BitmapDrawable)) {
             mArtView.setVisibility(View.GONE);
             return;
@@ -602,7 +599,11 @@
         }
         int desiredArtHeight = getDesiredArtHeight(art.getWidth(), art.getHeight());
         DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
-        View decorView = measureDecorView();
+        int dialogWidth = displayMetrics.widthPixels < displayMetrics.heightPixels
+                ? mDialogWidthPortrait : mDialogWidthLandscape;
+        View decorView = getWindow().getDecorView();
+        int widthMeasureSpec = MeasureSpec.makeMeasureSpec(dialogWidth, MeasureSpec.EXACTLY);
+        decorView.measure(widthMeasureSpec, MeasureSpec.UNSPECIFIED);
         // Show art if and only if it fits in the screen.
         if (mArtView.getVisibility() == View.GONE) {
             if (decorView.getMeasuredHeight() + desiredArtHeight <= displayMetrics.heightPixels) {
@@ -858,7 +859,6 @@
             mArtView.setImageBitmap(art);
             mArtView.setBackgroundColor(mBackgroundColor);
             updateArtView();
-            updateControlFrameLayout();
         }
     }
 }