FileDocCategorySizeDatePackage
MediaRouteChooserDialog.javaAPI DocAndroid 5.1 API9080Thu Mar 12 22:22:10 GMT 2015com.android.internal.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 TODO: Move this back into the API, as in the support library media router.

Fields Summary
private final android.media.MediaRouter
mRouter
private final MediaRouterCallback
mCallback
private int
mRouteTypes
private View.OnClickListener
mExtendedSettingsClickListener
private RouteAdapter
mAdapter
private android.widget.ListView
mListView
private android.widget.Button
mExtendedSettingsButton
private boolean
mAttachedToWindow
Constructors Summary
public MediaRouteChooserDialog(android.content.Context context, int theme)

        super(context, theme);

        mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
        mCallback = new MediaRouterCallback();
    
Methods Summary
public intgetRouteTypes()
Gets the media route types for filtering the routes that the user can select using the media route chooser dialog.

return
The route types.

        return mRouteTypes;
    
public voidonAttachedToWindow()

        super.onAttachedToWindow();

        mAttachedToWindow = true;
        mRouter.addCallback(mRouteTypes, 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.media_route_chooser_dialog);
        setTitle(mRouteTypes == MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY
                ? R.string.media_route_chooser_title_for_remote_display
                : R.string.media_route_chooser_title);

        // Must be called after setContentView.
        getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
                R.drawable.ic_media_route_off_holo_dark);

        mAdapter = new RouteAdapter(getContext());
        mListView = (ListView)findViewById(R.id.media_route_list);
        mListView.setAdapter(mAdapter);
        mListView.setOnItemClickListener(mAdapter);
        mListView.setEmptyView(findViewById(android.R.id.empty));

        mExtendedSettingsButton = (Button)findViewById(R.id.media_route_extended_settings_button);
        updateExtendedSettingsButton();
    
public voidonDetachedFromWindow()

        mAttachedToWindow = false;
        mRouter.removeCallback(mCallback);

        super.onDetachedFromWindow();
    
public booleanonFilterRoute(android.media.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 route types. 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.matchesTypes(mRouteTypes);
    
public voidrefreshRoutes()
Refreshes the list of routes that are shown in the chooser dialog.

        if (mAttachedToWindow) {
            mAdapter.update();
        }
    
public voidsetExtendedSettingsClickListener(View.OnClickListener listener)

        if (listener != mExtendedSettingsClickListener) {
            mExtendedSettingsClickListener = listener;
            updateExtendedSettingsButton();
        }
    
public voidsetRouteTypes(int types)
Sets the types of routes that will be shown in the media route chooser dialog launched by this button.

param
types The route types to match.

        if (mRouteTypes != types) {
            mRouteTypes = types;

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

            refreshRoutes();
        }
    
private voidupdateExtendedSettingsButton()

        if (mExtendedSettingsButton != null) {
            mExtendedSettingsButton.setOnClickListener(mExtendedSettingsClickListener);
            mExtendedSettingsButton.setVisibility(
                    mExtendedSettingsClickListener != null ? View.VISIBLE : View.GONE);
        }