- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.preferences);
-
- // 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 blockAdsPreference = findPreference("block_ads");
- final Preference incognitoModePreference = findPreference("incognito_mode");
- final Preference doNotTrackPreference = findPreference("do_not_track");
- 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 displayWebpageImagesPreference = findPreference("display_webpage_images");
-
- // Set dependencies.
- domStoragePreference.setDependency("javascript_enabled");
- torHomepagePreference.setDependency("proxy_through_orbot");
- torSearchPreference.setDependency("proxy_through_orbot");
- hideSystemBarsPreference.setDependency("full_screen_browsing_mode");
+ 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 the current theme status.
+ currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
+
+ // // Get a handle for the shared preferences.
+ SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
+
+ // 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("user_agent");
+ customUserAgentPreference = findPreference("custom_user_agent");
+ 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");
+ googleAnalyticsPreference = findPreference("google_analytics");
+ facebookClickIdsPreference = findPreference("facebook_click_ids");
+ twitterAmpRedirectsPreference = findPreference("twitter_amp_redirects");
+ searchPreference = findPreference("search");
+ searchCustomURLPreference = findPreference("search_custom_url");
+ proxyPreference = findPreference("proxy");
+ proxyCustomUrlPreference = findPreference("proxy_custom_url");
+ 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("font_size");
+ openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
+ swipeToRefreshPreference = findPreference("swipe_to_refresh");
+ downloadWithExternalAppPreference = findPreference(getString(R.string.download_with_external_app_key));
+ scrollAppBarPreference = findPreference("scroll_app_bar");
+ displayAdditionalAppBarIconsPreference = findPreference(getString(R.string.display_additional_app_bar_icons_key));
+ appThemePreference = findPreference("app_theme");
+ webViewThemePreference = findPreference("webview_theme");
+ wideViewportPreference = findPreference("wide_viewport");
+ displayWebpageImagesPreference = findPreference("display_webpage_images");
+
+ // 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 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 googleAnalyticsPreference != null;
+ assert facebookClickIdsPreference != null;
+ assert twitterAmpRedirectsPreference != 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 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");