From ed666e35740078d91a7cb786e56c71afeab9c909 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Wed, 9 Dec 2015 16:57:34 -0700 Subject: [PATCH] Enable full screen video. --- .idea/dictionaries/soren.xml | 2 + .../com/stoutner/privacybrowser/Webview.java | 45 +++++++++++++++++++ app/src/main/res/layout/activity_webview.xml | 10 ++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/.idea/dictionaries/soren.xml b/.idea/dictionaries/soren.xml index 5c98ab4c..a29dfbc4 100644 --- a/.idea/dictionaries/soren.xml +++ b/.idea/dictionaries/soren.xml @@ -2,6 +2,8 @@ duckduckgo + rehide + rehides webview diff --git a/app/src/main/java/com/stoutner/privacybrowser/Webview.java b/app/src/main/java/com/stoutner/privacybrowser/Webview.java index 70315bf8..5f1e8723 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/Webview.java +++ b/app/src/main/java/com/stoutner/privacybrowser/Webview.java @@ -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() { diff --git a/app/src/main/res/layout/activity_webview.xml b/app/src/main/res/layout/activity_webview.xml index d565fc0b..e00cdc12 100644 --- a/app/src/main/res/layout/activity_webview.xml +++ b/app/src/main/res/layout/activity_webview.xml @@ -1,5 +1,5 @@ @@ -11,4 +11,12 @@ android:focusable="true" android:focusableInTouchMode="true" /> + + + -- 2.45.2