+ case R.id.user_agent_internet_explorer_on_windows:
+ // Update the user agent.
+ mainWebView.getSettings().setUserAgentString(getResources().getStringArray(R.array.user_agent_data)[10]);
+
+ // Reload the WebView.
+ mainWebView.reload();
+ return true;
+
+ case R.id.user_agent_safari_on_macos:
+ // Update the user agent.
+ mainWebView.getSettings().setUserAgentString(getResources().getStringArray(R.array.user_agent_data)[11]);
+
+ // Reload the WebView.
+ mainWebView.reload();
+ return true;
+
+ case R.id.user_agent_custom:
+ // Update the user agent.
+ mainWebView.getSettings().setUserAgentString(defaultCustomUserAgentString);
+
+ // Reload the WebView.
+ mainWebView.reload();
+ return true;
+
+ case R.id.font_size_twenty_five_percent:
+ mainWebView.getSettings().setTextZoom(25);
+ return true;
+
+ case R.id.font_size_fifty_percent:
+ mainWebView.getSettings().setTextZoom(50);
+ return true;
+
+ case R.id.font_size_seventy_five_percent:
+ mainWebView.getSettings().setTextZoom(75);
+ return true;
+
+ case R.id.font_size_one_hundred_percent:
+ mainWebView.getSettings().setTextZoom(100);
+ return true;
+
+ case R.id.font_size_one_hundred_twenty_five_percent:
+ mainWebView.getSettings().setTextZoom(125);
+ return true;
+
+ case R.id.font_size_one_hundred_fifty_percent:
+ mainWebView.getSettings().setTextZoom(150);
+ return true;
+
+ case R.id.font_size_one_hundred_seventy_five_percent:
+ mainWebView.getSettings().setTextZoom(175);
+ return true;
+
+ case R.id.font_size_two_hundred_percent:
+ mainWebView.getSettings().setTextZoom(200);
+ return true;
+
+ case R.id.swipe_to_refresh:
+ // Toggle swipe to refresh.
+ swipeRefreshLayout.setEnabled(!swipeRefreshLayout.isEnabled());
+ return true;
+
+ case R.id.display_images:
+ if (mainWebView.getSettings().getLoadsImagesAutomatically()) { // Images are currently loaded automatically.
+ mainWebView.getSettings().setLoadsImagesAutomatically(false);
+ mainWebView.reload();
+ } else { // Images are not currently loaded automatically.
+ mainWebView.getSettings().setLoadsImagesAutomatically(true);
+ }
+ return true;
+
+ case R.id.night_mode:
+ // Toggle night mode.
+ nightMode = !nightMode;
+
+ // Enable or disable JavaScript according to night mode, the global preference, and any domain settings.
+ if (nightMode) { // Night mode is enabled. Enable JavaScript.
+ // Update the global variable.
+ javaScriptEnabled = true;
+ } else if (domainSettingsApplied) { // Night mode is disabled and domain settings are applied. Set JavaScript according to the domain settings.
+ // Get the JavaScript preference that was stored the last time domain settings were loaded.
+ javaScriptEnabled = domainSettingsJavaScriptEnabled;
+ } else { // Night mode is disabled and domain settings are not applied. Set JavaScript according to the global preference.
+ // Get a handle for the shared preference.
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+
+ // Get the JavaScript preference.
+ javaScriptEnabled = sharedPreferences.getBoolean("javascript", false);
+ }
+
+ // Apply the JavaScript setting to the WebView.
+ mainWebView.getSettings().setJavaScriptEnabled(javaScriptEnabled);
+
+ // Update the privacy icons.
+ updatePrivacyIcons(false);
+
+ // Reload the website.
+ mainWebView.reload();
+ return true;
+
+ case R.id.print:
+ // Get a `PrintManager` instance.
+ PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
+
+ // Convert `mainWebView` to `printDocumentAdapter`.
+ PrintDocumentAdapter printDocumentAdapter = mainWebView.createPrintDocumentAdapter();
+
+ // Remove the lint error below that `printManager` might be `null`.
+ assert printManager != null;
+
+ // Print the document. The print attributes are `null`.
+ printManager.print(getString(R.string.privacy_browser_web_page), printDocumentAdapter, null);
+ return true;
+
+ case R.id.find_on_page:
+ // Hide the URL app bar.
+ supportAppBar.setVisibility(View.GONE);
+
+ // Show the Find on Page `RelativeLayout`.
+ findOnPageLinearLayout.setVisibility(View.VISIBLE);
+
+ // Display the keyboard. We have to 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();
+
+ // Display the keyboard. `0` sets no input flags.
+ inputMethodManager.showSoftInput(findOnPageEditText, 0);
+ }, 200);
+ return true;
+
+ case R.id.add_to_homescreen:
+ // Show the alert dialog.
+ AppCompatDialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcutDialog();
+ createHomeScreenShortcutDialogFragment.show(getSupportFragmentManager(), getString(R.string.create_shortcut));
+
+ //Everything else will be handled by the alert dialog and the associated listener below.
+ return true;
+
+ case R.id.view_source:
+ // Launch the View Source activity.
+ Intent viewSourceIntent = new Intent(this, ViewSourceActivity.class);
+ startActivity(viewSourceIntent);
+ return true;
+
+ case R.id.share_url:
+ // Setup the share string.
+ String shareString = webViewTitle + " – " + urlTextBox.getText().toString();
+
+ // Create the share intent.
+ Intent shareIntent = new Intent(Intent.ACTION_SEND);
+ shareIntent.putExtra(Intent.EXTRA_TEXT, shareString);
+ shareIntent.setType("text/plain");
+
+ // Make it so.
+ startActivity(Intent.createChooser(shareIntent, getString(R.string.share_url)));
+ return true;
+
+ case R.id.open_with_app:
+ // Create the open with intent with `ACTION_VIEW`.
+ Intent openWithAppIntent = new Intent(Intent.ACTION_VIEW);
+
+ // Set the URI but not the MIME type. This should open all available apps.
+ openWithAppIntent.setData(Uri.parse(formattedUrlString));
+
+ // Flag the intent to open in a new task.
+ openWithAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ // Show the chooser.
+ startActivity(Intent.createChooser(openWithAppIntent, getString(R.string.open_with)));
+ return true;
+
+ case R.id.open_with_browser:
+ // Create the open with intent with `ACTION_VIEW`.
+ Intent openWithBrowserIntent = new Intent(Intent.ACTION_VIEW);
+
+ // Set the URI and the MIME type. `"text/html"` should load browser options.
+ openWithBrowserIntent.setDataAndType(Uri.parse(formattedUrlString), "text/html");
+
+ // Flag the intent to open in a new task.
+ openWithBrowserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ // Show the chooser.
+ startActivity(Intent.createChooser(openWithBrowserIntent, getString(R.string.open_with)));
+ return true;
+
+ case R.id.proxy_through_orbot:
+ // Toggle the proxy through Orbot variable.
+ proxyThroughOrbot = !proxyThroughOrbot;
+
+ // Apply the proxy through Orbot settings.
+ applyProxyThroughOrbot(true);
+ return true;
+
+ case R.id.refresh:
+ if (menuItem.getTitle().equals(getString(R.string.refresh))) { // The refresh button was pushed.
+ // Reload the WebView.
+ mainWebView.reload();
+ } else { // The stop button was pushed.
+ // Stop the loading of the WebView.
+ mainWebView.stopLoading();
+ }
+ return true;
+
+ case R.id.ad_consent:
+ // Display the ad consent dialog.
+ DialogFragment adConsentDialogFragment = new AdConsentDialog();
+ adConsentDialogFragment.show(getFragmentManager(), getString(R.string.ad_consent));
+ return true;
+
+ default:
+ // Don't consume the event.
+ return super.onOptionsItemSelected(menuItem);
+ }
+ }
+
+ // removeAllCookies is deprecated, but it is required for API < 21.
+ @SuppressWarnings("deprecation")
+ @Override
+ public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
+ int menuItemId = menuItem.getItemId();
+
+ switch (menuItemId) {
+ case R.id.home:
+ loadUrl(homepage);
+ break;