public class

MediaRouteControllerDialogFragment

extends DialogFragment

 java.lang.Object

androidx.fragment.app.Fragment

androidx.fragment.app.DialogFragment

↳androidx.mediarouter.app.MediaRouteControllerDialogFragment

Gradle dependencies

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

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

Artifact androidx.mediarouter:mediarouter:1.7.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.MediaRouteControllerDialogFragment android.support.v7.app.MediaRouteControllerDialogFragment

Overview

Media route controller dialog fragment.

Creates a MediaRouteControllerDialog. The application may subclass this dialog fragment to customize the media route controller dialog.

Summary

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

Creates a media route controller dialog fragment.

Methods
public MediaRouteSelectorgetRouteSelector()

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

public voidonConfigurationChanged(Configuration newConfig)

public MediaRouteControllerDialogonCreateControllerDialog(Context context, Bundle savedInstanceState)

Called when the controller dialog is being created.

public DialogonCreateDialog(Bundle savedInstanceState)

Override to build your own custom Dialog container.

public MediaRouteDynamicControllerDialogonCreateDynamicControllerDialog(Context context)

Called when the cast dialog is being created.

public voidonStop()

Called when the Fragment is no longer started.

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, onViewStateRestored, requireComponentDialog, 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 MediaRouteControllerDialogFragment()

Creates a media route controller 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 MediaRouteDynamicControllerDialog onCreateDynamicControllerDialog(Context context)

Called when the cast dialog is being created.

public MediaRouteControllerDialog onCreateControllerDialog(Context context, Bundle savedInstanceState)

Called when the controller 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 onStop()

Called when the Fragment is no longer started. This is generally tied to of the containing Activity's lifecycle.

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 controller dialog fragment.
 * <p>
 * Creates a {@link MediaRouteControllerDialog}.  The application may subclass
 * this dialog fragment to customize the media route controller dialog.
 * </p>
 */
public class MediaRouteControllerDialogFragment extends DialogFragment {
    private static final String ARGUMENT_SELECTOR = "selector";
    private boolean mUseDynamicGroup = false;
    private Dialog mDialog;
    private MediaRouteSelector mSelector;

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

    /**
     * Gets the media route selector for filtering the routes that the user can select.
     *
     * @return The selector, never null.
     */
    @RestrictTo(LIBRARY)
    @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.
     */
    @RestrictTo(LIBRARY)
    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) {
                    ((MediaRouteDynamicControllerDialog) mDialog).setRouteSelector(selector);
                }
            }
        }
    }

    /**
     * Called when the cast dialog is being created.
     */
    @RestrictTo(LIBRARY)
    @NonNull
    public MediaRouteDynamicControllerDialog onCreateDynamicControllerDialog(
            @NonNull Context context) {
        return new MediaRouteDynamicControllerDialog(context);
    }

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

    @Override
    @NonNull
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        if (mUseDynamicGroup) {
            mDialog = onCreateDynamicControllerDialog(getContext());
            ((MediaRouteDynamicControllerDialog) mDialog).setRouteSelector(mSelector);
        } else {
            mDialog = onCreateControllerDialog(getContext(), savedInstanceState);
        }
        return mDialog;
    }

    @Override
    public void onStop() {
        super.onStop();
        if (mDialog != null && !mUseDynamicGroup) {
            ((MediaRouteControllerDialog) mDialog).clearGroupListAnimation(false);
        }
    }

    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if (mDialog != null) {
            if (mUseDynamicGroup) {
                ((MediaRouteDynamicControllerDialog) mDialog).updateLayout();
            } else {
                ((MediaRouteControllerDialog) mDialog).updateLayout();
            }
        }
    }
}