- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.preferences);
-
- // Get a handle for the context.
- Context context = getActivity().getApplicationContext();
-
- // Initialize savedPreferences.
- savedPreferences = getPreferenceScreen().getSharedPreferences();
-
- // Get handles for the preferences we need to modify.
- final Preference javaScriptPreference = findPreference("javascript_enabled");
- final Preference firstPartyCookiesPreference = findPreference("first_party_cookies_enabled");
- final Preference thirdPartyCookiesPreference = findPreference("third_party_cookies_enabled");
- final Preference domStoragePreference = findPreference("dom_storage_enabled");
- final Preference saveFormDataPreference = findPreference("save_form_data_enabled");
- final Preference userAgentPreference = findPreference("user_agent");
- final Preference customUserAgentPreference = findPreference("custom_user_agent");
- final Preference incognitoModePreference = findPreference("incognito_mode");
- final Preference doNotTrackPreference = findPreference("do_not_track");
- final Preference easyListPreference = findPreference("easylist");
- final Preference easyPrivacyPreference = findPreference("easyprivacy");
- final Preference fanboyAnnoyanceListPreference = findPreference("fanboy_annoyance_list");
- final Preference fanboySocialBlockingListPreference = findPreference("fanboy_social_blocking_list");
- final Preference proxyThroughOrbotPreference = findPreference("proxy_through_orbot");
- final Preference torHomepagePreference = findPreference("tor_homepage");
- final Preference torSearchPreference = findPreference("tor_search");
- final Preference torSearchCustomURLPreference = findPreference("tor_search_custom_url");
- final Preference searchPreference = findPreference("search");
- final Preference searchCustomURLPreference = findPreference("search_custom_url");
- final Preference fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
- final Preference hideSystemBarsPreference = findPreference("hide_system_bars");
- final Preference translucentNavigationBarPreference = findPreference("translucent_navigation_bar");
- final Preference clearEverythingPreference = findPreference("clear_everything");
- final Preference clearCookiesPreference = findPreference("clear_cookies");
- final Preference clearDomStoragePreference = findPreference("clear_dom_storage");
- final Preference clearFormDataPreference = findPreference("clear_form_data");
- final Preference clearCachePreference = findPreference("clear_cache");
- final Preference homepagePreference = findPreference("homepage");
- final Preference defaultFontSizePreference = findPreference("default_font_size");
- final Preference swipeToRefreshPreference = findPreference("swipe_to_refresh");
- final Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons");
- final Preference darkThemePreference = findPreference("dark_theme");
- final Preference nightModePreference = findPreference("night_mode");
- final Preference displayWebpageImagesPreference = findPreference("display_webpage_images");
-
- // Set dependencies.
- torHomepagePreference.setDependency("proxy_through_orbot");
- torSearchPreference.setDependency("proxy_through_orbot");
- hideSystemBarsPreference.setDependency("full_screen_browsing_mode");
-
- // Get Strings from the preferences.
- String torSearchString = savedPreferences.getString("tor_search", "https://3g2upl4pq6kufc4m.onion/html/?q=");
- String searchString = savedPreferences.getString("search", "https://duckduckgo.com/html/?q=");
-
- // Get booleans from the preferences.
- final boolean javaScriptEnabled = savedPreferences.getBoolean("javascript_enabled", false);
- boolean firstPartyCookiesEnabled = savedPreferences.getBoolean("first_party_cookies_enabled", false);
- boolean thirdPartyCookiesEnabled = savedPreferences.getBoolean("third_party_cookies_enabled", false);
- boolean fanboyAnnoyanceListEnabled = savedPreferences.getBoolean("fanboy_annoyance_list", true);
- boolean fanboySocialBlockingEnabled = savedPreferences.getBoolean("fanboy_social_blocking_list", true);
- boolean proxyThroughOrbot = savedPreferences.getBoolean("proxy_through_orbot", false);
- boolean fullScreenBrowsingMode = savedPreferences.getBoolean("full_screen_browsing_mode", false);
- boolean hideSystemBars = savedPreferences.getBoolean("hide_system_bars", false);
- boolean clearEverything = savedPreferences.getBoolean("clear_everything", true);
- final boolean nightMode = savedPreferences.getBoolean("night_mode", false);
-
- // Only enable the third-party preference if first-party cookies are enabled and API >= 21.
- thirdPartyCookiesPreference.setEnabled(firstPartyCookiesEnabled && (Build.VERSION.SDK_INT >= 21));
-
- // Only enable the DOM storage preference if either JavaScript or Night Mode is enabled.
- domStoragePreference.setEnabled(javaScriptEnabled || nightMode);
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ // Load the preferences from the XML file.
+ setPreferencesFromResource(R.xml.preferences, rootKey);
+
+ // Get a handle for the activity.
+ Activity activity = getActivity();
+
+ // Remove the lint warning below that `getApplicationContext()` might produce a null pointer exception.
+ assert activity != null;
+
+ // Get a handle for the resources.
+ Resources resources = getResources();
+
+ // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
+
+ // Remove the incorrect warning below that the shared preferences might be null.
+ assert sharedPreferences != null;
+
+ // Get handles for the preferences.
+ javaScriptPreference = findPreference("javascript");
+ cookiesPreference = findPreference(getString(R.string.cookies_key));
+ domStoragePreference = findPreference("dom_storage");
+ formDataPreference = findPreference("save_form_data"); // The form data preference can be removed once the minimum API >= 26.
+ userAgentPreference = findPreference(getString(R.string.user_agent_key));
+ customUserAgentPreference = findPreference("custom_user_agent");
+ xRequestedWithHeaderPreference = findPreference(getString(R.string.x_requested_with_header_key));
+ incognitoModePreference = findPreference("incognito_mode");
+ allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key));
+ easyListPreference = findPreference("easylist");
+ easyPrivacyPreference = findPreference("easyprivacy");
+ fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
+ fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
+ ultraListPreference = findPreference("ultralist");
+ ultraPrivacyPreference = findPreference("ultraprivacy");
+ blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
+ trackingQueriesPreference = findPreference(getString(R.string.tracking_queries_key));
+ ampRedirectsPreference = findPreference(getString(R.string.amp_redirects_key));
+ searchPreference = findPreference("search");
+ searchCustomURLPreference = findPreference("search_custom_url");
+ proxyPreference = findPreference("proxy");
+ proxyCustomUrlPreference = findPreference(getString(R.string.proxy_custom_url_key));
+ fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
+ hideAppBarPreference = findPreference("hide_app_bar");
+ clearEverythingPreference = findPreference("clear_everything");
+ clearCookiesPreference = findPreference("clear_cookies");
+ clearDomStoragePreference = findPreference("clear_dom_storage");
+ clearFormDataPreference = findPreference("clear_form_data"); // The clear form data preference can be removed once the minimum API >= 26.
+ clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key));
+ clearCachePreference = findPreference("clear_cache");
+ homepagePreference = findPreference("homepage");
+ fontSizePreference = findPreference(getString(R.string.font_size_key));
+ openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
+ swipeToRefreshPreference = findPreference(getString(R.string.swipe_to_refresh_key));
+ downloadWithExternalAppPreference = findPreference(getString(R.string.download_with_external_app_key));
+ scrollAppBarPreference = findPreference(getString(R.string.scroll_app_bar_key));
+ bottomAppBarPreference = findPreference(getString(R.string.bottom_app_bar_key));
+ displayAdditionalAppBarIconsPreference = findPreference(getString(R.string.display_additional_app_bar_icons_key));
+ appThemePreference = findPreference("app_theme");
+ webViewThemePreference = findPreference(getString(R.string.webview_theme_key));
+ wideViewportPreference = findPreference(getString(R.string.wide_viewport_key));
+ displayWebpageImagesPreference = findPreference(getString(R.string.display_webpage_images_key));
+
+ // Remove the lint warnings below that the preferences might be null.
+ assert javaScriptPreference != null;
+ assert cookiesPreference != null;
+ assert domStoragePreference != null;
+ assert formDataPreference != null;
+ assert userAgentPreference != null;
+ assert customUserAgentPreference != null;
+ assert xRequestedWithHeaderPreference != null;
+ assert incognitoModePreference != null;
+ assert allowScreenshotsPreference != null;
+ assert easyListPreference != null;
+ assert easyPrivacyPreference != null;
+ assert fanboyAnnoyanceListPreference != null;
+ assert fanboySocialBlockingListPreference != null;
+ assert ultraListPreference != null;
+ assert ultraPrivacyPreference != null;
+ assert blockAllThirdPartyRequestsPreference != null;
+ assert trackingQueriesPreference != null;
+ assert ampRedirectsPreference != null;
+ assert searchPreference != null;
+ assert searchCustomURLPreference != null;
+ assert proxyPreference != null;
+ assert proxyCustomUrlPreference != null;
+ assert fullScreenBrowsingModePreference != null;
+ assert hideAppBarPreference != null;
+ assert clearEverythingPreference != null;
+ assert clearCookiesPreference != null;
+ assert clearDomStoragePreference != null;
+ assert clearFormDataPreference != null;
+ assert clearLogcatPreference != null;
+ assert clearCachePreference != null;
+ assert homepagePreference != null;
+ assert fontSizePreference != null;
+ assert openIntentsInNewTabPreference != null;
+ assert swipeToRefreshPreference != null;
+ assert downloadWithExternalAppPreference != null;
+ assert scrollAppBarPreference != null;
+ assert bottomAppBarPreference != null;
+ assert displayAdditionalAppBarIconsPreference != null;
+ assert appThemePreference != null;
+ assert webViewThemePreference != null;
+ assert wideViewportPreference != null;
+ assert displayWebpageImagesPreference != null;
+
+ // Set the preference dependencies.
+ hideAppBarPreference.setDependency("full_screen_browsing_mode");
+ domStoragePreference.setDependency("javascript");
+
+ // Get strings from the preferences.
+ String userAgentName = sharedPreferences.getString(getString(R.string.user_agent_key), getString(R.string.user_agent_default_value));
+ String searchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
+ String proxyString = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value));
+
+ // Get booleans that are used in multiple places from the preferences.
+ boolean javaScriptEnabled = sharedPreferences.getBoolean("javascript", false);
+ boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
+ boolean fanboySocialBlockingEnabled = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
+ boolean fullScreenBrowsingMode = sharedPreferences.getBoolean("full_screen_browsing_mode", false);
+ boolean clearEverything = sharedPreferences.getBoolean("clear_everything", true);
+
+ // Remove the form data preferences if the API is >= 26 as they no longer do anything.
+ if (Build.VERSION.SDK_INT >= 26) {
+ // Get handles for the categories.
+ PreferenceCategory privacyCategory = findPreference("privacy");
+ PreferenceCategory clearAndExitCategory = findPreference("clear_and_exit");
+
+ // Remove the incorrect lint warnings below that the preference categories might be null.
+ assert privacyCategory != null;
+ assert clearAndExitCategory != null;
+
+ // Remove the form data preferences.
+ privacyCategory.removePreference(formDataPreference);
+ clearAndExitCategory.removePreference(clearFormDataPreference);
+ }