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