Remove MediaRouteControlHelper class

MediaRouteControlHelper is a kind of temporary class created while changing
the type of the control view from ListView to LinearLayout.
Thic CL also contains the change of namings.

Change-Id: I9df6477b1fd32ecd8301ba2bd1ff678e464f797e
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 edc253b..8362fd7 100644
--- a/v7/mediarouter/res/layout/mr_controller_material_dialog_b.xml
+++ b/v7/mediarouter/res/layout/mr_controller_material_dialog_b.xml
@@ -18,13 +18,13 @@
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:orientation="vertical">
-    <LinearLayout android:id="@+id/title_bar"
+    <LinearLayout android:id="@+id/mr_title_bar"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:paddingLeft="24dp"
                   android:paddingRight="24dp"
                   android:orientation="horizontal" >
-        <TextView android:id="@+id/route_name"
+        <TextView android:id="@+id/mr_name"
                   android:layout_width="0dp"
                   android:layout_height="72dp"
                   android:layout_weight="1"
@@ -32,7 +32,7 @@
                   android:singleLine="true"
                   android:ellipsize="end"
                   android:textAppearance="?attr/mediaRouteControllerTitleTextStyle" />
-        <ImageButton android:id="@+id/close"
+        <ImageButton android:id="@+id/mr_close"
                      android:layout_width="24dp"
                      android:layout_height="24dp"
                      android:layout_marginLeft="12dp"
@@ -41,7 +41,7 @@
                      android:src="?attr/mediaRouteCloseDrawable"
                      android:background="?attr/selectableItemBackgroundBorderless" />
     </LinearLayout>
-    <FrameLayout android:id="@+id/custom_control_frame"
+    <FrameLayout android:id="@+id/mr_custom_control"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:visibility="gone" />
@@ -74,11 +74,11 @@
               android:layout_height="wrap_content"
               android:background="?attr/colorPrimaryDark"
               android:visibility="gone" />
-    <LinearLayout android:id="@+id/buttons"
+    <LinearLayout android:id="@+id/mr_buttons"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:orientation="horizontal">
-        <Button android:id="@+id/disconnect"
+        <Button android:id="@+id/mr_button_disconnect"
                 android:layout_width="0dp"
                 android:layout_height="48dp"
                 android:gravity="center"
@@ -86,7 +86,7 @@
                 android:background="?attr/selectableItemBackgroundBorderless"
                 android:text="@string/mr_controller_disconnect"
                 android:visibility="invisible" />
-        <Button android:id="@+id/stop"
+        <Button android:id="@+id/mr_button_stop"
                 android:layout_width="0dp"
                 android:layout_height="48dp"
                 android:gravity="center"
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
index d78af8f..c856c1a 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
@@ -97,16 +97,25 @@
 
     private Button mDisconnectButton;
     private Button mStopCastingButton;
+    private ImageButton mPlayPauseButton;
     private ImageButton mCloseButton;
+    private ImageButton mGroupExpandCollapseButton;
 
-    private FrameLayout mCustomControlFrame;
+    private FrameLayout mCustomControlLayout;
     private ImageView mArtView;
+    private TextView mTitleView;
+    private TextView mSubtitleView;
     private TextView mRouteNameTextView;
 
     private boolean mVolumeControlEnabled = true;
-    private LinearLayout mControlView;
-    private MediaRouteControlHelper mControlHelper;
+    private LinearLayout mControlLayout;
+    private RelativeLayout mPlaybackControl;
+    private LinearLayout mVolumeControl;
+    private View mDividerView;
+
     private ListView mVolumeGroupList;
+    private SeekBar mVolumeSlider;
+    private boolean mVolumeSliderTouched;
 
     private MediaControllerCompat mMediaController;
     private MediaControllerCallback mControllerCallback;
@@ -176,7 +185,7 @@
         if (mVolumeControlEnabled != enable) {
             mVolumeControlEnabled = enable;
             if (mCreated) {
-                mControlHelper.updateVolumeControl();
+                updateVolumeControl();
             }
         }
     }
@@ -247,28 +256,98 @@
 
         ClickListener listener = new ClickListener();
 
-        mDisconnectButton = (Button) findViewById(R.id.disconnect);
+        mDisconnectButton = (Button) findViewById(R.id.mr_button_disconnect);
         mDisconnectButton.setOnClickListener(listener);
 
-        mStopCastingButton = (Button) findViewById(R.id.stop);
+        mStopCastingButton = (Button) findViewById(R.id.mr_button_stop);
         mStopCastingButton.setOnClickListener(listener);
 
-        mRouteNameTextView = (TextView) findViewById(R.id.route_name);
-        mCloseButton = (ImageButton) findViewById(R.id.close);
+        mRouteNameTextView = (TextView) findViewById(R.id.mr_name);
+        mCloseButton = (ImageButton) findViewById(R.id.mr_close);
         mCloseButton.setOnClickListener(listener);
-
-        mCustomControlFrame = (FrameLayout) findViewById(R.id.custom_control_frame);
+        mCustomControlLayout = (FrameLayout) findViewById(R.id.mr_custom_control);
         mArtView = (ImageView) findViewById(R.id.mr_art);
 
-        mControlView = (LinearLayout) findViewById(R.id.mr_control);
-        mControlHelper = new MediaRouteControlHelper(listener);
+        mControlLayout = (LinearLayout) findViewById(R.id.mr_control);
+        mDividerView = findViewById(R.id.mr_control_divider);
+
+        mPlaybackControl = (RelativeLayout) findViewById(R.id.mr_playback_control);
+        mTitleView = (TextView) findViewById(R.id.mr_control_title);
+        mSubtitleView = (TextView) findViewById(R.id.mr_control_subtitle);
+        mPlayPauseButton = (ImageButton) findViewById(R.id.mr_control_play_pause);
+        mPlayPauseButton.setOnClickListener(listener);
+
+        mVolumeControl = (LinearLayout) findViewById(R.id.mr_volume_control);
+        mVolumeSlider = (SeekBar) findViewById(R.id.mr_volume_slider);
+        mVolumeSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+            private final Runnable mStopTrackingTouch = new Runnable() {
+                @Override
+                public void run() {
+                    if (mVolumeSliderTouched) {
+                        mVolumeSliderTouched = false;
+                        updateVolumeControl();
+                    }
+                }
+            };
+
+            @Override
+            public void onStartTrackingTouch(SeekBar seekBar) {
+                if (mVolumeSliderTouched) {
+                    mVolumeSlider.removeCallbacks(mStopTrackingTouch);
+                } else {
+                    mVolumeSliderTouched = true;
+                }
+            }
+
+            @Override
+            public void onStopTrackingTouch(SeekBar seekBar) {
+                // Defer resetting mVolumeSliderTouched to allow the media route provider
+                // a little time to settle into its new state and publish the final
+                // volume update.
+                mVolumeSlider.postDelayed(mStopTrackingTouch, VOLUME_UPDATE_DELAY_MILLIS);
+            }
+
+            @Override
+            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+                if (fromUser) {
+                    mRoute.requestSetVolume(progress);
+                }
+            }
+        });
+
+        TypedArray styledAttributes = getContext().obtainStyledAttributes(new int[] {
+                R.attr.mediaRouteExpandGroupDrawable,
+                R.attr.mediaRouteCollapseGroupDrawable
+        });
+        final Drawable expandGroupDrawable = styledAttributes.getDrawable(0);
+        final Drawable collapseGroupDrawable = styledAttributes.getDrawable(1);
+        styledAttributes.recycle();
+
         mVolumeGroupList = (ListView)findViewById(R.id.mr_volume_group_list);
+        mGroupExpandCollapseButton = (ImageButton) findViewById(R.id.mr_group_expand_collapse);
+        mGroupExpandCollapseButton.setOnClickListener(new View.OnClickListener() {
+            private boolean mIsExpanded;
+
+            @Override
+            public void onClick(View v) {
+                mIsExpanded = !mIsExpanded;
+                if (mIsExpanded) {
+                    mGroupExpandCollapseButton.setImageDrawable(collapseGroupDrawable);
+                    mVolumeGroupList.setVisibility(View.VISIBLE);
+                    mVolumeGroupList.setAdapter(
+                            new VolumeGroupAdapter(getContext(), getGroup().getRoutes()));
+                } else {
+                    mGroupExpandCollapseButton.setImageDrawable(expandGroupDrawable);
+                    mVolumeGroupList.setVisibility(View.GONE);
+                }
+            }
+        });
 
         mCreated = true;
         mCustomControlView = onCreateMediaControlView(savedInstanceState);
         if (mCustomControlView != null) {
-            mCustomControlFrame.addView(mCustomControlView);
-            mCustomControlFrame.setVisibility(View.VISIBLE);
+            mCustomControlLayout.addView(mCustomControlView);
+            mCustomControlLayout.setVisibility(View.VISIBLE);
             mArtView.setVisibility(View.GONE);
         }
         update();
@@ -351,8 +430,103 @@
             mFetchArtTask = new FetchArtTask();
             mFetchArtTask.execute();
         }
-        mControlHelper.updateVolumeControl();
-        mControlHelper.updatePlaybackControl();
+        updateVolumeControl();
+        updatePlaybackControl();
+    }
+
+    private void updateVolumeControl() {
+        if (!mVolumeSliderTouched) {
+            if (isVolumeControlAvailable()) {
+                mVolumeControl.setVisibility(View.VISIBLE);
+                mVolumeSlider.setMax(mRoute.getVolumeMax());
+                mVolumeSlider.setProgress(mRoute.getVolume());
+                if (USE_GROUP) {
+                    if (getGroup() == null) {
+                        mGroupExpandCollapseButton.setVisibility(View.GONE);
+                    } else {
+                        mGroupExpandCollapseButton.setVisibility(View.VISIBLE);
+                        VolumeGroupAdapter adapter =
+                                (VolumeGroupAdapter) mVolumeGroupList.getAdapter();
+                        if (adapter != null) {
+                            adapter.notifyDataSetChanged();
+                        }
+                    }
+                }
+            } else {
+                mVolumeControl.setVisibility(View.GONE);
+            }
+            adjustControlLayoutHeight();
+        }
+    }
+
+    private void updatePlaybackControl() {
+        if (mCustomControlView == null && (mDescription != null || mState != null)) {
+            mPlaybackControl.setVisibility(View.VISIBLE);
+            CharSequence title = mDescription == null ? null : mDescription.getTitle();
+            boolean hasTitle = !TextUtils.isEmpty(title);
+
+            CharSequence subtitle = mDescription == null ? null : mDescription.getSubtitle();
+            boolean hasSubtitle = !TextUtils.isEmpty(subtitle);
+
+            if (!hasTitle && !hasSubtitle) {
+                if (mRoute.getPresentationDisplayId()
+                        != MediaRouter.RouteInfo.PRESENTATION_DISPLAY_ID_NONE) {
+                    // The user is currently casting screen.
+                    mTitleView.setText(R.string.mr_controller_casting_screen);
+                } else {
+                    mTitleView.setText((mState == null
+                            || mState.getState() == PlaybackStateCompat.STATE_NONE)
+                                    ? R.string.mr_controller_no_media_selected
+                                    : R.string.mr_controller_no_info_available);
+                }
+                mTitleView.setEnabled(false);
+                mTitleView.setVisibility(View.VISIBLE);
+                mSubtitleView.setVisibility(View.GONE);
+            } else {
+                mTitleView.setText(title);
+                mTitleView.setEnabled(hasTitle);
+                mTitleView.setVisibility(hasTitle ? View.VISIBLE : View.GONE);
+                mSubtitleView.setText(subtitle);
+                mSubtitleView.setVisibility(hasSubtitle ? View.VISIBLE : View.GONE);
+            }
+            if (mState != null) {
+                boolean isPlaying = mState.getState() == PlaybackStateCompat.STATE_BUFFERING
+                        || mState.getState() == PlaybackStateCompat.STATE_PLAYING;
+                boolean supportsPlay = (mState.getActions() & (PlaybackStateCompat.ACTION_PLAY
+                        | PlaybackStateCompat.ACTION_PLAY_PAUSE)) != 0;
+                boolean supportsPause = (mState.getActions() & (PlaybackStateCompat.ACTION_PAUSE
+                        | PlaybackStateCompat.ACTION_PLAY_PAUSE)) != 0;
+                if (isPlaying && supportsPause) {
+                    mPlayPauseButton.setVisibility(View.VISIBLE);
+                    mPlayPauseButton.setImageResource(MediaRouterThemeHelper.getThemeResource(
+                            getContext(), R.attr.mediaRoutePauseDrawable));
+                    mPlayPauseButton.setContentDescription(getContext().getResources()
+                            .getText(R.string.mr_controller_pause));
+                } else if (!isPlaying && supportsPlay) {
+                    mPlayPauseButton.setVisibility(View.VISIBLE);
+                    mPlayPauseButton.setImageResource(MediaRouterThemeHelper.getThemeResource(
+                            getContext(), R.attr.mediaRoutePlayDrawable));
+                    mPlayPauseButton.setContentDescription(getContext().getResources()
+                            .getText(R.string.mr_controller_play));
+                } else {
+                    mPlayPauseButton.setVisibility(View.GONE);
+                }
+            }
+        } else {
+            mPlaybackControl.setVisibility(View.GONE);
+        }
+        adjustControlLayoutHeight();
+    }
+
+    private void adjustControlLayoutHeight() {
+        // TODO: Adjust the top and bottom padding of the control layout according to the display
+        // height.
+        mDividerView.setVisibility((mVolumeControl.getVisibility() == View.VISIBLE
+                && mPlaybackControl.getVisibility() == View.VISIBLE)
+                ? View.VISIBLE : View.GONE);
+        mControlLayout.setVisibility((mVolumeControl.getVisibility() == View.GONE
+                && mPlaybackControl.getVisibility() == View.GONE)
+                ? View.GONE : View.VISIBLE);
     }
 
     private boolean isVolumeControlAvailable() {
@@ -419,7 +593,7 @@
         @Override
         public void onRouteVolumeChanged(MediaRouter router, MediaRouter.RouteInfo route) {
             if (route == mRoute) {
-                mControlHelper.updateVolumeControl();
+                updateVolumeControl();
             }
         }
     }
@@ -450,9 +624,9 @@
         @Override
         public void onClick(View v) {
             int id = v.getId();
-            if (id == R.id.stop || id == R.id.disconnect) {
+            if (id == R.id.mr_button_stop || id == R.id.mr_button_disconnect) {
                 if (mRoute.isSelected()) {
-                    mRouter.unselect(id == R.id.stop ?
+                    mRouter.unselect(id == R.id.mr_button_stop ?
                             MediaRouter.UNSELECT_REASON_STOPPED :
                             MediaRouter.UNSELECT_REASON_DISCONNECTED);
                 }
@@ -465,194 +639,12 @@
                         mMediaController.getTransportControls().play();
                     }
                 }
-            } else if (id == R.id.close) {
+            } else if (id == R.id.mr_close) {
                 dismiss();
             }
         }
     }
 
-    private class MediaRouteControlHelper {
-        private RelativeLayout mPlaybackControl;
-        private TextView mTitleView;
-        private TextView mSubtitleView;
-        private ImageButton mPlayPauseButton;
-
-        private LinearLayout mVolumeControl;
-        private SeekBar mVolumeSlider;
-        private ImageButton mGroupExpandCollapseButton;
-        private boolean mVolumeSliderTouched;
-
-        private View mDividerView;
-
-        public MediaRouteControlHelper(ClickListener listener) {
-            mPlaybackControl = (RelativeLayout) findViewById(R.id.mr_playback_control);
-            mTitleView = (TextView) findViewById(R.id.mr_control_title);
-            mSubtitleView = (TextView) findViewById(R.id.mr_control_subtitle);
-            mPlayPauseButton = (ImageButton) findViewById(R.id.mr_control_play_pause);
-            mPlayPauseButton.setOnClickListener(listener);
-
-            mVolumeControl = (LinearLayout) findViewById(R.id.mr_volume_control);
-            mVolumeSlider = (SeekBar) findViewById(R.id.mr_volume_slider);
-            mVolumeSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
-                private final Runnable mStopTrackingTouch = new Runnable() {
-                    @Override
-                    public void run() {
-                        if (mVolumeSliderTouched) {
-                            mVolumeSliderTouched = false;
-                            updateVolumeControl();
-                        }
-                    }
-                };
-
-                @Override
-                public void onStartTrackingTouch(SeekBar seekBar) {
-                    if (mVolumeSliderTouched) {
-                        mVolumeSlider.removeCallbacks(mStopTrackingTouch);
-                    } else {
-                        mVolumeSliderTouched = true;
-                    }
-                }
-
-                @Override
-                public void onStopTrackingTouch(SeekBar seekBar) {
-                    // Defer resetting mVolumeSliderTouched to allow the media route provider
-                    // a little time to settle into its new state and publish the final
-                    // volume update.
-                    mVolumeSlider.postDelayed(mStopTrackingTouch, VOLUME_UPDATE_DELAY_MILLIS);
-                }
-
-                @Override
-                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
-                    if (fromUser) {
-                        mRoute.requestSetVolume(progress);
-                    }
-                }
-            });
-
-            TypedArray styledAttributes = getContext().obtainStyledAttributes(new int[] {
-                    R.attr.mediaRouteExpandGroupDrawable,
-                    R.attr.mediaRouteCollapseGroupDrawable
-            });
-            final Drawable expandGroupDrawable = styledAttributes.getDrawable(0);
-            final Drawable collapseGroupDrawable = styledAttributes.getDrawable(1);
-            styledAttributes.recycle();
-
-            mGroupExpandCollapseButton = (ImageButton) findViewById(R.id.mr_group_expand_collapse);
-            mGroupExpandCollapseButton.setOnClickListener(new View.OnClickListener() {
-                private boolean mIsExpanded;
-
-                @Override
-                public void onClick(View v) {
-                    mIsExpanded = !mIsExpanded;
-                    if (mIsExpanded) {
-                        mGroupExpandCollapseButton.setImageDrawable(collapseGroupDrawable);
-                        mVolumeGroupList.setVisibility(View.VISIBLE);
-                        mVolumeGroupList.setAdapter(
-                                new VolumeGroupAdapter(getContext(), getGroup().getRoutes()));
-                    } else {
-                        mGroupExpandCollapseButton.setImageDrawable(expandGroupDrawable);
-                        mVolumeGroupList.setVisibility(View.GONE);
-                    }
-                }
-            });
-
-            mDividerView = findViewById(R.id.mr_control_divider);
-        }
-
-        public void updateVolumeControl() {
-            if (!mVolumeSliderTouched) {
-                if (isVolumeControlAvailable()) {
-                    mVolumeControl.setVisibility(View.VISIBLE);
-                    mVolumeSlider.setMax(mRoute.getVolumeMax());
-                    mVolumeSlider.setProgress(mRoute.getVolume());
-                    if (USE_GROUP) {
-                        if (getGroup() == null) {
-                            mGroupExpandCollapseButton.setVisibility(View.GONE);
-                        } else {
-                            mGroupExpandCollapseButton.setVisibility(View.VISIBLE);
-                            VolumeGroupAdapter adapter =
-                                    (VolumeGroupAdapter) mVolumeGroupList.getAdapter();
-                            if (adapter != null) {
-                                adapter.notifyDataSetChanged();
-                            }
-                        }
-                    }
-                } else {
-                    mVolumeControl.setVisibility(View.GONE);
-                }
-                adjustControlViewVisibilities();
-            }
-        }
-
-        public void updatePlaybackControl() {
-            if (mCustomControlView == null && (mDescription != null || mState != null)) {
-                mPlaybackControl.setVisibility(View.VISIBLE);
-                CharSequence title = mDescription == null ? null : mDescription.getTitle();
-                boolean hasTitle = !TextUtils.isEmpty(title);
-
-                CharSequence subtitle = mDescription == null ? null : mDescription.getSubtitle();
-                boolean hasSubtitle = !TextUtils.isEmpty(subtitle);
-
-                if (!hasTitle && !hasSubtitle) {
-                    if (mRoute.getPresentationDisplayId()
-                            != MediaRouter.RouteInfo.PRESENTATION_DISPLAY_ID_NONE) {
-                        // The user is currently casting screen.
-                        mTitleView.setText(R.string.mr_controller_casting_screen);
-                    } else {
-                        mTitleView.setText((mState == null
-                                || mState.getState() == PlaybackStateCompat.STATE_NONE)
-                                        ? R.string.mr_controller_no_media_selected
-                                        : R.string.mr_controller_no_info_available);
-                    }
-                    mTitleView.setEnabled(false);
-                    mTitleView.setVisibility(View.VISIBLE);
-                    mSubtitleView.setVisibility(View.GONE);
-                } else {
-                    mTitleView.setText(title);
-                    mTitleView.setEnabled(hasTitle);
-                    mTitleView.setVisibility(hasTitle ? View.VISIBLE : View.GONE);
-                    mSubtitleView.setText(subtitle);
-                    mSubtitleView.setVisibility(hasSubtitle ? View.VISIBLE : View.GONE);
-                }
-                if (mState != null) {
-                    boolean isPlaying = mState.getState() == PlaybackStateCompat.STATE_BUFFERING
-                            || mState.getState() == PlaybackStateCompat.STATE_PLAYING;
-                    boolean supportsPlay = (mState.getActions() & (PlaybackStateCompat.ACTION_PLAY
-                            | PlaybackStateCompat.ACTION_PLAY_PAUSE)) != 0;
-                    boolean supportsPause = (mState.getActions() & (PlaybackStateCompat.ACTION_PAUSE
-                            | PlaybackStateCompat.ACTION_PLAY_PAUSE)) != 0;
-                    if (isPlaying && supportsPause) {
-                        mPlayPauseButton.setVisibility(View.VISIBLE);
-                        mPlayPauseButton.setImageResource(MediaRouterThemeHelper.getThemeResource(
-                                getContext(), R.attr.mediaRoutePauseDrawable));
-                        mPlayPauseButton.setContentDescription(getContext().getResources()
-                                .getText(R.string.mr_controller_pause));
-                    } else if (!isPlaying && supportsPlay) {
-                        mPlayPauseButton.setVisibility(View.VISIBLE);
-                        mPlayPauseButton.setImageResource(MediaRouterThemeHelper.getThemeResource(
-                                getContext(), R.attr.mediaRoutePlayDrawable));
-                        mPlayPauseButton.setContentDescription(getContext().getResources()
-                                .getText(R.string.mr_controller_play));
-                    } else {
-                        mPlayPauseButton.setVisibility(View.GONE);
-                    }
-                }
-            } else {
-                mPlaybackControl.setVisibility(View.GONE);
-            }
-            adjustControlViewVisibilities();
-        }
-
-        private void adjustControlViewVisibilities() {
-            mDividerView.setVisibility((mVolumeControl.getVisibility() == View.VISIBLE
-                    && mPlaybackControl.getVisibility() == View.VISIBLE)
-                            ? View.VISIBLE : View.GONE);
-            mControlView.setVisibility((mVolumeControl.getVisibility() == View.GONE
-                    && mPlaybackControl.getVisibility() == View.GONE)
-                            ? View.GONE : View.VISIBLE);
-        }
-    }
-
     private class VolumeGroupAdapter extends ArrayAdapter<MediaRouter.RouteInfo> {
         final static float DISABLED_ALPHA = .3f;