Index: chrome/android/java/src/org/chromium/chrome/browser/media/remote/OverlayDialog.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/OverlayDialog.java b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/OverlayDialog.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fde79143acc1e8b7d4d4dc552d186887a7280d21 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/OverlayDialog.java |
@@ -0,0 +1,89 @@ |
+// Copyright 2013 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.chrome.browser.media.remote; |
+ |
+import android.app.Activity; |
+import android.app.Dialog; |
+import android.graphics.drawable.ColorDrawable; |
+import android.view.Gravity; |
+import android.view.MotionEvent; |
+import android.view.View; |
+import android.view.ViewGroup; |
+import android.view.Window; |
+import android.view.WindowManager; |
+import android.widget.LinearLayout; |
+ |
+/** |
+ * In order to have a true overlay onto the full screen activity, we need to create a separate |
+ * {@link android.view.Window}. By using normal view hierarchy of the activity, we cannot put |
+ * the button on top of the video (if they intersect, as in landscape mode) because the video |
+ * is shown with {@link android.view.SurfaceView}, and it is set to be on top. Since it is a |
+ * special kind of view, it doesn't respect normal views' Z hierarchy. |
+ * |
+ * One way to create a new window is through creating a dialog. The more preferred ways of |
+ * creating a dialog are {@link android.app.Activity#showDialog(int)} or {@link |
+ * android.app.DialogFragment}. We don't use the former because it requires changes to upstream |
+ * full screen activity code. The latter can be used, but requires quite more additional work. |
+ * |
+ * TODO(cimamoglu): Use {@link android.app.DialogFragment}. |
+ * Relevant Android chatty discussion: |
+ * https://groups.google.com/a/google.com/d/topic/android-chatty-eng/9JKrya_20m0/discussion |
+ */ |
+public class OverlayDialog extends Dialog { |
+ private View.OnTouchListener mOutsideTouchHandler; |
+ private ViewGroup mRootView; |
+ |
+ public OverlayDialog(Activity activity, View.OnTouchListener outsideTouchHandler) { |
+ super(activity, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); |
+ mOutsideTouchHandler = outsideTouchHandler; |
+ |
+ requestWindowFeature(Window.FEATURE_NO_TITLE); |
+ Window dialogWindow = getWindow(); |
+ WindowManager.LayoutParams dialogLayoutParams = dialogWindow.getAttributes(); |
+ dialogLayoutParams.x = 0; |
+ dialogLayoutParams.y = 0; |
+ dialogLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; |
+ dialogLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT; |
+ dialogLayoutParams.gravity = Gravity.TOP | Gravity.START; |
+ dialogWindow.setAttributes(dialogLayoutParams); |
+ dialogWindow.setBackgroundDrawable( |
+ new ColorDrawable(android.graphics.Color.TRANSPARENT)); |
+ |
+ // We would like to intercept touch events of the dialog's content, but want to be |
+ // able to pass down the ones that are outside. |
+ dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
+ |
+ // This flag makes sure that soft key events are not handled by the dialog window. |
+ dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); |
+ |
+ // We want to intercept ACTION_OUTSIDE events so we can pass them down to the relevant |
+ // handler. |
+ dialogWindow.addFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH); |
+ |
+ // We don't want to cancel, we just want to hide/show. |
+ setCancelable(false); |
+ setCanceledOnTouchOutside(false); |
+ |
+ // Create a container/root view for the dialog. |
+ LinearLayout layout = new LinearLayout(activity); |
+ WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams( |
+ ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); |
+ layout.setLayoutParams(layoutParams); |
+ layout.setOrientation(LinearLayout.VERTICAL); |
+ mRootView = layout; |
+ setContentView(mRootView); |
+ } |
+ |
+ public ViewGroup getRootView() { |
+ return mRootView; |
+ } |
+ |
+ @Override |
+ public boolean dispatchTouchEvent(MotionEvent event) { |
+ if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { |
+ mOutsideTouchHandler.onTouch(null, event); |
+ } |
+ return super.dispatchTouchEvent(event); |
+ } |
+} |