The Android Developer Challenge is back! Submit your idea before December 2.

MediaRouteButton

open class MediaRouteButton : View
kotlin.Any
   ↳ android.view.View
   ↳ androidx.mediarouter.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 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

Public constructors

<init>(context: Context!)

<init>(context: Context!, attrs: AttributeSet!)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Public methods

open Unit

Enables dynamic group feature.

open MediaRouteDialogFactory

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

open MediaRouteSelector

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

open Unit

open Unit

open Unit

open Boolean

open Unit
setAlwaysVisible(alwaysVisible: Boolean)

Sets whether the button is visible when no routes are available.

open Unit

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

open Unit

Sets a drawable to use as the remote route indicator.

open Unit

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

open Unit
setVisibility(visibility: Int)

open Boolean

Show the route chooser or controller dialog.

Protected methods

open Unit

open IntArray!

open Unit
onDraw(canvas: Canvas!)

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

open Boolean

Public constructors

<init>

MediaRouteButton(context: Context!)

<init>

MediaRouteButton(context: Context!, attrs: AttributeSet!)

<init>

MediaRouteButton(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Public methods

enableDynamicGroup

open fun enableDynamicGroup(): Unit

Enables dynamic group feature. With this enabled, a different set of MediaRouteChooserDialog and MediaRouteControllerDialog is shown when the button is clicked. If a media route provider supports dynamic group, the users can use that feature with the dialogs.

getDialogFactory

@NonNull open fun getDialogFactory(): MediaRouteDialogFactory

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

Return
MediaRouteDialogFactory: The dialog factory, never null.

getRouteSelector

@NonNull open fun getRouteSelector(): MediaRouteSelector

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

Return
MediaRouteSelector: The selector, never null.

jumpDrawablesToCurrentState

open fun jumpDrawablesToCurrentState(): Unit

onAttachedToWindow

open fun onAttachedToWindow(): Unit

onDetachedFromWindow

open fun onDetachedFromWindow(): Unit

performClick

open fun performClick(): Boolean

setAlwaysVisible

open fun setAlwaysVisible(alwaysVisible: Boolean): Unit

Sets whether the button is visible when no routes are available. When true, the button is visible even if there are no routes to connect. You may want to override View#performClick() to change the behavior when the button is clicked. The default is false. It doesn't overrides the visibility status of the button.

Parameters
alwaysVisible Boolean: true to show button always.

setDialogFactory

open fun setDialogFactory(@NonNull factory: MediaRouteDialogFactory): Unit

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

open fun setRemoteIndicatorDrawable(d: Drawable!): Unit

Sets a drawable to use as the remote route indicator.

setRouteSelector

open fun setRouteSelector(selector: MediaRouteSelector!): Unit

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

open fun setVisibility(visibility: Int): Unit

showDialog

open fun showDialog(): Boolean

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 to provide a customized dialog factory.

Return
Boolean: True if the dialog was actually shown.
Exceptions
IllegalStateException if the activity is not a subclass of FragmentActivity.

Protected methods

drawableStateChanged

protected open fun drawableStateChanged(): Unit

onCreateDrawableState

protected open fun onCreateDrawableState(extraSpace: Int): IntArray!

onDraw

protected open fun onDraw(canvas: Canvas!): Unit

onMeasure

protected open fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit

verifyDrawable

protected open fun verifyDrawable(who: Drawable!): Boolean