FileDocCategorySizeDatePackage
MediaRouteControllerDialog.javaAPI DocAndroid 5.1 API10435Thu Mar 12 22:22:10 GMT 2015com.android.internal.app

MediaRouteControllerDialog

public class MediaRouteControllerDialog extends android.app.Dialog
This class implements the route controller dialog for {@link MediaRouter}.

This dialog allows the user to control or disconnect from the currently selected route.

see
MediaRouteButton
see
MediaRouteActionProvider TODO: Move this back into the API, as in the support library media router.

Fields Summary
private static final int
VOLUME_UPDATE_DELAY_MILLIS
private final android.media.MediaRouter
mRouter
private final MediaRouterCallback
mCallback
private final android.media.MediaRouter.RouteInfo
mRoute
private boolean
mCreated
private android.graphics.drawable.Drawable
mMediaRouteConnectingDrawable
private android.graphics.drawable.Drawable
mMediaRouteOnDrawable
private android.graphics.drawable.Drawable
mCurrentIconDrawable
private boolean
mVolumeControlEnabled
private android.widget.LinearLayout
mVolumeLayout
private android.widget.SeekBar
mVolumeSlider
private boolean
mVolumeSliderTouched
private android.view.View
mControlView
private android.widget.Button
mDisconnectButton
Constructors Summary
public MediaRouteControllerDialog(android.content.Context context, int theme)


         
        super(context, theme);

        mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
        mCallback = new MediaRouterCallback();
        mRoute = mRouter.getSelectedRoute();
    
Methods Summary
private android.graphics.drawable.DrawablegetIconDrawable()

        if (mRoute.isConnecting()) {
            if (mMediaRouteConnectingDrawable == null) {
                mMediaRouteConnectingDrawable = getContext().getDrawable(
                        R.drawable.ic_media_route_connecting_holo_dark);
            }
            return mMediaRouteConnectingDrawable;
        } else {
            if (mMediaRouteOnDrawable == null) {
                mMediaRouteOnDrawable = getContext().getDrawable(
                        R.drawable.ic_media_route_on_holo_dark);
            }
            return mMediaRouteOnDrawable;
        }
    
public android.view.ViewgetMediaControlView()
Gets the media control view that was created by {@link #onCreateMediaControlView(Bundle)}.

return
The media control view, or null if none.

        return mControlView;
    
public android.media.MediaRouter.RouteInfogetRoute()
Gets the route that this dialog is controlling.

        return mRoute;
    
private booleanisVolumeControlAvailable()

        return mVolumeControlEnabled && mRoute.getVolumeHandling() ==
                MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE;
    
public booleanisVolumeControlEnabled()
Returns whether to enable the volume slider and volume control using the volume keys when the route supports it.

        return mVolumeControlEnabled;
    
public voidonAttachedToWindow()

        super.onAttachedToWindow();

        mRouter.addCallback(0, mCallback, MediaRouter.CALLBACK_FLAG_UNFILTERED_EVENTS);
        update();
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        getWindow().requestFeature(Window.FEATURE_LEFT_ICON);

        setContentView(R.layout.media_route_controller_dialog);

        mVolumeLayout = (LinearLayout)findViewById(R.id.media_route_volume_layout);
        mVolumeSlider = (SeekBar)findViewById(R.id.media_route_volume_slider);
        mVolumeSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            private final Runnable mStopTrackingTouch = new Runnable() {
                @Override
                public void run() {
                    if (mVolumeSliderTouched) {
                        mVolumeSliderTouched = false;
                        updateVolume();
                    }
                }
            };

            @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);
                }
            }
        });

        mDisconnectButton = (Button)findViewById(R.id.media_route_disconnect_button);
        mDisconnectButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mRoute.isSelected()) {
                    mRouter.getDefaultRoute().select();
                }
                dismiss();
            }
        });

        mCreated = true;
        if (update()) {
            mControlView = onCreateMediaControlView(savedInstanceState);
            FrameLayout controlFrame =
                    (FrameLayout)findViewById(R.id.media_route_control_frame);
            if (mControlView != null) {
                controlFrame.addView(mControlView);
                controlFrame.setVisibility(View.VISIBLE);
            } else {
                controlFrame.setVisibility(View.GONE);
            }
        }
    
public android.view.ViewonCreateMediaControlView(android.os.Bundle savedInstanceState)
Provides the subclass an opportunity to create a view that will be included within the body of the dialog to offer additional media controls for the currently playing content.

param
savedInstanceState The dialog's saved instance state.
return
The media control view, or null if none.

        return null;
    
public voidonDetachedFromWindow()

        mRouter.removeCallback(mCallback);

        super.onDetachedFromWindow();
    
public booleanonKeyDown(int keyCode, android.view.KeyEvent event)

        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
                || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            mRoute.requestUpdateVolume(keyCode == KeyEvent.KEYCODE_VOLUME_DOWN ? -1 : 1);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    
public booleanonKeyUp(int keyCode, android.view.KeyEvent event)

        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
                || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            return true;
        }
        return super.onKeyUp(keyCode, event);
    
public voidsetVolumeControlEnabled(boolean enable)
Sets whether to enable the volume slider and volume control using the volume keys when the route supports it.

The default value is true.

        if (mVolumeControlEnabled != enable) {
            mVolumeControlEnabled = enable;
            if (mCreated) {
                updateVolume();
            }
        }
    
private booleanupdate()

        if (!mRoute.isSelected() || mRoute.isDefault()) {
            dismiss();
            return false;
        }

        setTitle(mRoute.getName());
        updateVolume();

        Drawable icon = getIconDrawable();
        if (icon != mCurrentIconDrawable) {
            mCurrentIconDrawable = icon;
            getWindow().setFeatureDrawable(Window.FEATURE_LEFT_ICON, icon);
        }
        return true;
    
private voidupdateVolume()

        if (!mVolumeSliderTouched) {
            if (isVolumeControlAvailable()) {
                mVolumeLayout.setVisibility(View.VISIBLE);
                mVolumeSlider.setMax(mRoute.getVolumeMax());
                mVolumeSlider.setProgress(mRoute.getVolume());
            } else {
                mVolumeLayout.setVisibility(View.GONE);
            }
        }