]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/Webview.java
Enable full screen video.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / Webview.java
index 116360d0e27448473af6a83540f79c6bee5ee562..5f1e87239a5a009f22d67723638928c8f7aed975 100644 (file)
@@ -1,6 +1,5 @@
 package com.stoutner.privacybrowser;
 
-import android.Manifest;
 import android.annotation.SuppressLint;
 import android.annotation.TargetApi;
 import android.app.Activity;
@@ -9,14 +8,10 @@ import android.content.ClipData;
 import android.content.ClipboardManager;
 import android.content.Context;
 import android.content.Intent;
-import android.content.pm.PackageManager;
 import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.Environment;
-import android.support.v4.app.ActivityCompat;
-import android.support.v4.content.ContextCompat;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.util.Patterns;
@@ -32,11 +27,11 @@ 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.File;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -56,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();
@@ -147,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() {