Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 1 | /* |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package com.android.internal.app; |
| 18 | |
Adam Powell | d6d0bdd | 2012-06-13 23:15:49 -0700 | [diff] [blame] | 19 | import android.app.Dialog; |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 20 | import android.app.DialogFragment; |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 21 | import android.content.Context; |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 23 | import android.view.View; |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 26 | * 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 Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 31 | * |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 32 | * TODO: Move this back into the API, as in the support library media router. |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 33 | */ |
| 34 | public class MediaRouteChooserDialogFragment extends DialogFragment { |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 35 | private final String ARGUMENT_ROUTE_TYPES = "routeTypes"; |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 36 | |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 37 | private View.OnClickListener mExtendedSettingsClickListener; |
Adam Powell | d6d0bdd | 2012-06-13 23:15:49 -0700 | [diff] [blame] | 38 | |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 39 | /** |
| 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 Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 45 | public MediaRouteChooserDialogFragment() { |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 46 | setCancelable(true); |
| 47 | setStyle(STYLE_NORMAL, android.R.style.Theme_DeviceDefault_Dialog); |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 50 | public int getRouteTypes() { |
| 51 | Bundle args = getArguments(); |
| 52 | return args != null ? args.getInt(ARGUMENT_ROUTE_TYPES) : 0; |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | public void setRouteTypes(int types) { |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 56 | if (types != getRouteTypes()) { |
| 57 | Bundle args = getArguments(); |
| 58 | if (args == null) { |
| 59 | args = new Bundle(); |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 60 | } |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 61 | args.putInt(ARGUMENT_ROUTE_TYPES, types); |
| 62 | setArguments(args); |
Adam Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 63 | |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 64 | MediaRouteChooserDialog dialog = (MediaRouteChooserDialog)getDialog(); |
| 65 | if (dialog != null) { |
| 66 | dialog.setRouteTypes(types); |
Adam Powell | d6d0bdd | 2012-06-13 23:15:49 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
Adam Powell | 4599696 | 2012-06-16 14:58:39 -0700 | [diff] [blame] | 69 | } |
Adam Powell | 0d03c04 | 2012-06-14 16:04:12 -0700 | [diff] [blame] | 70 | |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 71 | public void setExtendedSettingsClickListener(View.OnClickListener listener) { |
| 72 | if (listener != mExtendedSettingsClickListener) { |
| 73 | mExtendedSettingsClickListener = listener; |
Adam Powell | 0d03c04 | 2012-06-14 16:04:12 -0700 | [diff] [blame] | 74 | |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 75 | MediaRouteChooserDialog dialog = (MediaRouteChooserDialog)getDialog(); |
| 76 | if (dialog != null) { |
| 77 | dialog.setExtendedSettingsClickListener(listener); |
Adam Powell | 8e37a85 | 2012-06-20 15:56:39 -0700 | [diff] [blame] | 78 | } |
| 79 | } |
Adam Powell | 4599696 | 2012-06-16 14:58:39 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /** |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 83 | * Called when the chooser dialog is being created. |
| 84 | * <p> |
| 85 | * Subclasses may override this method to customize the dialog. |
| 86 | * </p> |
Adam Powell | 4599696 | 2012-06-16 14:58:39 -0700 | [diff] [blame] | 87 | */ |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 88 | public MediaRouteChooserDialog onCreateChooserDialog( |
| 89 | Context context, Bundle savedInstanceState) { |
| 90 | return new MediaRouteChooserDialog(context, getTheme()); |
Adam Powell | 4599696 | 2012-06-16 14:58:39 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Jeff Brown | 0abd3a6 | 2013-11-09 17:48:23 -0800 | [diff] [blame] | 93 | @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 Powell | 70e11e5 | 2012-06-12 16:59:45 -0700 | [diff] [blame] | 99 | } |
| 100 | } |