summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/MediaRouteActionProvider.java32
-rw-r--r--core/java/android/app/MediaRouteButton.java50
2 files changed, 79 insertions, 3 deletions
diff --git a/core/java/android/app/MediaRouteActionProvider.java b/core/java/android/app/MediaRouteActionProvider.java
index 5fe08ec..4860182 100644
--- a/core/java/android/app/MediaRouteActionProvider.java
+++ b/core/java/android/app/MediaRouteActionProvider.java
@@ -16,7 +16,10 @@
package android.app;
+import com.android.internal.app.MediaRouteChooserDialogFragment;
+
import android.content.Context;
+import android.content.ContextWrapper;
import android.media.MediaRouter;
import android.media.MediaRouter.RouteInfo;
import android.util.Log;
@@ -83,10 +86,37 @@ public class MediaRouteActionProvider extends ActionProvider {
@Override
public boolean onPerformDefaultAction() {
- // Show routing dialog
+ final FragmentManager fm = getActivity().getFragmentManager();
+ // See if one is already attached to this activity.
+ MediaRouteChooserDialogFragment dialogFragment =
+ (MediaRouteChooserDialogFragment) fm.findFragmentByTag(
+ MediaRouteChooserDialogFragment.FRAGMENT_TAG);
+ if (dialogFragment != null) {
+ Log.w(TAG, "onPerformDefaultAction(): Chooser dialog already showing!");
+ return false;
+ }
+
+ dialogFragment = new MediaRouteChooserDialogFragment();
+ dialogFragment.setExtendedSettingsClickListener(mExtendedSettingsListener);
+ dialogFragment.setRouteTypes(mRouteTypes);
+ dialogFragment.show(fm, MediaRouteChooserDialogFragment.FRAGMENT_TAG);
return true;
}
+ private Activity getActivity() {
+ // Gross way of unwrapping the Activity so we can get the FragmentManager
+ Context context = mContext;
+ while (context instanceof ContextWrapper && !(context instanceof Activity)) {
+ context = ((ContextWrapper) context).getBaseContext();
+ }
+ if (!(context instanceof Activity)) {
+ throw new IllegalStateException("The MediaRouteActionProvider's Context " +
+ "is not an Activity.");
+ }
+
+ return (Activity) context;
+ }
+
public void setExtendedSettingsClickListener(View.OnClickListener listener) {
mExtendedSettingsListener = listener;
if (mView != null) {
diff --git a/core/java/android/app/MediaRouteButton.java b/core/java/android/app/MediaRouteButton.java
index 385241c..a4eebda 100644
--- a/core/java/android/app/MediaRouteButton.java
+++ b/core/java/android/app/MediaRouteButton.java
@@ -17,8 +17,10 @@
package android.app;
import com.android.internal.R;
+import com.android.internal.app.MediaRouteChooserDialogFragment;
import android.content.Context;
+import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
@@ -44,6 +46,7 @@ public class MediaRouteButton extends View {
private int mMinHeight;
private OnClickListener mExtendedSettingsClickListener;
+ private MediaRouteChooserDialogFragment mDialogFragment;
private static final int[] ACTIVATED_STATE_SET = {
R.attr.state_activated
@@ -112,7 +115,7 @@ public class MediaRouteButton extends View {
}
}
} else {
- Log.d(TAG, "TODO: Implement the dialog!");
+ showDialog();
}
return handled;
@@ -263,8 +266,51 @@ public class MediaRouteButton extends View {
}
public void setExtendedSettingsClickListener(OnClickListener listener) {
- // TODO: if dialog is already open, propagate so that it updates live.
mExtendedSettingsClickListener = listener;
+ if (mDialogFragment != null) {
+ mDialogFragment.setExtendedSettingsClickListener(listener);
+ }
+ }
+
+ /**
+ * Asynchronously show the route chooser dialog.
+ * This will attach a {@link DialogFragment} to the containing Activity.
+ */
+ public void showDialog() {
+ final FragmentManager fm = getActivity().getFragmentManager();
+ if (mDialogFragment == null) {
+ // See if one is already attached to this activity.
+ mDialogFragment = (MediaRouteChooserDialogFragment) fm.findFragmentByTag(
+ MediaRouteChooserDialogFragment.FRAGMENT_TAG);
+ }
+ if (mDialogFragment != null) {
+ Log.w(TAG, "showDialog(): Already showing!");
+ return;
+ }
+
+ mDialogFragment = new MediaRouteChooserDialogFragment();
+ mDialogFragment.setExtendedSettingsClickListener(mExtendedSettingsClickListener);
+ mDialogFragment.setLauncherListener(new MediaRouteChooserDialogFragment.LauncherListener() {
+ @Override
+ public void onDetached(MediaRouteChooserDialogFragment detachedFragment) {
+ mDialogFragment = null;
+ }
+ });
+ mDialogFragment.setRouteTypes(mRouteTypes);
+ mDialogFragment.show(fm, MediaRouteChooserDialogFragment.FRAGMENT_TAG);
+ }
+
+ private Activity getActivity() {
+ // Gross way of unwrapping the Activity so we can get the FragmentManager
+ Context context = getContext();
+ while (context instanceof ContextWrapper && !(context instanceof Activity)) {
+ context = ((ContextWrapper) context).getBaseContext();
+ }
+ if (!(context instanceof Activity)) {
+ throw new IllegalStateException("The MediaRouteButton's Context is not an Activity.");
+ }
+
+ return (Activity) context;
}
private class MediaRouteCallback extends MediaRouter.SimpleCallback {