| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.app; |
| 18 |
|
| 19 |
|
| 20 |
import android.app.Activity; |
| 21 |
import android.app.Dialog; |
| 22 |
import android.app.DialogFragment; |
| 23 |
import android.app.FragmentManager; |
| 24 |
import android.content.Context; |
| 25 |
import android.media.MediaRouter; |
| 26 |
import android.util.Log; |
| 27 |
import android.view.View; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public abstract class MediaRouteDialogPresenter { |
| 34 |
private static final String TAG = "MediaRouter"; |
| 35 |
|
| 36 |
private static final String CHOOSER_FRAGMENT_TAG = |
| 37 |
"android.app.MediaRouteButton:MediaRouteChooserDialogFragment"; |
| 38 |
private static final String CONTROLLER_FRAGMENT_TAG = |
| 39 |
"android.app.MediaRouteButton:MediaRouteControllerDialogFragment"; |
| 40 |
|
| 41 |
public static DialogFragment showDialogFragment(Activity activity, |
| 42 |
int routeTypes, View.OnClickListener extendedSettingsClickListener) { |
| 43 |
final MediaRouter router = (MediaRouter)activity.getSystemService( |
| 44 |
Context.MEDIA_ROUTER_SERVICE); |
| 45 |
final FragmentManager fm = activity.getFragmentManager(); |
| 46 |
|
| 47 |
MediaRouter.RouteInfo route = router.getSelectedRoute(); |
| 48 |
if (route.isDefault() || !route.matchesTypes(routeTypes)) { |
| 49 |
if (fm.findFragmentByTag(CHOOSER_FRAGMENT_TAG) != null) { |
| 50 |
Log.w(TAG, "showDialog(): Route chooser dialog already showing!"); |
| 51 |
return null; |
| 52 |
} |
| 53 |
MediaRouteChooserDialogFragment f = new MediaRouteChooserDialogFragment(); |
| 54 |
f.setRouteTypes(routeTypes); |
| 55 |
f.setExtendedSettingsClickListener(extendedSettingsClickListener); |
| 56 |
f.show(fm, CHOOSER_FRAGMENT_TAG); |
| 57 |
return f; |
| 58 |
} else { |
| 59 |
if (fm.findFragmentByTag(CONTROLLER_FRAGMENT_TAG) != null) { |
| 60 |
Log.w(TAG, "showDialog(): Route controller dialog already showing!"); |
| 61 |
return null; |
| 62 |
} |
| 63 |
MediaRouteControllerDialogFragment f = new MediaRouteControllerDialogFragment(); |
| 64 |
f.show(fm, CONTROLLER_FRAGMENT_TAG); |
| 65 |
return f; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
public static Dialog createDialog(Context context, |
| 71 |
int routeTypes, View.OnClickListener extendedSettingsClickListener) { |
| 72 |
int theme = MediaRouteChooserDialog.isLightTheme(context) |
| 73 |
? android.R.style.Theme_DeviceDefault_Light_Dialog |
| 74 |
: android.R.style.Theme_DeviceDefault_Dialog; |
| 75 |
return createDialog(context, routeTypes, extendedSettingsClickListener, theme); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public static Dialog createDialog(Context context, |
| 80 |
int routeTypes, View.OnClickListener extendedSettingsClickListener, int theme) { |
| 81 |
return createDialog(context, routeTypes, extendedSettingsClickListener, theme, |
| 82 |
true ); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
public static Dialog createDialog(Context context, int routeTypes, |
| 87 |
View.OnClickListener extendedSettingsClickListener, int theme, |
| 88 |
boolean showProgressBarWhenEmpty) { |
| 89 |
final MediaRouter router = context.getSystemService(MediaRouter.class); |
| 90 |
|
| 91 |
MediaRouter.RouteInfo route = router.getSelectedRoute(); |
| 92 |
if (route.isDefault() || !route.matchesTypes(routeTypes)) { |
| 93 |
final MediaRouteChooserDialog d = new MediaRouteChooserDialog(context, theme, |
| 94 |
showProgressBarWhenEmpty); |
| 95 |
d.setRouteTypes(routeTypes); |
| 96 |
d.setExtendedSettingsClickListener(extendedSettingsClickListener); |
| 97 |
return d; |
| 98 |
} else { |
| 99 |
return new MediaRouteControllerDialog(context, theme); |
| 100 |
} |
| 101 |
} |
| 102 |
} |