- // Consume the event.
- return true;
-
- case R.id.font_size:
- // Instantiate the font size dialog.
- DialogFragment fontSizeDialogFragment = FontSizeDialog.displayDialog(currentWebView.getSettings().getTextZoom());
-
- // Show the font size dialog.
- fontSizeDialogFragment.show(getSupportFragmentManager(), getString(R.string.font_size));
-
- // Consume the event.
- return true;
-
- case R.id.swipe_to_refresh:
- // Toggle the stored status of swipe to refresh.
- currentWebView.setSwipeToRefresh(!currentWebView.getSwipeToRefresh());
-
- // Get a handle for the swipe refresh layout.
- SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.swiperefreshlayout);
-
- // Update the swipe refresh layout.
- if (currentWebView.getSwipeToRefresh()) { // Swipe to refresh is enabled.
- // Only enable the swipe refresh layout if the WebView is scrolled to the top. It is updated every time the scroll changes.
- swipeRefreshLayout.setEnabled(currentWebView.getY() == 0);
- } else { // Swipe to refresh is disabled.
- // Disable the swipe refresh layout.
- swipeRefreshLayout.setEnabled(false);
- }
-
- // Consume the event.
- return true;
-
- case R.id.wide_viewport:
- // Toggle the viewport.
- currentWebView.getSettings().setUseWideViewPort(!currentWebView.getSettings().getUseWideViewPort());
-
- // Consume the event.
- return true;
-
- case R.id.display_images:
- if (currentWebView.getSettings().getLoadsImagesAutomatically()) { // Images are currently loaded automatically.
- // Disable loading of images.
- currentWebView.getSettings().setLoadsImagesAutomatically(false);
-
- // Reload the website to remove existing images.
- currentWebView.reload();
- } else { // Images are not currently loaded automatically.
- // Enable loading of images. Missing images will be loaded without the need for a reload.
- currentWebView.getSettings().setLoadsImagesAutomatically(true);
- }
-
- // Consume the event.
- return true;
-
- case R.id.dark_webview:
- // Check to see if dark WebView is supported by this WebView.
- if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
- // Toggle the dark WebView setting.
- if (WebSettingsCompat.getForceDark(currentWebView.getSettings()) == WebSettingsCompat.FORCE_DARK_ON) { // Dark WebView is currently enabled.
- // Turn off dark WebView.
- WebSettingsCompat.setForceDark(currentWebView.getSettings(), WebSettingsCompat.FORCE_DARK_OFF);
- } else { // Dark WebView is currently disabled.
- // turn on dark WebView.
- WebSettingsCompat.setForceDark(currentWebView.getSettings(), WebSettingsCompat.FORCE_DARK_ON);
- }
- }
-
- // Consume the event.
- return true;
-
- case R.id.find_on_page:
- // Get a handle for the views.
- Toolbar toolbar = findViewById(R.id.toolbar);
- LinearLayout findOnPageLinearLayout = findViewById(R.id.find_on_page_linearlayout);
- EditText findOnPageEditText = findViewById(R.id.find_on_page_edittext);
-
- // Set the minimum height of the find on page linear layout to match the toolbar.
- findOnPageLinearLayout.setMinimumHeight(toolbar.getHeight());
-
- // Hide the toolbar.
- toolbar.setVisibility(View.GONE);
-
- // Show the find on page linear layout.
- findOnPageLinearLayout.setVisibility(View.VISIBLE);
-
- // Display the keyboard. The app must wait 200 ms before running the command to work around a bug in Android.
- // http://stackoverflow.com/questions/5520085/android-show-softkeyboard-with-showsoftinput-is-not-working
- findOnPageEditText.postDelayed(() -> {
- // Set the focus on `findOnPageEditText`.
- findOnPageEditText.requestFocus();
-
- // Get a handle for the input method manager.
- InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
-
- // Remove the lint warning below that the input method manager might be null.
- assert inputMethodManager != null;
-
- // Display the keyboard. `0` sets no input flags.
- inputMethodManager.showSoftInput(findOnPageEditText, 0);
- }, 200);
-
- // Consume the event.
- return true;
-
- case R.id.print:
- // Get a print manager instance.
- PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
-
- // Remove the lint error below that print manager might be null.
- assert printManager != null;
-
- // Create a print document adapter from the current WebView.
- PrintDocumentAdapter printDocumentAdapter = currentWebView.createPrintDocumentAdapter();
-
- // Print the document.
- printManager.print(getString(R.string.privacy_browser_web_page), printDocumentAdapter, null);
-
- // Consume the event.
- return true;
-
- case R.id.save_url:
- // Prepare the save dialog. The dialog will be displayed once the file size and the content disposition have been acquired.
- new PrepareSaveDialog(this, this, getSupportFragmentManager(), StoragePermissionDialog.SAVE_URL, currentWebView.getSettings().getUserAgentString(),
- currentWebView.getAcceptFirstPartyCookies()).execute(currentWebView.getCurrentUrl());
-
- // Consume the event.
- return true;
-
- case R.id.save_archive:
- // Instantiate the save dialog.
- DialogFragment saveArchiveFragment = SaveWebpageDialog.saveWebpage(StoragePermissionDialog.SAVE_ARCHIVE, null, null, getString(R.string.webpage_mht), null,
- false);
-
- // Show the save dialog. It must be named `save_dialog` so that the file picker can update the file name.
- saveArchiveFragment.show(getSupportFragmentManager(), getString(R.string.save_dialog));
-
- // Consume the event.
- return true;
-
- case R.id.save_image:
- // Instantiate the save dialog.
- DialogFragment saveImageFragment = SaveWebpageDialog.saveWebpage(StoragePermissionDialog.SAVE_IMAGE, null, null, getString(R.string.webpage_png), null,
- false);
-
- // Show the save dialog. It must be named `save_dialog` so that the file picker can update the file name.
- saveImageFragment.show(getSupportFragmentManager(), getString(R.string.save_dialog));
-
- // Consume the event.
- return true;
-
- case R.id.add_to_homescreen:
- // Instantiate the create home screen shortcut dialog.
- DialogFragment createHomeScreenShortcutDialogFragment = CreateHomeScreenShortcutDialog.createDialog(currentWebView.getTitle(), currentWebView.getUrl(),
- currentWebView.getFavoriteOrDefaultIcon());
-
- // Show the create home screen shortcut dialog.
- createHomeScreenShortcutDialogFragment.show(getSupportFragmentManager(), getString(R.string.create_shortcut));
-
- // Consume the event.
- return true;
-
- case R.id.view_source:
- // Create an intent to launch the view source activity.
- Intent viewSourceIntent = new Intent(this, ViewSourceActivity.class);
-
- // Add the variables to the intent.
- viewSourceIntent.putExtra("user_agent", currentWebView.getSettings().getUserAgentString());
- viewSourceIntent.putExtra("current_url", currentWebView.getUrl());
-
- // Make it so.
- startActivity(viewSourceIntent);
-
- // Consume the event.
- return true;
-
- case R.id.share_url:
- // Setup the share string.
- String shareString = currentWebView.getTitle() + " – " + currentWebView.getUrl();
-
- // Create the share intent.
- Intent shareIntent = new Intent(Intent.ACTION_SEND);
-
- // Add the share string to the intent.
- shareIntent.putExtra(Intent.EXTRA_TEXT, shareString);