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

Unified Diff: chromecast/shell/android/apk/src/org/chromium/chromecast/shell/CastWindowManager.java

Issue 490603002: Chromecast: initial checkin of Android-based cast shell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added android DEPS (git cl presubmit doesn't check Java DEPS?) Created 6 years, 3 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
Index: chromecast/shell/android/apk/src/org/chromium/chromecast/shell/CastWindowManager.java
diff --git a/chromecast/shell/android/apk/src/org/chromium/chromecast/shell/CastWindowManager.java b/chromecast/shell/android/apk/src/org/chromium/chromecast/shell/CastWindowManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..a8aca376072896409ea770f3fd27dccda5e1e3c3
--- /dev/null
+++ b/chromecast/shell/android/apk/src/org/chromium/chromecast/shell/CastWindowManager.java
@@ -0,0 +1,155 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chromecast.shell;
+
+import android.content.Context;
+import android.graphics.Color;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.widget.FrameLayout;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+import org.chromium.content.browser.ContentViewCore;
+import org.chromium.content.browser.ContentViewRenderView;
+import org.chromium.ui.base.WindowAndroid;
+
+/**
+ * Container and generator of CastWindow instances.
+ */
+@JNINamespace("chromecast::shell")
+public class CastWindowManager extends FrameLayout {
+ private static final String TAG = "CastWindowManager";
+
+ private WindowAndroid mWindow;
+ private CastWindowAndroid mActiveCastWindow;
+
+ // The target for all content rendering.
+ private ContentViewRenderView mContentViewRenderView;
+
+ /**
+ * Delegate to deliver events from the native window.
+ */
+ public interface Delegate {
+ public void onCreated();
+ public void onClosed();
+ }
+ private Delegate mDelegate;
+
+ /**
+ * Constructor for inflating via XML.
+ */
+ public CastWindowManager(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ nativeInit(this);
+ }
+
+ /**
+ * @param delegate Delegate to handle events.
+ */
+ public void setDelegate(Delegate delegate) {
+ mDelegate = delegate;
+ }
+
+ /**
+ * @param window Represents the activity window.
+ */
+ public void setWindow(WindowAndroid window) {
+ assert window != null;
+ mWindow = window;
+ mContentViewRenderView = new ContentViewRenderView(getContext()) {
+ @Override
+ protected void onReadyToRender() {
+ setOverlayVideoMode(true);
+ }
+ };
+ mContentViewRenderView.onNativeLibraryLoaded(window);
+ // Setting the background color to black avoids rendering a white splash screen
+ // before the players are loaded. See crbug/307113 for details.
+ mContentViewRenderView.setSurfaceViewBackgroundColor(Color.BLACK);
+ }
+
+ /**
+ * @return The window used to generate all shells.
+ */
+ public WindowAndroid getWindow() {
+ return mWindow;
+ }
+
+ /**
+ * @return The currently visible shell view or null if one is not showing.
+ */
+ public CastWindowAndroid getActiveCastWindow() {
+ return mActiveCastWindow;
+ }
+
+ /**
+ * Creates a new shell pointing to the specified URL.
+ * @param url The URL the shell should load upon creation.
+ * @return Pointer of native cast shell instance.
+ */
+ public long launchCastWindow(String url) {
+ return nativeLaunchCastWindow(url);
+ }
+
+ /**
+ * Stops a native cast shell instance created by {@link #launchCastWindow(String)}.
+ * @param nativeCastWindow Pointer of native cast shell instance returned
+ * by {@link #launchCastWindow(String)}.
+ * @see #launchCastWindow(String)
+ */
+ public void stopCastWindow(long nativeCastWindow) {
+ nativeStopCastWindow(nativeCastWindow);
+ }
+
+ @SuppressWarnings("unused")
+ @CalledByNative
+ private Object createCastWindow() {
+ assert mContentViewRenderView != null;
+ LayoutInflater inflater =
+ (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ CastWindowAndroid shellView =
+ (CastWindowAndroid) inflater.inflate(R.layout.cast_window_view, null);
+ shellView.setWindow(mWindow);
+
+ if (mActiveCastWindow != null) closeCastWindow(mActiveCastWindow);
+
+ shellView.setContentViewRenderView(mContentViewRenderView);
+ addView(shellView, new FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
+ mActiveCastWindow = shellView;
+ ContentViewCore contentViewCore = mActiveCastWindow.getContentViewCore();
+ if (contentViewCore != null) {
+ mContentViewRenderView.setCurrentContentViewCore(contentViewCore);
+ contentViewCore.onShow();
+ }
+
+ if (mDelegate != null) {
+ mDelegate.onCreated();
+ }
+
+ return shellView;
+ }
+
+ @SuppressWarnings("unused")
+ @CalledByNative
+ private void closeCastWindow(CastWindowAndroid shellView) {
+ if (shellView == mActiveCastWindow) mActiveCastWindow = null;
+ ContentViewCore contentViewCore = shellView.getContentViewCore();
+ if (contentViewCore != null) contentViewCore.onHide();
+ shellView.setContentViewRenderView(null);
+ shellView.setWindow(null);
+ removeView(shellView);
+
+ if (mDelegate != null) {
+ mDelegate.onClosed();
+ }
+ }
+
+ private static native void nativeInit(Object shellManagerInstance);
+ private static native long nativeLaunchCastWindow(String url);
+ private static native void nativeStopCastWindow(long pointerOfNativeCastWindow);
+ public static native void nativeEnableDevTools(boolean enable);
+}
« no previous file with comments | « chromecast/shell/android/apk/src/org/chromium/chromecast/shell/CastWindowAndroid.java ('k') | chromecast/shell/app/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698