Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterDialogController.java

Issue 1277883003: [PresentationAPI,Android] Implement the ChromeMediaRouterDialogController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media-router-dialog-controller-jni
Patch Set: Corrected Cast URN domain and close the dialog fragment upon dialog dismissal. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/MediaSource.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterDialogController.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterDialogController.java b/chrome/android/java/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterDialogController.java
index 1b3a473bbbe900fb7f229bd5a613eff34132bb31..48946898573edfc24c89e3da3764f4dbe7beb303 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterDialogController.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/router/ChromeMediaRouterDialogController.java
@@ -4,23 +4,43 @@
package org.chromium.chrome.browser.media.router;
+import android.app.Dialog;
import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnDismissListener;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.app.FragmentManager;
+import android.support.v7.app.MediaRouteChooserDialogFragment;
+import android.support.v7.app.MediaRouteDialogFactory;
+import android.support.v7.media.MediaRouteSelector;
+import android.support.v7.media.MediaRouter;
+import android.support.v7.media.MediaRouter.Callback;
+import org.chromium.base.ApplicationStatus;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
+import org.chromium.chrome.browser.media.remote.ChromeMediaRouteDialogFactory;
+import org.chromium.chrome.browser.media.router.cast.MediaSource;
/**
* Implements the JNI interface called from the C++ Media Router dialog controller implementation
* on Android.
*/
@JNINamespace("media_router")
-public class ChromeMediaRouterDialogController {
- private static final String TAG = "cr.MediaRouter";
+public class ChromeMediaRouterDialogController extends MediaRouter.Callback
+ implements OnDismissListener {
+ private static final String MEDIA_ROUTE_CHOOSER_DIALOG_FRAGMENT =
+ "android.support.v7.mediarouter:MediaRouteChooserDialogFragment";
private final long mNativeDialogController;
+ private final MediaRouter mAndroidMediaRouter;
+ private MediaRouteChooserDialogFragment mChooserDialogFragment;
/**
- * Initializes the media router and its providers.
+ * Returns a new initialized {@link ChromeMediaRouterDialogController}.
+ * @param nativeDialogController the handle of the native object.
+ * @param context the application context.
+ * @return a new dialog controller to use from the native side.
*/
@CalledByNative
public static ChromeMediaRouterDialogController create(
@@ -28,7 +48,92 @@ public class ChromeMediaRouterDialogController {
return new ChromeMediaRouterDialogController(nativeDialogController, context);
}
+ /**
+ * Shows the {@link MediaRouteChooserDialogFragment} dialog if it's not shown yet.
+ * @param sourceUrn the URN identifying the media source to filter the devices with.
+ */
+ @CalledByNative
+ public void createDialog(String sourceUrn) {
+ if (isShowingDialog()) return;
+
+ MediaSource mediaSource = MediaSource.from(sourceUrn);
+ if (mediaSource == null) return;
+
+ FragmentActivity currentActivity =
+ (FragmentActivity) ApplicationStatus.getLastTrackedFocusedActivity();
+ if (currentActivity == null) return;
+
+ FragmentManager fm = currentActivity.getSupportFragmentManager();
+ if (fm == null) return;
+
+ if (fm.findFragmentByTag(MEDIA_ROUTE_CHOOSER_DIALOG_FRAGMENT) != null) return;
+
+ MediaRouteSelector selector = mediaSource.buildRouteSelector();
+ mAndroidMediaRouter.addCallback(selector, this);
+
+ MediaRouteDialogFactory factory = new ChromeMediaRouteDialogFactory();
+ mChooserDialogFragment = factory.onCreateChooserDialogFragment();
+ mChooserDialogFragment.setRouteSelector(selector);
+ mChooserDialogFragment.show(fm, MEDIA_ROUTE_CHOOSER_DIALOG_FRAGMENT);
+ fm.executePendingTransactions();
+
+ Dialog dialog = mChooserDialogFragment.getDialog();
+ if (dialog == null) {
+ closeDialog();
+ return;
+ }
+
+ dialog.setOnDismissListener(this);
+ }
+
+ /**
+ * Closes the currently open dialog if it's open.
+ */
+ @CalledByNative
+ public void closeDialog() {
+ if (!isShowingDialog()) return;
+
+ // Will remove MediaRouter.Callback in onDismiss().
+ mChooserDialogFragment.dismiss();
+ mChooserDialogFragment = null;
+ }
+
+ /**
+ * @return if the media route chooser dialog is currently open.
+ */
+ @CalledByNative
+ public boolean isShowingDialog() {
+ return mChooserDialogFragment != null && mChooserDialogFragment.isVisible();
+ }
+
+ /**
+ * {@link Callback} implementation.
+ */
+ @Override
+ public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo route) {
+ closeDialog();
+ }
+
+ /**
+ * {@link OnDialogDismissListener} implementation.
+ */
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ mAndroidMediaRouter.removeCallback(this);
+ mChooserDialogFragment.dismiss();
+ mChooserDialogFragment = null;
+ }
+
private ChromeMediaRouterDialogController(long nativeDialogController, Context context) {
mNativeDialogController = nativeDialogController;
+ MediaRouter androidMediaRouter = null;
+ try {
+ // Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
+ // so getting the MediaRouter instance will throw an exception.
+ androidMediaRouter = MediaRouter.getInstance(context);
+ } catch (NoSuchMethodError e) {
+ androidMediaRouter = null;
+ }
+ mAndroidMediaRouter = androidMediaRouter;
}
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/MediaSource.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698