+ // Make sure that actionBar is not null.
+ if (actionBar != null) {
+ ProgressBar progressBar = (ProgressBar) actionBar.getCustomView().findViewById(R.id.progressBar);
+ progressBar.setProgress(progress);
+ if (progress < 100) {
+ progressBar.setVisibility(View.VISIBLE);
+ } else {
+ progressBar.setVisibility(View.GONE);
+ }
+ }
+ }
+
+ // Set the favorite icon when it changes.
+ @Override
+ public void onReceivedIcon(WebView view, Bitmap icon) {
+ // Save a copy of the favorite icon for use if a shortcut is added to the home screen.
+ favoriteIcon = icon;
+
+ // Place the favorite icon in the actionBar if it is not null.
+ if (actionBar != null) {
+ ImageView imageViewFavoriteIcon = (ImageView) actionBar.getCustomView().findViewById(R.id.favoriteIcon);
+ imageViewFavoriteIcon.setImageBitmap(Bitmap.createScaledBitmap(icon, 64, 64, true));
+ }
+ }
+
+ // Enter full screen video
+ @Override
+ public void onShowCustomView(View view, CustomViewCallback callback) {
+ if (getSupportActionBar() != null) {
+ 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() {
+ if (getSupportActionBar() != null) {
+ getSupportActionBar().show();
+ }
+
+ mainWebView.setVisibility(View.VISIBLE);
+
+ fullScreenVideoFrameLayout.removeAllViews();
+ fullScreenVideoFrameLayout.setVisibility(View.GONE);
+ }
+ });
+
+ // Allow the downloading of files.
+ mainWebView.setDownloadListener(new DownloadListener() {
+ // Launch the Android download manager when a link leads to a download.
+ @Override
+ public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
+ DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
+ DownloadManager.Request requestUri = new DownloadManager.Request(Uri.parse(url));
+
+ // Add the URL as the description for the download.
+ requestUri.setDescription(url);
+
+ // Show the download notification after the download is completed if the API is 11 or greater.
+ if (Build.VERSION.SDK_INT >= 11) {
+ requestUri.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);