+ // Allow the user to access "dom_storage_enabled" if "javascript_enabled" is enabled. The default is false.
+ final Preference domStorageEnabled = findPreference("dom_storage_enabled");
+ domStorageEnabled.setEnabled(savedPreferences.getBoolean("javascript_enabled", false));
+
+ // Allow the user to access "third_party_cookies_enabled" if "first_party_cookies_enabled" is enabled. The default is false.
+ final Preference thirdPartyCookiesEnabled = findPreference("third_party_cookies_enabled");
+ thirdPartyCookiesEnabled.setEnabled(savedPreferences.getBoolean("first_party_cookies_enabled", false));
+
+ // Set the current user-agent as the summary text for the "user_agent" preference when the preference screen is loaded.
+ final Preference userAgentPreference = findPreference("user_agent");
+ switch (savedPreferences.getString("user_agent", "Default user agent")) {
+ case "Default user agent":
+ // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
+ // Once API >= 17 we can use getDefaultUserAgent() instead of getUserAgentString().
+ userAgentPreference.setSummary(MainWebViewActivity.mainWebView.getSettings().getUserAgentString());
+ break;
+
+ case "Custom user agent":
+ // We can't use the string from the array because it is referenced in code and can't be translated.
+ userAgentPreference.setSummary(R.string.custom_user_agent);
+ break;
+
+ default:
+ // Display the user agent from the preference as the summary text.
+ userAgentPreference.setSummary(savedPreferences.getString("user_agent", "Default user agent"));
+ break;
+ }
+
+ // Set the summary text for "custom_user_agent" (the default is "PrivacyBrowser/1.0") and enable it if "user_agent" it set to "Custom user agent".
+ final Preference customUserAgent = findPreference("custom_user_agent");
+ customUserAgent.setSummary(savedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0"));
+ customUserAgent.setEnabled(userAgentPreference.getSummary().equals("Custom user agent"));
+