blob: ae362af74837248deda2a1ada380e3589e8d9d11 [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;
Jeff Brown0abd3a62013-11-09 17:48:23 -080024import android.view.View.OnClickListener;
Adam Powell70e11e52012-06-12 16:59:45 -070025
26/**
Jeff Brown0abd3a62013-11-09 17:48:23 -080027 * Media route chooser dialog fragment.
28 * <p>
29 * Creates a {@link MediaRouteChooserDialog}. The application may subclass
30 * this dialog fragment to customize the media route chooser dialog.
31 * </p>
Adam Powell70e11e52012-06-12 16:59:45 -070032 *
Jeff Brown0abd3a62013-11-09 17:48:23 -080033 * TODO: Move this back into the API, as in the support library media router.
Adam Powell70e11e52012-06-12 16:59:45 -070034 */
35public class MediaRouteChooserDialogFragment extends DialogFragment {
Jeff Brown0abd3a62013-11-09 17:48:23 -080036 private final String ARGUMENT_ROUTE_TYPES = "routeTypes";
Adam Powell70e11e52012-06-12 16:59:45 -070037
Jeff Brown0abd3a62013-11-09 17:48:23 -080038 private View.OnClickListener mExtendedSettingsClickListener;
Adam Powelld6d0bdd2012-06-13 23:15:49 -070039
Jeff Brown0abd3a62013-11-09 17:48:23 -080040 /**
41 * Creates a media route chooser dialog fragment.
42 * <p>
43 * All subclasses of this class must also possess a default constructor.
44 * </p>
45 */
Adam Powell70e11e52012-06-12 16:59:45 -070046 public MediaRouteChooserDialogFragment() {
Jeff Brown0abd3a62013-11-09 17:48:23 -080047 setCancelable(true);
48 setStyle(STYLE_NORMAL, android.R.style.Theme_DeviceDefault_Dialog);
Adam Powell70e11e52012-06-12 16:59:45 -070049 }
50
Jeff Brown0abd3a62013-11-09 17:48:23 -080051 public int getRouteTypes() {
52 Bundle args = getArguments();
53 return args != null ? args.getInt(ARGUMENT_ROUTE_TYPES) : 0;
Adam Powell70e11e52012-06-12 16:59:45 -070054 }
55
56 public void setRouteTypes(int types) {
Jeff Brown0abd3a62013-11-09 17:48:23 -080057 if (types != getRouteTypes()) {
58 Bundle args = getArguments();
59 if (args == null) {
60 args = new Bundle();
Adam Powell70e11e52012-06-12 16:59:45 -070061 }
Jeff Brown0abd3a62013-11-09 17:48:23 -080062 args.putInt(ARGUMENT_ROUTE_TYPES, types);
63 setArguments(args);
Adam Powell70e11e52012-06-12 16:59:45 -070064
Jeff Brown0abd3a62013-11-09 17:48:23 -080065 MediaRouteChooserDialog dialog = (MediaRouteChooserDialog)getDialog();
66 if (dialog != null) {
67 dialog.setRouteTypes(types);
Adam Powelld6d0bdd2012-06-13 23:15:49 -070068 }
69 }
Adam Powell45996962012-06-16 14:58:39 -070070 }
Adam Powell0d03c042012-06-14 16:04:12 -070071
Jeff Brown0abd3a62013-11-09 17:48:23 -080072 public void setExtendedSettingsClickListener(View.OnClickListener listener) {
73 if (listener != mExtendedSettingsClickListener) {
74 mExtendedSettingsClickListener = listener;
Adam Powell0d03c042012-06-14 16:04:12 -070075
Jeff Brown0abd3a62013-11-09 17:48:23 -080076 MediaRouteChooserDialog dialog = (MediaRouteChooserDialog)getDialog();
77 if (dialog != null) {
78 dialog.setExtendedSettingsClickListener(listener);
Adam Powell8e37a852012-06-20 15:56:39 -070079 }
80 }
Adam Powell45996962012-06-16 14:58:39 -070081 }
82
83 /**
Jeff Brown0abd3a62013-11-09 17:48:23 -080084 * Called when the chooser dialog is being created.
85 * <p>
86 * Subclasses may override this method to customize the dialog.
87 * </p>
Adam Powell45996962012-06-16 14:58:39 -070088 */
Jeff Brown0abd3a62013-11-09 17:48:23 -080089 public MediaRouteChooserDialog onCreateChooserDialog(
90 Context context, Bundle savedInstanceState) {
91 return new MediaRouteChooserDialog(context, getTheme());
Adam Powell45996962012-06-16 14:58:39 -070092 }
93
Jeff Brown0abd3a62013-11-09 17:48:23 -080094 @Override
95 public Dialog onCreateDialog(Bundle savedInstanceState) {
96 MediaRouteChooserDialog dialog = onCreateChooserDialog(getActivity(), savedInstanceState);
97 dialog.setRouteTypes(getRouteTypes());
98 dialog.setExtendedSettingsClickListener(mExtendedSettingsClickListener);
99 return dialog;
Adam Powell70e11e52012-06-12 16:59:45 -0700100 }
101}