blob: 237feed01b18df4a413a13aa01b83497b2a3e834 [file] [log] [blame]
Adam Powell70e11e52012-06-12 16:59:45 -07001/*
Jeff Brown0abd3a62013-11-09 17:48:23 -08002 * Copyright (C) 2013 The Android Open Source Project
Adam Powell70e11e52012-06-12 16:59:45 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.app;
18
Adam Powelld6d0bdd2012-06-13 23:15:49 -070019import android.app.Dialog;
Adam Powell70e11e52012-06-12 16:59:45 -070020import android.app.DialogFragment;
Adam Powell70e11e52012-06-12 16:59:45 -070021import android.content.Context;
Adam Powell70e11e52012-06-12 16:59:45 -070022import android.os.Bundle;
Adam Powell70e11e52012-06-12 16:59:45 -070023import android.view.View;
Adam Powell70e11e52012-06-12 16:59:45 -070024
25/**
Jeff Brown0abd3a62013-11-09 17:48:23 -080026 * Media route chooser dialog fragment.
27 * <p>
28 * Creates a {@link MediaRouteChooserDialog}. The application may subclass
29 * this dialog fragment to customize the media route chooser dialog.
30 * </p>
Adam Powell70e11e52012-06-12 16:59:45 -070031 *
Jeff Brown0abd3a62013-11-09 17:48:23 -080032 * TODO: Move this back into the API, as in the support library media router.
Adam Powell70e11e52012-06-12 16:59:45 -070033 */
34public class MediaRouteChooserDialogFragment extends DialogFragment {
Jeff Brown0abd3a62013-11-09 17:48:23 -080035 private final String ARGUMENT_ROUTE_TYPES = "routeTypes";
Adam Powell70e11e52012-06-12 16:59:45 -070036
Jeff Brown0abd3a62013-11-09 17:48:23 -080037 private View.OnClickListener mExtendedSettingsClickListener;
Adam Powelld6d0bdd2012-06-13 23:15:49 -070038
Jeff Brown0abd3a62013-11-09 17:48:23 -080039 /**
40 * Creates a media route chooser dialog fragment.
41 * <p>
42 * All subclasses of this class must also possess a default constructor.
43 * </p>
44 */
Adam Powell70e11e52012-06-12 16:59:45 -070045 public MediaRouteChooserDialogFragment() {
Jeff Brown0abd3a62013-11-09 17:48:23 -080046 setCancelable(true);
47 setStyle(STYLE_NORMAL, android.R.style.Theme_DeviceDefault_Dialog);
Adam Powell70e11e52012-06-12 16:59:45 -070048 }
49
Jeff Brown0abd3a62013-11-09 17:48:23 -080050 public int getRouteTypes() {
51 Bundle args = getArguments();
52 return args != null ? args.getInt(ARGUMENT_ROUTE_TYPES) : 0;
Adam Powell70e11e52012-06-12 16:59:45 -070053 }
54
55 public void setRouteTypes(int types) {
Jeff Brown0abd3a62013-11-09 17:48:23 -080056 if (types != getRouteTypes()) {
57 Bundle args = getArguments();
58 if (args == null) {
59 args = new Bundle();
Adam Powell70e11e52012-06-12 16:59:45 -070060 }
Jeff Brown0abd3a62013-11-09 17:48:23 -080061 args.putInt(ARGUMENT_ROUTE_TYPES, types);
62 setArguments(args);
Adam Powell70e11e52012-06-12 16:59:45 -070063
Jeff Brown0abd3a62013-11-09 17:48:23 -080064 MediaRouteChooserDialog dialog = (MediaRouteChooserDialog)getDialog();
65 if (dialog != null) {
66 dialog.setRouteTypes(types);
Adam Powelld6d0bdd2012-06-13 23:15:49 -070067 }
68 }
Adam Powell45996962012-06-16 14:58:39 -070069 }
Adam Powell0d03c042012-06-14 16:04:12 -070070
Jeff Brown0abd3a62013-11-09 17:48:23 -080071 public void setExtendedSettingsClickListener(View.OnClickListener listener) {
72 if (listener != mExtendedSettingsClickListener) {
73 mExtendedSettingsClickListener = listener;
Adam Powell0d03c042012-06-14 16:04:12 -070074
Jeff Brown0abd3a62013-11-09 17:48:23 -080075 MediaRouteChooserDialog dialog = (MediaRouteChooserDialog)getDialog();
76 if (dialog != null) {
77 dialog.setExtendedSettingsClickListener(listener);
Adam Powell8e37a852012-06-20 15:56:39 -070078 }
79 }
Adam Powell45996962012-06-16 14:58:39 -070080 }
81
82 /**
Jeff Brown0abd3a62013-11-09 17:48:23 -080083 * Called when the chooser dialog is being created.
84 * <p>
85 * Subclasses may override this method to customize the dialog.
86 * </p>
Adam Powell45996962012-06-16 14:58:39 -070087 */
Jeff Brown0abd3a62013-11-09 17:48:23 -080088 public MediaRouteChooserDialog onCreateChooserDialog(
89 Context context, Bundle savedInstanceState) {
90 return new MediaRouteChooserDialog(context, getTheme());
Adam Powell45996962012-06-16 14:58:39 -070091 }
92
Jeff Brown0abd3a62013-11-09 17:48:23 -080093 @Override
94 public Dialog onCreateDialog(Bundle savedInstanceState) {
95 MediaRouteChooserDialog dialog = onCreateChooserDialog(getActivity(), savedInstanceState);
96 dialog.setRouteTypes(getRouteTypes());
97 dialog.setExtendedSettingsClickListener(mExtendedSettingsClickListener);
98 return dialog;
Adam Powell70e11e52012-06-12 16:59:45 -070099 }
100}