savedPreferences = getPreferenceScreen().getSharedPreferences();
+ // 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");
+ // Get the user agent text from the webview (which changes based on the version of Android and WebView installed) if we are using the default.
+ if (savedPreferences.getString("user_agent", "Default user agent").equals("Default user agent")) {
+ // Once API >= 17 we can use getDefaultUserAgent() instead of getUserAgentString().
+ userAgentPreference.setSummary(MainWebViewActivity.mainWebView.getSettings().getUserAgentString());
+ } else { // Display the user-agent from the preference as the summary text.
+ userAgentPreference.setSummary(savedPreferences.getString("user_agent", "Default user agent"));
+ }
+
+ // 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"));
+
+
// Set the JavaScript-disabled search URL as the summary text for the JavaScript-disabled search preference when the preference screen is loaded.
// The default is "https://duckduckgo.com/html/?q=".
final Preference javaScriptDisabledSearchPreference = findPreference("javascript_disabled_search");
javaScriptEnabledSearchCustomURLPreference.setSummary(savedPreferences.getString("javascript_enabled_search_custom_url", ""));
javaScriptEnabledSearchCustomURLPreference.setEnabled(javaScriptEnabledSearchPreference.getSummary().equals("Custom URL"));
+
// Set the homepage URL as the summary text for the Homepage preference when the preference screen is loaded. The default is "https://www.duckduckgo.com".
final Preference homepagePreference = findPreference("homepage");
homepagePreference.setSummary(savedPreferences.getString("homepage", "https://www.duckduckgo.com"));
toggleJavaScript.setIcon(R.drawable.privacy_mode);
}
}
- return;
+ break;
case "first_party_cookies_enabled":
// Set firstPartyCookiesEnabled to the new state. The default is false.
toggleJavaScript.setIcon(R.drawable.privacy_mode);
}
}
- return;
+ break;
case "third_party_cookies_enabled":
// Set thirdPartyCookiesEnabled to the new state. The default is false.
MainWebViewActivity.cookieManager.setAcceptThirdPartyCookies(MainWebViewActivity.mainWebView, MainWebViewActivity.thirdPartyCookiesEnabled);
MainWebViewActivity.mainWebView.reload();
}
- return;
+ break;
case "dom_storage_enabled":
// Set domStorageEnabled to the new state. The default is false.
toggleJavaScript.setIcon(R.drawable.privacy_mode);
}
}
- return;
+ 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("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", "PrivacyBrowser/1.0"));
+ 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("user_agent", "PrivacyBrowser/1.0"));
+ break;
case "javascript_disabled_search":
// Set the new search URL as the summary text for the JavaScript-disabled search preference. The default is "https://duckduckgo.com/html/?q=".
// Update the javaScriptDisabledSearchURL variable. The default is "https://duckduckgo.com/html/?q=".
MainWebViewActivity.javaScriptDisabledSearchURL = sharedPreferences.getString("javascript_disabled_search", "https://duckduckgo.com/html/?q=");
- return;
+ 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 "".
// Update javaScriptDisabledSearchCustomURL. The default is "".
MainWebViewActivity.javaScriptDisabledSearchCustomURL = sharedPreferences.getString("javascript_disabled_search_custom_url", "");
+ break;
case "javascript_enabled_search":
// Set the new search URL as the summary text for the JavaScript-enabled search preference. The default is "https://duckduckgo.com/?q=".
// Update the javaScriptEnabledSearchURL variable. The default is "https://duckduckgo.com/?q=".
MainWebViewActivity.javaScriptEnabledSearchURL = sharedPreferences.getString("javascript_enabled_search", "https://duckduckgo.com/?q=");
- return;
+ 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 "".
// Update javaScriptEnabledSearchCustomURL. The default is "".
MainWebViewActivity.javaScriptEnabledSearchCustomURL = sharedPreferences.getString("javascript_enabled_search_custom_url", "");
+ break;
case "homepage":
// Set the new homepage URL as the summary text for the Homepage preference. The default is "https://www.duckduckgo.com".
// Update the homepage variable. The default is "https://www.duckduckgo.com".
MainWebViewActivity.homepage = sharedPreferences.getString("homepage", "https://www.duckduckgo.com");
- return;
+ break;
case "swipe_to_refresh_enabled":
// Set swipeToRefreshEnabled to the new state. The default is true.
// Update swipeRefreshLayout to match the new state.
MainWebViewActivity.swipeToRefresh.setEnabled(MainWebViewActivity.swipeToRefreshEnabled);
- return;
+ break;
- // If no match, do nothing.
default:
+ // If no match, do nothing.
+ break;
}
}
};
<string name="dom_storage_preference">Enable DOM storage by default</string>
<string name="dom_storage_preference_summary">Document Object Management storage, also called web storage, is an enhanced form of cookies
that allows websites to store larger and more complex types of information, like pictures, on your device.</string>
+ <string name="user_agent">User agent</string>
+ <string-array name="user_agent_entries">
+ <item>WebView Default</item>
+ <item>Privacy Browser 1.0</item>
+ <item>Firefox 46 on Android 6.0.1</item>
+ <item>Chrome 50 on Android 6.0.1</item>
+ <item>Firefox 46 on Linux</item>
+ <item>Chromium 50 on Linux</item>
+ <item>Konqueror 4.14 on Linux</item>
+ <item>Firefox 46 on Windows 10</item>
+ <item>Chrome 50 on Windows 10</item>
+ <item>Internet Explorer 11 on Windows 10</item>
+ <item>Edge 13 on Windows 10</item>
+ <item>Custom</item>
+ </string-array>
+ <string-array name="user_agent_entry_values">
+ <item>Default user agent</item>
+ <item>PrivacyBrowser/1.0</item>
+ <item>Mozilla/5.0 (Android 6.0.1; Mobile; rv:46.0) Gecko/46.0 Firefox/46.0</item>
+ <item>Mozilla/5.0 (Linux; Android 6.0.1; Nexus 6P Build/MHC19Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.89 Mobile Safari/537.36</item>
+ <item>Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0</item>
+ <item>Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36</item>
+ <item>Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) konqueror/4.14.14 Safari/537.21</item>
+ <item>Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0</item>
+ <item>Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36</item>
+ <item>Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko</item>
+ <item>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586</item>
+ <item>Custom user agent</item>
+ </string-array>
+ <string name="custom_user_agent">Custom user agent</string>
<string name="search">Search</string>
<string name="javascript_disabled_search">JavaScript-disabled search</string>
<string-array name="javascript_disabled_search_entries">