FileDocCategorySizeDatePackage
MediaRouteChooserDialog.javaAPI DocAndroid 5.1 API9016Thu Mar 12 22:22:56 GMT 2015android.support.v7.app

MediaRouteChooserDialog

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

This dialog allows the user to choose a route that matches a given selector.

see
MediaRouteButton
see
MediaRouteActionProvider

Fields Summary
private final android.support.v7.media.MediaRouter
mRouter
private final MediaRouterCallback
mCallback
private android.support.v7.media.MediaRouteSelector
mSelector
private ArrayList
mRoutes
private RouteAdapter
mAdapter
private android.widget.ListView
mListView
private boolean
mAttachedToWindow
Constructors Summary
public MediaRouteChooserDialog(android.content.Context context)


       
        this(context, 0);
    
public MediaRouteChooserDialog(android.content.Context context, int theme)

        super(MediaRouterThemeHelper.createThemedContext(context), theme);
        context = getContext();

        mRouter = MediaRouter.getInstance(context);
        mCallback = new MediaRouterCallback();
    
Methods Summary
public android.support.v7.media.MediaRouteSelectorgetRouteSelector()
Gets the media route selector for filtering the routes that the user can select.

return
The selector, never null.

        return mSelector;
    
public voidonAttachedToWindow()

        super.onAttachedToWindow();

        mAttachedToWindow = true;
        mRouter.addCallback(mSelector, mCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
        refreshRoutes();
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        getWindow().requestFeature(Window.FEATURE_LEFT_ICON);

        setContentView(R.layout.mr_media_route_chooser_dialog);
        setTitle(R.string.mr_media_route_chooser_title);

        // Must be called after setContentView.
        getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
                MediaRouterThemeHelper.getThemeResource(
                        getContext(), R.attr.mediaRouteOffDrawable));

        mRoutes = new ArrayList<MediaRouter.RouteInfo>();
        mAdapter = new RouteAdapter(getContext(), mRoutes);
        mListView = (ListView)findViewById(R.id.media_route_list);
        mListView.setAdapter(mAdapter);
        mListView.setOnItemClickListener(mAdapter);
        mListView.setEmptyView(findViewById(android.R.id.empty));
    
public voidonDetachedFromWindow()

        mAttachedToWindow = false;
        mRouter.removeCallback(mCallback);

        super.onDetachedFromWindow();
    
public booleanonFilterRoute(MediaRouter.RouteInfo route)
Returns true if the route should be included in the list.

The default implementation returns true for enabled non-default routes that match the selector. Subclasses can override this method to filter routes differently.

param
route The route to consider, never null.
return
True if the route should be included in the chooser dialog.

        return !route.isDefault() && route.isEnabled() && route.matchesSelector(mSelector);
    
public voidonFilterRoutes(java.util.List routes)
Called to filter the set of routes that should be included in the list.

The default implementation iterates over all routes in the provided list and removes those for which {@link #onFilterRoute} returns false.

param
routes The list of routes to filter in-place, never null.

        for (int i = routes.size(); i-- > 0; ) {
            if (!onFilterRoute(routes.get(i))) {
                routes.remove(i);
            }
        }
    
public voidrefreshRoutes()
Refreshes the list of routes that are shown in the chooser dialog.

        if (mAttachedToWindow) {
            mRoutes.clear();
            mRoutes.addAll(mRouter.getRoutes());
            onFilterRoutes(mRoutes);
            Collections.sort(mRoutes, RouteComparator.sInstance);
            mAdapter.notifyDataSetChanged();
        }
    
public voidsetRouteSelector(android.support.v7.media.MediaRouteSelector selector)
Sets the media route selector for filtering the routes that the user can select.

param
selector The selector, must not be null.

        if (selector == null) {
            throw new IllegalArgumentException("selector must not be null");
        }

        if (!mSelector.equals(selector)) {
            mSelector = selector;

            if (mAttachedToWindow) {
                mRouter.removeCallback(mCallback);
                mRouter.addCallback(selector, mCallback,
                        MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
            }

            refreshRoutes();
        }