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

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

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

Powered by Google App Engine
This is Rietveld 408576698