Most visited

Recently visited

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.

See also:

Summary

Inherited XML attributes

From class android.view.View

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()

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

void onAttachedToWindow()

This is called when the view is attached to a window.

void onDetachedFromWindow()

This is called when the view is detached from a window.

boolean performClick()

Call this view's OnClickListener, if it is defined.

boolean performLongClick()

Calls this view's OnLongClickListener, if it is defined.

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)

Set the enabled state of this view.

boolean showDialog()

Show the route chooser or controller dialog.

Protected methods

void drawableStateChanged()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

int[] onCreateDrawableState(int extraSpace)

Generate the new Drawable state for this view.

void onDraw(Canvas canvas)

Implement this to do your drawing.

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

boolean verifyDrawable(Drawable who)

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.

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

MediaRouteButton (Context context)

Parameters
context Context

MediaRouteButton

MediaRouteButton (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

MediaRouteButton

MediaRouteButton (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

Public methods

getDialogFactory

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

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 ()

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

Also calls jumpToCurrentState() if there is a StateListAnimator attached to this view.

onAttachedToWindow

void onAttachedToWindow ()

This is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(android.graphics.Canvas), however it may be called any time before the first onDraw -- including before or after onMeasure(int, int).

onDetachedFromWindow

void onDetachedFromWindow ()

This is called when the view is detached from a window. At this point it no longer has a surface for drawing.

performClick

boolean performClick ()

Call this view's OnClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.

Returns
boolean True there was an assigned OnClickListener that was called, false otherwise is returned.

performLongClick

boolean performLongClick ()

Calls this view's OnLongClickListener, if it is defined. Invokes the context menu if the OnLongClickListener did not consume the event.

Returns
boolean true if one of the above receivers consumed the event, false otherwise

setDialogFactory

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

void setRemoteIndicatorDrawable (Drawable d)

Sets a drawable to use as the remote route indicator.

Parameters
d Drawable

setRouteSelector

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)

Set the enabled state of this view.

Parameters
visibility int: One of VISIBLE, INVISIBLE, or GONE.

showDialog

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 ()

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

If the View has a StateListAnimator, it will also be called to run necessary state change animations.

Be sure to call through to the superclass when overriding this function.

onCreateDrawableState

int[] onCreateDrawableState (int extraSpace)

Generate the new Drawable state for this view. This is called by the view system when the cached Drawable state is determined to be invalid. To retrieve the current state, you should use getDrawableState().

Parameters
extraSpace int: if non-zero, this is the number of extra entries you would like in the returned array in which you can place your own states.
Returns
int[] Returns an array holding the current Drawable state of the view.

onDraw

void onDraw (Canvas canvas)

Implement this to do your drawing.

Parameters
canvas Canvas: the canvas on which the background will be drawn

onMeasure

void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.

verifyDrawable

boolean verifyDrawable (Drawable who)

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.

Parameters
who Drawable: The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class.
Returns
boolean boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.

Hooray!