| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.media.router; | 5 package org.chromium.chrome.browser.media.router; |
| 6 | 6 |
| 7 import android.content.Context; | |
| 8 import android.support.v7.app.MediaRouteChooserDialogFragment; | 7 import android.support.v7.app.MediaRouteChooserDialogFragment; |
| 9 import android.support.v7.app.MediaRouteControllerDialogFragment; | 8 import android.support.v7.app.MediaRouteControllerDialogFragment; |
| 10 | 9 |
| 11 import org.chromium.base.annotations.CalledByNative; | 10 import org.chromium.base.annotations.CalledByNative; |
| 12 import org.chromium.base.annotations.JNINamespace; | 11 import org.chromium.base.annotations.JNINamespace; |
| 13 import org.chromium.chrome.browser.media.router.cast.MediaSink; | 12 import org.chromium.chrome.browser.media.router.cast.MediaSink; |
| 14 import org.chromium.chrome.browser.media.router.cast.MediaSource; | 13 import org.chromium.chrome.browser.media.router.cast.MediaSource; |
| 15 | 14 |
| 16 /** | 15 /** |
| 17 * Implements the JNI interface called from the C++ Media Router dialog controll
er implementation | 16 * Implements the JNI interface called from the C++ Media Router dialog controll
er implementation |
| 18 * on Android. | 17 * on Android. |
| 19 */ | 18 */ |
| 20 @JNINamespace("media_router") | 19 @JNINamespace("media_router") |
| 21 public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega
te { | 20 public class ChromeMediaRouterDialogController implements MediaRouteDialogDelega
te { |
| 22 | 21 |
| 23 private static final String MEDIA_ROUTE_CONTROLLER_DIALOG_FRAGMENT = | 22 private static final String MEDIA_ROUTE_CONTROLLER_DIALOG_FRAGMENT = |
| 24 "android.support.v7.mediarouter:MediaRouteControllerDialogFragment"; | 23 "android.support.v7.mediarouter:MediaRouteControllerDialogFragment"; |
| 25 | 24 |
| 26 private final long mNativeDialogController; | 25 private final long mNativeDialogController; |
| 27 private final Context mApplicationContext; | |
| 28 private MediaRouteDialogManager mDialogManager; | 26 private MediaRouteDialogManager mDialogManager; |
| 29 | 27 |
| 30 /** | 28 /** |
| 31 * Returns a new initialized {@link ChromeMediaRouterDialogController}. | 29 * Returns a new initialized {@link ChromeMediaRouterDialogController}. |
| 32 * @param nativeDialogController the handle of the native object. | 30 * @param nativeDialogController the handle of the native object. |
| 33 * @param context the application context. | |
| 34 * @return a new dialog controller to use from the native side. | 31 * @return a new dialog controller to use from the native side. |
| 35 */ | 32 */ |
| 36 @CalledByNative | 33 @CalledByNative |
| 37 public static ChromeMediaRouterDialogController create( | 34 public static ChromeMediaRouterDialogController create(long nativeDialogCont
roller) { |
| 38 long nativeDialogController, Context context) { | 35 return new ChromeMediaRouterDialogController(nativeDialogController); |
| 39 return new ChromeMediaRouterDialogController(nativeDialogController, con
text); | |
| 40 } | 36 } |
| 41 | 37 |
| 42 /** | 38 /** |
| 43 * Shows the {@link MediaRouteChooserDialogFragment} if it's not shown yet. | 39 * Shows the {@link MediaRouteChooserDialogFragment} if it's not shown yet. |
| 44 * @param sourceUrn the URN identifying the media source to filter the devic
es with. | 40 * @param sourceUrn the URN identifying the media source to filter the devic
es with. |
| 45 */ | 41 */ |
| 46 @CalledByNative | 42 @CalledByNative |
| 47 public void openRouteChooserDialog(String sourceUrn) { | 43 public void openRouteChooserDialog(String sourceUrn) { |
| 48 if (isShowingDialog()) return; | 44 if (isShowingDialog()) return; |
| 49 | 45 |
| 50 MediaSource source = MediaSource.from(sourceUrn); | 46 MediaSource source = MediaSource.from(sourceUrn); |
| 51 if (source == null) return; | 47 if (source == null) return; |
| 52 | 48 |
| 53 mDialogManager = new MediaRouteChooserDialogManager(source, mApplication
Context, this); | 49 mDialogManager = new MediaRouteChooserDialogManager(source, this); |
| 54 mDialogManager.openDialog(); | 50 mDialogManager.openDialog(); |
| 55 } | 51 } |
| 56 | 52 |
| 57 /** | 53 /** |
| 58 * Shows the {@link MediaRouteControllerDialogFragment} if it's not shown ye
t. | 54 * Shows the {@link MediaRouteControllerDialogFragment} if it's not shown ye
t. |
| 59 * @param sourceUrn the URN identifying the media source of the current medi
a route. | 55 * @param sourceUrn the URN identifying the media source of the current medi
a route. |
| 60 * @param mediaRouteId the identifier of the route to be controlled. | 56 * @param mediaRouteId the identifier of the route to be controlled. |
| 61 */ | 57 */ |
| 62 @CalledByNative | 58 @CalledByNative |
| 63 public void openRouteControllerDialog(String sourceUrn, String mediaRouteId)
{ | 59 public void openRouteControllerDialog(String sourceUrn, String mediaRouteId)
{ |
| 64 if (isShowingDialog()) return; | 60 if (isShowingDialog()) return; |
| 65 | 61 |
| 66 MediaSource source = MediaSource.from(sourceUrn); | 62 MediaSource source = MediaSource.from(sourceUrn); |
| 67 if (source == null) return; | 63 if (source == null) return; |
| 68 | 64 |
| 69 mDialogManager = new MediaRouteControllerDialogManager( | 65 mDialogManager = new MediaRouteControllerDialogManager(source, mediaRout
eId, this); |
| 70 source, mediaRouteId, mApplicationContext, this); | |
| 71 mDialogManager.openDialog(); | 66 mDialogManager.openDialog(); |
| 72 } | 67 } |
| 73 | 68 |
| 74 /** | 69 /** |
| 75 * Closes the currently open dialog if it's open. | 70 * Closes the currently open dialog if it's open. |
| 76 */ | 71 */ |
| 77 @CalledByNative | 72 @CalledByNative |
| 78 public void closeDialog() { | 73 public void closeDialog() { |
| 79 if (!isShowingDialog()) return; | 74 if (!isShowingDialog()) return; |
| 80 | 75 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 107 // For MediaRouteControllerDialog this method will be called in case the
route is closed | 102 // For MediaRouteControllerDialog this method will be called in case the
route is closed |
| 108 // since it only call onDismiss() and there's no way to distinguish betw
een the two. | 103 // since it only call onDismiss() and there's no way to distinguish betw
een the two. |
| 109 // Here we can figure it out: if mDialogManager is null, onRouteClosed()
was called and | 104 // Here we can figure it out: if mDialogManager is null, onRouteClosed()
was called and |
| 110 // there's no need to tell the native controller the dialog has been can
celled. | 105 // there's no need to tell the native controller the dialog has been can
celled. |
| 111 if (mDialogManager == null) return; | 106 if (mDialogManager == null) return; |
| 112 | 107 |
| 113 mDialogManager = null; | 108 mDialogManager = null; |
| 114 nativeOnDialogCancelled(mNativeDialogController); | 109 nativeOnDialogCancelled(mNativeDialogController); |
| 115 } | 110 } |
| 116 | 111 |
| 117 private ChromeMediaRouterDialogController(long nativeDialogController, Conte
xt context) { | 112 private ChromeMediaRouterDialogController(long nativeDialogController) { |
| 118 mNativeDialogController = nativeDialogController; | 113 mNativeDialogController = nativeDialogController; |
| 119 mApplicationContext = context; | |
| 120 } | 114 } |
| 121 | 115 |
| 122 native void nativeOnDialogCancelled(long nativeMediaRouterDialogControllerAn
droid); | 116 native void nativeOnDialogCancelled(long nativeMediaRouterDialogControllerAn
droid); |
| 123 native void nativeOnSinkSelected( | 117 native void nativeOnSinkSelected( |
| 124 long nativeMediaRouterDialogControllerAndroid, String sinkId); | 118 long nativeMediaRouterDialogControllerAndroid, String sinkId); |
| 125 native void nativeOnRouteClosed(long nativeMediaRouterDialogControllerAndroi
d, String routeId); | 119 native void nativeOnRouteClosed(long nativeMediaRouterDialogControllerAndroi
d, String routeId); |
| 126 } | 120 } |
| OLD | NEW |