public class

MediaRouteChooserDialogFragment

extends DialogFragment

 java.lang.Object

androidx.fragment.app.Fragment

androidx.fragment.app.DialogFragment

↳androidx.mediarouter.app.MediaRouteChooserDialogFragment

Gradle dependencies

compile group: 'androidx.mediarouter', name: 'mediarouter', version: '1.3.0'

  • groupId: androidx.mediarouter
  • artifactId: mediarouter
  • version: 1.3.0

Artifact androidx.mediarouter:mediarouter:1.3.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.mediarouter:mediarouter com.android.support:mediarouter-v7

Androidx class mapping:

androidx.mediarouter.app.MediaRouteChooserDialogFragment android.support.v7.app.MediaRouteChooserDialogFragment

Overview

Media route chooser dialog fragment.

Creates a MediaRouteChooserDialog. The application may subclass this dialog fragment to customize the media route chooser dialog.

Summary

Fields
from DialogFragmentSTYLE_NO_FRAME, STYLE_NO_INPUT, STYLE_NO_TITLE, STYLE_NORMAL
from FragmentmPreviousWho
Constructors
publicMediaRouteChooserDialogFragment()

Creates a media route chooser dialog fragment.

Methods
public MediaRouteSelectorgetRouteSelector()

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

public voidonConfigurationChanged(Configuration newConfig)

public MediaRouteChooserDialogonCreateChooserDialog(Context context, Bundle savedInstanceState)

Called when the chooser dialog is being created.

public DialogonCreateDialog(Bundle savedInstanceState)

Override to build your own custom Dialog container.

public MediaRouteDynamicChooserDialogonCreateDynamicChooserDialog(Context context)

Called when the device picker dialog is being created.

public voidsetRouteSelector(MediaRouteSelector selector)

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

from DialogFragmentdismiss, dismissAllowingStateLoss, dismissNow, getDialog, getShowsDialog, getTheme, isCancelable, onActivityCreated, onAttach, onCancel, onCreate, onDestroyView, onDetach, onDismiss, onGetLayoutInflater, onSaveInstanceState, onStart, onStop, onViewStateRestored, requireDialog, setCancelable, setShowsDialog, setStyle, setupDialog, show, show, showNow
from Fragmentdump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getDefaultViewModelCreationExtras, getDefaultViewModelProviderFactory, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLayoutInflater, getLifecycle, getLoaderManager, getParentFragment, getParentFragmentManager, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSavedStateRegistry, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, getViewLifecycleOwner, getViewLifecycleOwnerLiveData, getViewModelStore, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isStateSaved, isVisible, onActivityResult, onAttach, onAttachFragment, onContextItemSelected, onCreateAnimation, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onCreateView, onDestroy, onDestroyOptionsMenu, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPictureInPictureModeChanged, onPrepareOptionsMenu, onPrimaryNavigationFragmentChanged, onRequestPermissionsResult, onResume, onViewCreated, postponeEnterTransition, postponeEnterTransition, registerForActivityResult, registerForActivityResult, registerForContextMenu, requestPermissions, requireActivity, requireArguments, requireContext, requireFragmentManager, requireHost, requireParentFragment, requireView, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, startPostponedEnterTransition, toString, unregisterForContextMenu
from java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait

Constructors

public MediaRouteChooserDialogFragment()

Creates a media route chooser dialog fragment.

All subclasses of this class must also possess a default constructor.

Methods

public MediaRouteSelector getRouteSelector()

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

Returns:

The selector, never null.

public void setRouteSelector(MediaRouteSelector selector)

Sets the media route selector for filtering the routes that the user can select. This method must be called before the fragment is added.

Parameters:

selector: The selector to set.

public MediaRouteDynamicChooserDialog onCreateDynamicChooserDialog(Context context)

Called when the device picker dialog is being created.

public MediaRouteChooserDialog onCreateChooserDialog(Context context, Bundle savedInstanceState)

Called when the chooser dialog is being created.

Subclasses may override this method to customize the dialog.

public Dialog onCreateDialog(Bundle savedInstanceState)

Override to build your own custom Dialog container. This is typically used to show an AlertDialog instead of a generic Dialog; when doing so, Fragment.onCreateView(LayoutInflater, ViewGroup, Bundle) does not need to be implemented since the AlertDialog takes care of its own content.

This method will be called after DialogFragment.onCreate(Bundle) and immediately before Fragment.onCreateView(LayoutInflater, ViewGroup, Bundle). The default implementation simply instantiates and returns a Dialog class.

Note: DialogFragment own the Dialog.setOnCancelListener and Dialog.setOnDismissListener callbacks. You must not set them yourself. To find out about these events, override DialogFragment.onCancel(DialogInterface) and DialogFragment.onDismiss(DialogInterface).

Parameters:

savedInstanceState: The last saved instance state of the Fragment, or null if this is a freshly created Fragment.

Returns:

Return a new Dialog instance to be displayed by the Fragment.

public void onConfigurationChanged(Configuration newConfig)

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.mediarouter.app;

import static androidx.annotation.RestrictTo.Scope.LIBRARY;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.fragment.app.DialogFragment;
import androidx.mediarouter.media.MediaRouteSelector;

/**
 * Media route chooser dialog fragment.
 * <p>
 * Creates a {@link MediaRouteChooserDialog}.  The application may subclass
 * this dialog fragment to customize the media route chooser dialog.
 * </p>
 */
public class MediaRouteChooserDialogFragment extends DialogFragment {
    private static final String ARGUMENT_SELECTOR = "selector";
    private boolean mUseDynamicGroup = false;
    private Dialog mDialog;
    private MediaRouteSelector mSelector;

    /**
     * Creates a media route chooser dialog fragment.
     * <p>
     * All subclasses of this class must also possess a default constructor.
     * </p>
     */
    public MediaRouteChooserDialogFragment() {
        setCancelable(true);
    }

    /**
     * Gets the media route selector for filtering the routes that the user can select.
     *
     * @return The selector, never null.
     */
    @NonNull
    public MediaRouteSelector getRouteSelector() {
        ensureRouteSelector();
        return mSelector;
    }

    private void ensureRouteSelector() {
        if (mSelector == null) {
            Bundle args = getArguments();
            if (args != null) {
                mSelector = MediaRouteSelector.fromBundle(args.getBundle(ARGUMENT_SELECTOR));
            }
            if (mSelector == null) {
                mSelector = MediaRouteSelector.EMPTY;
            }
        }
    }

    /**
     * Sets whether it creates dialog for dynamic group or not.
     * This method must be called before a dialog is created,
     * otherwise, this will throw {@link IllegalStateException}
     *
     * @param useDynamicGroup true if this should create the dialog for dynamic group
     */
    void setUseDynamicGroup(boolean useDynamicGroup) {
        if (mDialog != null) {
            throw new IllegalStateException("This must be called before creating dialog");
        }
        mUseDynamicGroup = useDynamicGroup;
    }

    /**
     * Sets the media route selector for filtering the routes that the user can select.
     * This method must be called before the fragment is added.
     *
     * @param selector The selector to set.
     */
    public void setRouteSelector(@NonNull MediaRouteSelector selector) {
        if (selector == null) {
            throw new IllegalArgumentException("selector must not be null");
        }

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

            Bundle args = getArguments();
            if (args == null) {
                args = new Bundle();
            }
            args.putBundle(ARGUMENT_SELECTOR, selector.asBundle());
            setArguments(args);

            if (mDialog != null) {
                if (mUseDynamicGroup) {
                    ((MediaRouteDynamicChooserDialog) mDialog).setRouteSelector(selector);
                } else {
                    ((MediaRouteChooserDialog) mDialog).setRouteSelector(selector);
                }
            }
        }
    }

    /**
     * Called when the device picker dialog is being created.
     * @hide
     */
    @RestrictTo(LIBRARY)
    @NonNull
    public MediaRouteDynamicChooserDialog onCreateDynamicChooserDialog(@NonNull Context context) {
        return new MediaRouteDynamicChooserDialog(context);
    }

    /**
     * Called when the chooser dialog is being created.
     * <p>
     * Subclasses may override this method to customize the dialog.
     * </p>
     */
    @NonNull
    public MediaRouteChooserDialog onCreateChooserDialog(
            @NonNull Context context, @Nullable Bundle savedInstanceState) {
        return new MediaRouteChooserDialog(context);
    }

    @Override
    @NonNull
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        if (mUseDynamicGroup) {
            mDialog = onCreateDynamicChooserDialog(getContext());
            ((MediaRouteDynamicChooserDialog) mDialog).setRouteSelector(getRouteSelector());
        } else {
            mDialog = onCreateChooserDialog(getContext(), savedInstanceState);
            ((MediaRouteChooserDialog) mDialog).setRouteSelector(getRouteSelector());
        }
        return mDialog;
    }

    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (mDialog == null) {
            return;
        }
        if (mUseDynamicGroup) {
            ((MediaRouteDynamicChooserDialog) mDialog).updateLayout();
        } else {
            ((MediaRouteChooserDialog) mDialog).updateLayout();
        }
    }
}