Enable full screen video.
authorSoren Stoutner <soren@stoutner.com>
Wed, 9 Dec 2015 23:57:34 +0000 (16:57 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 9 Dec 2015 23:57:34 +0000 (16:57 -0700)
.idea/dictionaries/soren.xml
app/src/main/java/com/stoutner/privacybrowser/Webview.java
app/src/main/res/layout/activity_webview.xml

index 5c98ab4c778da94babf4c2a9cac095ca40d42203..a29dfbc440954a5c334ffd90a53eb4cadff12db6 100644 (file)
@@ -2,6 +2,8 @@
   <dictionary name="soren">
     <words>
       <w>duckduckgo</w>
+      <w>rehide</w>
+      <w>rehides</w>
       <w>webview</w>
     </words>
   </dictionary>
index 70315bf8197f210229b7c7e0a71dfdf89bdae943..5f1e87239a5a009f22d67723638928c8f7aed975 100644 (file)
@@ -27,8 +27,10 @@ import android.webkit.WebResourceRequest;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
 import android.widget.EditText;
+import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.ProgressBar;
+import android.widget.RelativeLayout;
 import android.widget.Toast;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
@@ -49,6 +51,8 @@ public class Webview extends AppCompatActivity {
         setContentView(R.layout.activity_webview);
 
         final WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
+        final FrameLayout fullScreenVideoFrameLayout = (FrameLayout) findViewById(R.id.fullScreenVideoFrameLayout);
+        final RelativeLayout rootRelativeLayout = (RelativeLayout) findViewById(R.id.rootRelativeLayout);
         final Activity mainWebViewActivity = this;
 
         final ActionBar actionBar = getSupportActionBar();
@@ -140,6 +144,47 @@ public class Webview extends AppCompatActivity {
                     favoriteIcon.setImageBitmap(Bitmap.createScaledBitmap(icon, 64, 64, true));
                 }
             }
+
+            // Enter full screen video
+            @Override
+            public void onShowCustomView(View view, CustomViewCallback callback) {
+                getSupportActionBar().hide();
+
+                fullScreenVideoFrameLayout.addView(view);
+                fullScreenVideoFrameLayout.setVisibility(View.VISIBLE);
+
+                mainWebView.setVisibility(View.GONE);
+
+                /* SYSTEM_UI_FLAG_HIDE_NAVIGATION hides the navigation bars on the bottom or right of the screen.
+                ** SYSTEM_UI_FLAG_FULLSCREEN hides the status bar across the top of the screen.
+                ** SYSTEM_UI_FLAG_IMMERSIVE_STICKY makes the navigation and status bars ghosted overlays and automatically rehides them.
+                */
+
+                // Set the one flag supported by API >= 14.
+                if (Build.VERSION.SDK_INT >= 14) {
+                    view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
+                }
+
+                // Set the two flags that are supported by API >= 16.
+                if (Build.VERSION.SDK_INT >= 16) {
+                    view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN);
+                }
+
+                // Set all three flags that are supported by API >= 19.
+                if (Build.VERSION.SDK_INT >= 19) {
+                    view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
+                }
+            }
+
+            // Exit full screen video
+            public void onHideCustomView() {
+                getSupportActionBar().show();
+
+                mainWebView.setVisibility(View.VISIBLE);
+
+                fullScreenVideoFrameLayout.removeAllViews();
+                fullScreenVideoFrameLayout.setVisibility(View.GONE);
+            }
         });
 
         mainWebView.setDownloadListener(new DownloadListener() {
index d565fc0bd4418c09ac7acfe382288317ab1ba0dc..e00cdc12f08dd012f27b651b2411264322befd35 100644 (file)
@@ -1,5 +1,5 @@
 <RelativeLayout
-    android:id="@+id/relativeLayout"
+    android:id="@+id/rootRelativeLayout"
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
             android:focusable="true"
             android:focusableInTouchMode="true" />
 
+        <!-- fullScreenVideoFrameLayout is used to display full screen videos.  It is initially android:visibility="gone" to hide it from view. -->
+        <FrameLayout
+            android:id="@+id/fullScreenVideoFrameLayout"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:visibility="gone"
+            android:background="#000000" />
+
 </RelativeLayout>