added in version 22.1.0
belongs to Maven artifact com.android.support:mediarouter-v7:28.0.0-alpha1

MediaRouteButton

public class MediaRouteButton
extends View

java.lang.Object
   ↳ android.view.View
     ↳ android.support.v7.app.MediaRouteButton


The media route button allows the user to select routes and to control the currently selected route.

The application must specify the kinds of routes that the user should be allowed to select by specifying a selector with the setRouteSelector(MediaRouteSelector) method.

When the default route is selected or when the currently selected route does not match the selector, the button will appear in an inactive state indicating that the application is not connected to a route of the kind that it wants to use. Clicking on the button opens a MediaRouteChooserDialog to allow the user to select a route. If no non-default routes match the selector and it is not possible for an active scan to discover any matching routes, then the button is disabled and cannot be clicked.

When a non-default route is selected that matches the selector, the button will appear in an active state indicating that the application is connected to a route of the kind that it wants to use. The button may also appear in an intermediary connecting state if the route is in the process of connecting to the destination but has not yet completed doing so. In either case, clicking on the button opens a MediaRouteControllerDialog to allow the user to control or disconnect from the current route.

Prerequisites

To use the media route button, the activity must be a subclass of FragmentActivity from the android.support.v4 support library. Refer to support library documentation for details.

Summary

Inherited constants

From class android.view.View

Inherited fields

From class android.view.View

Public constructors

MediaRouteButton(Context context)
MediaRouteButton(Context context, AttributeSet attrs)
MediaRouteButton(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

MediaRouteDialogFactory getDialogFactory()

Gets the media route dialog factory to use when showing the route chooser or controller dialog.

MediaRouteSelector getRouteSelector()

Gets the media route selector for filtering the routes that the user can select using the media route chooser dialog.

void jumpDrawablesToCurrentState()
void onAttachedToWindow()
void onDetachedFromWindow()
boolean performClick()
void setDialogFactory(MediaRouteDialogFactory factory)

Sets the media route dialog factory to use when showing the route chooser or controller dialog.

void setRemoteIndicatorDrawable(Drawable d)

Sets a drawable to use as the remote route indicator.

void setRouteSelector(MediaRouteSelector selector)

Sets the media route selector for filtering the routes that the user can select using the media route chooser dialog.

void setVisibility(int visibility)
boolean showDialog()

Show the route chooser or controller dialog.

Protected methods

void drawableStateChanged()
int[] onCreateDrawableState(int extraSpace)
void onDraw(Canvas canvas)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
boolean verifyDrawable(Drawable who)

Inherited methods

From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Public constructors

MediaRouteButton

added in version 22.1.0
MediaRouteButton (Context context)

Parameters
context Context

MediaRouteButton

added in version 22.1.0
MediaRouteButton (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

MediaRouteButton

added in version 22.1.0
MediaRouteButton (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

getDialogFactory

added in version 22.1.0
MediaRouteDialogFactory getDialogFactory ()

Gets the media route dialog factory to use when showing the route chooser or controller dialog.

Returns
MediaRouteDialogFactory The dialog factory, never null.

getRouteSelector

added in version 22.1.0
MediaRouteSelector getRouteSelector ()

Gets the media route selector for filtering the routes that the user can select using the media route chooser dialog.

Returns
MediaRouteSelector The selector, never null.

jumpDrawablesToCurrentState

void jumpDrawablesToCurrentState ()

onAttachedToWindow

added in version 22.1.0
void onAttachedToWindow ()

onDetachedFromWindow

added in version 22.1.0
void onDetachedFromWindow ()

performClick

boolean performClick ()

Returns
boolean

setDialogFactory

added in version 22.1.0
void setDialogFactory (MediaRouteDialogFactory factory)

Sets the media route dialog factory to use when showing the route chooser or controller dialog.

Parameters
factory MediaRouteDialogFactory: The dialog factory, must not be null.

setRemoteIndicatorDrawable

added in version 24.1.0
void setRemoteIndicatorDrawable (Drawable d)

Sets a drawable to use as the remote route indicator.

Parameters
d Drawable

setRouteSelector

added in version 22.1.0
void setRouteSelector (MediaRouteSelector selector)

Sets the media route selector for filtering the routes that the user can select using the media route chooser dialog.

Parameters
selector MediaRouteSelector: The selector, must not be null.

setVisibility

void setVisibility (int visibility)

Parameters
visibility int

showDialog

added in version 22.1.0
boolean showDialog ()

Show the route chooser or controller dialog.

If the default route is selected or if the currently selected route does not match the selector, then shows the route chooser dialog. Otherwise, shows the route controller dialog to offer the user a choice to disconnect from the route or perform other control actions such as setting the route's volume.

The application can customize the dialogs by calling setDialogFactory(MediaRouteDialogFactory) to provide a customized dialog factory.

Returns
boolean True if the dialog was actually shown.

Throws
IllegalStateException if the activity is not a subclass of FragmentActivity.

Protected methods

drawableStateChanged

void drawableStateChanged ()

onCreateDrawableState

int[] onCreateDrawableState (int extraSpace)

Parameters
extraSpace int

Returns
int[]

onDraw

void onDraw (Canvas canvas)

Parameters
canvas Canvas

onMeasure

void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int

verifyDrawable

boolean verifyDrawable (Drawable who)

Parameters
who Drawable

Returns
boolean