+ // 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));
+
+
+ // We need an inflated `WebView` to get the default user agent.
+ LayoutInflater inflater = getActivity().getLayoutInflater();
+ // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because we don't want to display `bare_webview` on the screen.
+ // `false` does not attach the view to the root.
+ @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
+ final WebView bareWebView = (WebView) bareWebViewLayout.findViewById(R.id.bare_webview);
+
+ // 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).
+ userAgentPreference.setSummary(bareWebView.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"));
+