+
+ // Update the privacy icons.
+ MainWebViewActivity.updatePrivacyIcons(MainWebViewActivity.privacyBrowserActivity);
+ break;
+
+ case "save_form_data_enabled":
+ // Set `saveFormDataEnabled` to the new state. The default is `false`.
+ MainWebViewActivity.saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false);
+
+ // Update the checkbox in the options menu.
+ MenuItem saveFormDataMenuItem = MainWebViewActivity.mainMenu.findItem(R.id.toggleSaveFormData);
+ saveFormDataMenuItem.setChecked(MainWebViewActivity.saveFormDataEnabled);
+
+ // Update `mainWebView`.
+ MainWebViewActivity.mainWebView.getSettings().setSaveFormData(MainWebViewActivity.saveFormDataEnabled);
+
+ // Update the privacy icons.
+ MainWebViewActivity.updatePrivacyIcons(MainWebViewActivity.privacyBrowserActivity);
+ break;
+
+ case "user_agent":
+ String userAgentString = sharedPreferences.getString("user_agent", "Default user agent");
+
+ switch (userAgentString) {
+ case "Default user agent":
+ // Set the default user agent on `mainWebView`, display the user agent as the summary text for `userAgentPreference`, and disable `customUserAgent`.
+ // Once API >= 17 we can use getDefaultUserAgent(). For now, setUserAgentString("") sets the WebView's default user agent.
+ MainWebViewActivity.mainWebView.getSettings().setUserAgentString("");
+ userAgentPreference.setSummary(MainWebViewActivity.mainWebView.getSettings().getUserAgentString());
+ customUserAgent.setEnabled(false);
+ break;
+
+ case "Custom user agent":
+ // Set the custom user agent on mainWebView, display "Custom user agent" as the summary text for userAgentPreference, and enable customUserAgent.
+ MainWebViewActivity.mainWebView.getSettings().setUserAgentString(sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0"));
+ userAgentPreference.setSummary(R.string.custom_user_agent);
+ customUserAgent.setEnabled(true);
+ break;
+
+ default:
+ // Set the user agent on mainWebView, display the user agent as the summary text for userAgentPreference, and disable customUserAgent.
+ MainWebViewActivity.mainWebView.getSettings().setUserAgentString(sharedPreferences.getString("user_agent", "Default user agent"));
+ userAgentPreference.setSummary(MainWebViewActivity.mainWebView.getSettings().getUserAgentString());
+ customUserAgent.setEnabled(false);
+ break;
+ }
+ break;
+
+ case "custom_user_agent":
+ // Set the new custom user agent as the summary text for "custom_user_agent". The default is "PrivacyBrowser/1.0".
+ customUserAgent.setSummary(sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0"));
+
+ // Update mainWebView's user agent. The default is "PrivacyBrowser/1.0".
+ MainWebViewActivity.mainWebView.getSettings().setUserAgentString(sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0"));
+ break;
+
+ case "javascript_disabled_search":
+ String newJavaScriptDisabledSearchString = sharedPreferences.getString("javascript_disabled_search", "https://duckduckgo.com/html/?q=");
+ if (newJavaScriptDisabledSearchString.equals("Custom URL")) {
+ // Set the summary text to R.string.custom_url, which will be translated.
+ javaScriptDisabledSearchPreference.setSummary(R.string.custom_url);
+
+ // Update the javaScriptDisabledSearchURL variable. The default is "".
+ MainWebViewActivity.javaScriptDisabledSearchURL = sharedPreferences.getString("javascript_disabled_search_custom_url", "");
+ } else { // javascript_disabled_search is not set to Custom.
+ // Set the new search URL as the summary text for the JavaScript-disabled search preference. The default is "https://duckduckgo.com/html/?q=".
+ javaScriptDisabledSearchPreference.setSummary(newJavaScriptDisabledSearchString);
+
+ // Update the javaScriptDisabledSearchURL variable. The default is "https://duckduckgo.com/html/?q=".
+ MainWebViewActivity.javaScriptDisabledSearchURL = newJavaScriptDisabledSearchString;
+ }
+
+ // Enable or disable javaScriptDisabledSearchCustomURLPreference.
+ javaScriptDisabledSearchCustomURLPreference.setEnabled(newJavaScriptDisabledSearchString.equals("Custom URL"));
+ break;
+
+ case "javascript_disabled_search_custom_url":
+ // Set the new custom search URL as the summary text for "javascript_disabled_search_custom_url". The default is "".
+ javaScriptDisabledSearchCustomURLPreference.setSummary(sharedPreferences.getString("javascript_disabled_search_custom_url", ""));
+
+ // Update javaScriptDisabledSearchCustomURL. The default is "".
+ MainWebViewActivity.javaScriptDisabledSearchURL = sharedPreferences.getString("javascript_disabled_search_custom_url", "");
+ break;
+
+ case "javascript_enabled_search":
+ String newJavaScriptEnabledSearchString = sharedPreferences.getString("javascript_enabled_search", "https://duckduckgo.com/?q=");
+ if (newJavaScriptEnabledSearchString.equals("Custom URL")) {
+ // Set the summary text to R.string.custom_url, which will be translated.
+ javaScriptEnabledSearchPreference.setSummary(R.string.custom_url);
+
+ // Update the javaScriptEnabledSearchURL variable. The default is "".
+ MainWebViewActivity.javaScriptEnabledSearchURL = sharedPreferences.getString("javascript_enabled_search_custom_url", "");
+ } else { // javascript_enabled_search is not set to Custom.
+ // Set the new search URL as the summary text for the JavaScript-enabled search preference. The default is "https://duckduckgo.com/?q=".
+ javaScriptEnabledSearchPreference.setSummary(newJavaScriptEnabledSearchString);
+
+ // Update the javaScriptEnabledSearchURL variable. The default is "https://duckduckgo.com/?q=".
+ MainWebViewActivity.javaScriptEnabledSearchURL = newJavaScriptEnabledSearchString;
+ }
+
+ // Enable or disable javaScriptEnabledSearchCustomURLPreference.
+ javaScriptEnabledSearchCustomURLPreference.setEnabled(newJavaScriptEnabledSearchString.equals("Custom URL"));
+ break;
+
+ case "javascript_enabled_search_custom_url":
+ // Set the new custom search URL as the summary text for `javascript_enabled_search_custom_url`. The default is ``.
+ javaScriptEnabledSearchCustomURLPreference.setSummary(sharedPreferences.getString("javascript_enabled_search_custom_url", ""));
+
+ // Update javaScriptEnabledSearchCustomURL. The default is ``.
+ MainWebViewActivity.javaScriptEnabledSearchURL = sharedPreferences.getString("javascript_enabled_search_custom_url", "");
+ break;
+
+ case "do_not_track":
+ // Update `customHeaders`. The default is `true`.
+ if (sharedPreferences.getBoolean("do_not_track", true)) {
+ MainWebViewActivity.customHeaders.put("DNT", "1");
+ } else { // Remove the Do Not Track header.
+ MainWebViewActivity.customHeaders.remove("DNT");