+
+ // Apply the other settings from `sharedPreferences`.
+ homepage = homepageString;
+ swipeRefreshLayout.setEnabled(swipeToRefreshEnabled);
+
+ // Set the user agent initial status.
+ switch (userAgentString) {
+ case "Default user agent":
+ // Set the user agent to `""`, which uses the default value.
+ mainWebView.getSettings().setUserAgentString("");
+ break;
+
+ case "Custom user agent":
+ // Set the custom user agent.
+ mainWebView.getSettings().setUserAgentString(customUserAgentString);
+ break;
+
+ default:
+ // Use the selected user agent.
+ mainWebView.getSettings().setUserAgentString(userAgentString);
+ break;
+ }
+
+ // Set JavaScript disabled search.
+ if (javaScriptDisabledSearchString.equals("Custom URL")) { // Get the custom URL string.
+ javaScriptDisabledSearchURL = javaScriptDisabledCustomSearchString;
+ } else { // Use the string from the pre-built list.
+ javaScriptDisabledSearchURL = javaScriptDisabledSearchString;
+ }
+
+ // Set JavaScript enabled search.
+ if (javaScriptEnabledSearchString.equals("Custom URL")) { // Get the custom URL string.
+ javaScriptEnabledSearchURL = javaScriptEnabledCustomSearchString;
+ } else { // Use the string from the pre-built list.
+ javaScriptEnabledSearchURL = javaScriptEnabledSearchString;
+ }
+
+ // Set Do Not Track status.
+ if (doNotTrackEnabled) {
+ customHeaders.put("DNT", "1");
+ } else {
+ customHeaders.remove("DNT");
+ }
+
+ // Set Orbot proxy status.
+ if (proxyThroughOrbot) {
+ // Set the proxy. `this` refers to the current activity where an `AlertDialog` might be displayed.
+ OrbotProxyHelper.setProxy(getApplicationContext(), this, "localhost", "8118");
+ } else { // Reset the proxy to default. The host is `""` and the port is `"0"`.
+ OrbotProxyHelper.setProxy(getApplicationContext(), this, "", "0");
+ }
+ }
+
+ private void updatePrivacyIcons(boolean runInvalidateOptionsMenu) {
+ // Get handles for the icons.
+ MenuItem privacyIcon = mainMenu.findItem(R.id.toggleJavaScript);
+ MenuItem firstPartyCookiesIcon = mainMenu.findItem(R.id.toggleFirstPartyCookies);
+ MenuItem domStorageIcon = mainMenu.findItem(R.id.toggleDomStorage);
+ MenuItem formDataIcon = mainMenu.findItem(R.id.toggleSaveFormData);
+
+ // Update `privacyIcon`.
+ if (javaScriptEnabled) { // JavaScript is enabled.
+ privacyIcon.setIcon(R.drawable.javascript_enabled);
+ } else if (firstPartyCookiesEnabled) { // JavaScript is disabled but cookies are enabled.
+ privacyIcon.setIcon(R.drawable.warning);
+ } else { // All the dangerous features are disabled.
+ privacyIcon.setIcon(R.drawable.privacy_mode);
+ }
+
+ // Update `firstPartyCookiesIcon`.
+ if (firstPartyCookiesEnabled) { // First-party cookies are enabled.
+ firstPartyCookiesIcon.setIcon(R.drawable.cookies_enabled);
+ } else { // First-party cookies are disabled.
+ firstPartyCookiesIcon.setIcon(R.drawable.cookies_disabled);
+ }
+
+ // Update `domStorageIcon`.
+ if (javaScriptEnabled && domStorageEnabled) { // Both JavaScript and DOM storage are enabled.
+ domStorageIcon.setIcon(R.drawable.dom_storage_enabled);
+ } else if (javaScriptEnabled) { // JavaScript is enabled but DOM storage is disabled.
+ domStorageIcon.setIcon(R.drawable.dom_storage_disabled);
+ } else { // JavaScript is disabled, so DOM storage is ghosted.
+ domStorageIcon.setIcon(R.drawable.dom_storage_ghosted);
+ }
+
+ // Update `formDataIcon`.
+ if (saveFormDataEnabled) { // Form data is enabled.
+ formDataIcon.setIcon(R.drawable.form_data_enabled);
+ } else { // Form data is disabled.
+ formDataIcon.setIcon(R.drawable.form_data_disabled);
+ }
+
+ // `invalidateOptionsMenu` calls `onPrepareOptionsMenu()` and redraws the icons in the `AppBar`. `this` references the current activity.
+ if (runInvalidateOptionsMenu) {
+ ActivityCompat.invalidateOptionsMenu(this);
+ }