Add option to remove Facebook Click IDs from URLs. https://redmine.stoutner.com...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / SettingsFragment.java
index 410a21ed08be6afe22cd1b470e7180b33980f790..51962b6bbb92904a988969ee34bda5029e22312c 100644 (file)
@@ -25,6 +25,7 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Handler;
 import android.preference.Preference;
 import android.preference.PreferenceCategory;
 import android.preference.PreferenceFragment;
@@ -55,44 +56,47 @@ public class SettingsFragment extends PreferenceFragment {
         savedPreferences = getPreferenceScreen().getSharedPreferences();
 
         // Get handles for the preferences.
-        final Preference javaScriptPreference = findPreference("javascript");
-        final Preference firstPartyCookiesPreference = findPreference("first_party_cookies");
-        final Preference thirdPartyCookiesPreference = findPreference("third_party_cookies");
-        final Preference domStoragePreference = findPreference("dom_storage");
-        final Preference saveFormDataPreference = findPreference("save_form_data");  // The form data preference can be removed once the minimum API >= 26.
-        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 allowScreenshotsPreference = findPreference("allow_screenshots");
-        final Preference easyListPreference = findPreference("easylist");
-        final Preference easyPrivacyPreference = findPreference("easyprivacy");
-        final Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
-        final Preference fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
-        final Preference ultraPrivacyPreference = findPreference("ultraprivacy");
-        final Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
-        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 hideAppBarPreference = findPreference("hide_app_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");  // The clear form data preference can be removed once the minimum API >= 26.
-        final Preference clearCachePreference = findPreference("clear_cache");
-        final Preference homepagePreference = findPreference("homepage");
-        final Preference fontSizePreference = findPreference("font_size");
-        final Preference swipeToRefreshPreference = findPreference("swipe_to_refresh");
-        final Preference scrollAppBarPreference = findPreference("scroll_app_bar");
-        final Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons");
-        final Preference downloadWithExternalAppPreference = findPreference("download_with_external_app");
-        final Preference darkThemePreference = findPreference("dark_theme");
-        final Preference nightModePreference = findPreference("night_mode");
-        final Preference displayWebpageImagesPreference = findPreference("display_webpage_images");
+        Preference javaScriptPreference = findPreference("javascript");
+        Preference firstPartyCookiesPreference = findPreference("first_party_cookies");
+        Preference thirdPartyCookiesPreference = findPreference("third_party_cookies");
+        Preference domStoragePreference = findPreference("dom_storage");
+        Preference formDataPreference = findPreference("save_form_data");  // The form data preference can be removed once the minimum API >= 26.
+        Preference userAgentPreference = findPreference("user_agent");
+        Preference customUserAgentPreference = findPreference("custom_user_agent");
+        Preference incognitoModePreference = findPreference("incognito_mode");
+        Preference doNotTrackPreference = findPreference("do_not_track");
+        Preference allowScreenshotsPreference = findPreference("allow_screenshots");
+        Preference easyListPreference = findPreference("easylist");
+        Preference easyPrivacyPreference = findPreference("easyprivacy");
+        Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
+        Preference fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
+        Preference ultraPrivacyPreference = findPreference("ultraprivacy");
+        Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
+        Preference googleAnalyticsPreference = findPreference("google_analytics");
+        Preference facebookClickIdsPreference = findPreference("facebook_click_ids");
+        Preference proxyThroughOrbotPreference = findPreference("proxy_through_orbot");
+        Preference torHomepagePreference = findPreference("tor_homepage");
+        Preference torSearchPreference = findPreference("tor_search");
+        Preference torSearchCustomURLPreference = findPreference("tor_search_custom_url");
+        Preference searchPreference = findPreference("search");
+        Preference searchCustomURLPreference = findPreference("search_custom_url");
+        Preference fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
+        Preference hideAppBarPreference = findPreference("hide_app_bar");
+        Preference clearEverythingPreference = findPreference("clear_everything");
+        Preference clearCookiesPreference = findPreference("clear_cookies");
+        Preference clearDomStoragePreference = findPreference("clear_dom_storage");
+        Preference clearFormDataPreference = findPreference("clear_form_data");  // The clear form data preference can be removed once the minimum API >= 26.
+        Preference clearCachePreference = findPreference("clear_cache");
+        Preference homepagePreference = findPreference("homepage");
+        Preference fontSizePreference = findPreference("font_size");
+        Preference openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
+        Preference swipeToRefreshPreference = findPreference("swipe_to_refresh");
+        Preference scrollAppBarPreference = findPreference("scroll_app_bar");
+        Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons");
+        Preference downloadWithExternalAppPreference = findPreference("download_with_external_app");
+        Preference darkThemePreference = findPreference("dark_theme");
+        Preference nightModePreference = findPreference("night_mode");
+        Preference displayWebpageImagesPreference = findPreference("display_webpage_images");
 
         // Set dependencies.
         torHomepagePreference.setDependency("proxy_through_orbot");
@@ -104,7 +108,7 @@ public class SettingsFragment extends PreferenceFragment {
         String searchString = savedPreferences.getString("search", getString(R.string.search_default_value));
 
         // Get booleans that are used in multiple places from the preferences.
-        final boolean javaScriptEnabled = savedPreferences.getBoolean("javascript", false);
+        boolean javaScriptEnabled = savedPreferences.getBoolean("javascript", false);
         boolean firstPartyCookiesEnabled = savedPreferences.getBoolean("first_party_cookies", false);
         boolean thirdPartyCookiesEnabled = savedPreferences.getBoolean("third_party_cookies", false);
         boolean fanboyAnnoyanceListEnabled = savedPreferences.getBoolean("fanboys_annoyance_list", true);
@@ -112,7 +116,8 @@ public class SettingsFragment extends PreferenceFragment {
         boolean proxyThroughOrbot = savedPreferences.getBoolean("proxy_through_orbot", false);
         boolean fullScreenBrowsingMode = savedPreferences.getBoolean("full_screen_browsing_mode", false);
         boolean clearEverything = savedPreferences.getBoolean("clear_everything", true);
-        final boolean nightMode = savedPreferences.getBoolean("night_mode", false);
+        boolean darkTheme = savedPreferences.getBoolean("dark_theme", false);
+        boolean nightMode = savedPreferences.getBoolean("night_mode", false);
 
         // Only enable the third-party cookies preference if first-party cookies are enabled and API >= 21.
         thirdPartyCookiesPreference.setEnabled(firstPartyCookiesEnabled && (Build.VERSION.SDK_INT >= 21));
@@ -127,7 +132,7 @@ public class SettingsFragment extends PreferenceFragment {
             PreferenceCategory clearAndExitCategory = (PreferenceCategory) findPreference("clear_and_exit");
 
             // Remove the form data preferences.
-            privacyCategory.removePreference(saveFormDataPreference);
+            privacyCategory.removePreference(formDataPreference);
             clearAndExitCategory.removePreference(clearFormDataPreference);
         }
 
@@ -138,7 +143,7 @@ public class SettingsFragment extends PreferenceFragment {
         LayoutInflater inflater = getActivity().getLayoutInflater();
         // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because the `bare_webview` will not be displayed.
         @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
-        final WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
+        WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
 
         // Get the user agent arrays.
         ArrayAdapter<CharSequence> userAgentNamesArray = ArrayAdapter.createFromResource(context, R.array.user_agent_names, R.layout.spinner_item);
@@ -237,7 +242,7 @@ public class SettingsFragment extends PreferenceFragment {
         if (firstPartyCookiesEnabled) {
             firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
             } else {
                 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
@@ -249,14 +254,14 @@ public class SettingsFragment extends PreferenceFragment {
             if (thirdPartyCookiesEnabled) {
                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
             } else {
-                if (MainWebViewActivity.darkTheme) {
+                if (darkTheme) {
                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
                 } else {
                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
                 }
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_dark);
             } else {
                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_light);
@@ -268,14 +273,14 @@ public class SettingsFragment extends PreferenceFragment {
             if (savedPreferences.getBoolean("dom_storage", false)) {  // DOM storage is enabled.
                 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
             } else {  // DOM storage is disabled.
-                if (MainWebViewActivity.darkTheme) {
+                if (darkTheme) {
                     domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
                 } else {
                     domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
                 }
             }
         } else {  // The preference is disabled.  The icon should be ghosted.
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_dark);
             } else {
                 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_light);
@@ -285,25 +290,25 @@ public class SettingsFragment extends PreferenceFragment {
         // Set the save form data icon if API < 26.  Save form data has no effect on API >= 26.
         if (Build.VERSION.SDK_INT < 26) {
             if (savedPreferences.getBoolean("save_form_data", false)) {
-                saveFormDataPreference.setIcon(R.drawable.form_data_enabled);
+                formDataPreference.setIcon(R.drawable.form_data_enabled);
             } else {
-                if (MainWebViewActivity.darkTheme) {
-                    saveFormDataPreference.setIcon(R.drawable.form_data_disabled_dark);
+                if (darkTheme) {
+                    formDataPreference.setIcon(R.drawable.form_data_disabled_dark);
                 } else {
-                    saveFormDataPreference.setIcon(R.drawable.form_data_disabled_light);
+                    formDataPreference.setIcon(R.drawable.form_data_disabled_light);
                 }
             }
         }
 
         // Set the custom user agent icon.
         if (customUserAgentPreference.isEnabled()) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_dark);
             } else {
                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_dark);
             } else {
                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_light);
@@ -312,13 +317,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the incognito mode icon.
         if (savedPreferences.getBoolean("incognito_mode", false)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_dark);
             } else {
                 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_dark);
             } else {
                 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_light);
@@ -327,13 +332,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the Do Not Track icon.
         if (savedPreferences.getBoolean("do_not_track", false)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_dark);
             } else {
                 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_dark);
             } else {
                 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_light);
@@ -342,13 +347,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the allow screenshots icon.
         if (savedPreferences.getBoolean("allow_screenshots", false)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_dark);
             } else {
                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_dark);
             } else {
                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_light);
@@ -357,13 +362,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the EasyList icon.
         if (savedPreferences.getBoolean("easylist", true)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 easyListPreference.setIcon(R.drawable.block_ads_enabled_dark);
             } else {
                 easyListPreference.setIcon(R.drawable.block_ads_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 easyListPreference.setIcon(R.drawable.block_ads_disabled_dark);
             } else {
                 easyListPreference.setIcon(R.drawable.block_ads_disabled_light);
@@ -372,13 +377,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the EasyPrivacy icon.
         if (savedPreferences.getBoolean("easyprivacy", true)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
             } else {
                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
             } else {
                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
@@ -387,7 +392,7 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the Fanboy lists icons.
         if (fanboyAnnoyanceListEnabled) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 // Set the Fanboy annoyance list icon.
                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_dark);
 
@@ -401,7 +406,7 @@ public class SettingsFragment extends PreferenceFragment {
                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 // Set the Fanboy annoyance list icon.
                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_dark);
 
@@ -426,13 +431,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the UltraPrivacy icon.
         if (savedPreferences.getBoolean("ultraprivacy", true)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
             } else {
                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
             } else {
                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
@@ -441,22 +446,52 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the block all third-party requests icon.
         if (savedPreferences.getBoolean("block_all_third_party_requests", false)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_dark);
             } else {
                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_dark);
             } else {
                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_light);
             }
         }
 
+        // Set the Google Analytics icon according to the theme.
+        if (savedPreferences.getBoolean("google_analytics", true)) {
+            if (darkTheme) {
+                googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_dark);
+            } else {
+                googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_light);
+            }
+        } else {
+            if (darkTheme) {
+                googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_dark);
+            } else {
+                googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_light);
+            }
+        }
+
+        // Set the Facebook Click IDs icon according to the theme.
+        if (savedPreferences.getBoolean("facebook_click_ids", true)) {
+            if (darkTheme) {
+                facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_dark);
+            } else {
+                facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_light);
+            }
+        } else {
+            if (darkTheme) {
+                facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_dark);
+            } else {
+                facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_light);
+            }
+        }
+
         // Set the Tor icons according to the theme.
         if (proxyThroughOrbot) {  // Proxying is enabled.
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 proxyThroughOrbotPreference.setIcon(R.drawable.orbot_enabled_dark);
                 torHomepagePreference.setIcon(R.drawable.home_enabled_dark);
                 torSearchPreference.setIcon(R.drawable.search_enabled_dark);
@@ -480,7 +515,7 @@ public class SettingsFragment extends PreferenceFragment {
                 }
             }
         } else {  // Proxying is disabled.
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 proxyThroughOrbotPreference.setIcon(R.drawable.orbot_disabled_dark);
                 torHomepagePreference.setIcon(R.drawable.home_ghosted_dark);
                 torSearchPreference.setIcon(R.drawable.search_ghosted_dark);
@@ -495,13 +530,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the search custom URL icon.
         if (searchCustomURLPreference.isEnabled()) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
             } else {
                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
             } else {
                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
@@ -511,7 +546,7 @@ public class SettingsFragment extends PreferenceFragment {
         // Set the full screen browsing mode icons.
         if (fullScreenBrowsingMode) {  // Full screen browsing mode is enabled.
             // Set the `fullScreenBrowsingModePreference` icon according to the theme.
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_dark);
             } else {
                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_light);
@@ -520,14 +555,14 @@ public class SettingsFragment extends PreferenceFragment {
             // Set the hide app bar icon.
             if (savedPreferences.getBoolean("hide_app_bar", true)) {  // Hide app bar is enabled.
                 // Set the icon according to the theme.
-                if (MainWebViewActivity.darkTheme) {
+                if (darkTheme) {
                     hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
                 } else {
                     hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
                 }
             } else {  // Hide app bar is disabled.
                 // Set the icon according to the theme.
-                if (MainWebViewActivity.darkTheme) {
+                if (darkTheme) {
                     hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
                 } else {
                     hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
@@ -535,7 +570,7 @@ public class SettingsFragment extends PreferenceFragment {
             }
         } else {  // Full screen browsing mode is disabled.
             // Set the icons according to the theme.
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_dark);
                 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_dark);
             } else {
@@ -546,7 +581,7 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the clear everything preference icon.
         if (clearEverything) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_dark);
             } else {
                 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_light);
@@ -557,7 +592,7 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the clear cookies preference icon.
         if (clearEverything || savedPreferences.getBoolean("clear_cookies", true)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_dark);
             } else {
                 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_light);
@@ -568,7 +603,7 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the clear DOM storage preference icon.
         if (clearEverything || savedPreferences.getBoolean("clear_dom_storage", true)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_dark);
             } else {
                 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_light);
@@ -580,7 +615,7 @@ public class SettingsFragment extends PreferenceFragment {
         // Set the clear form data preference icon if the API < 26.  It has no effect on newer versions of Android.
         if (Build.VERSION.SDK_INT < 26) {
             if (clearEverything || savedPreferences.getBoolean("clear_form_data", true)) {
-                if (MainWebViewActivity.darkTheme) {
+                if (darkTheme) {
                     clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark);
                 } else {
                     clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light);
@@ -592,7 +627,7 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the clear cache preference icon.
         if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 clearCachePreference.setIcon(R.drawable.cache_cleared_dark);
             } else {
                 clearCachePreference.setIcon(R.drawable.cache_cleared_light);
@@ -601,15 +636,30 @@ public class SettingsFragment extends PreferenceFragment {
             clearCachePreference.setIcon(R.drawable.cache_warning);
         }
 
+        // Set the open intents in new tab preference icon.
+        if (savedPreferences.getBoolean("open_intents_in_new_tab", true)) {
+            if (darkTheme) {
+                openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_dark);
+            } else {
+                openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_light);
+            }
+        } else {
+            if (darkTheme) {
+                openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_dark);
+            } else {
+                openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_light);
+            }
+        }
+
         // Set the swipe to refresh preference icon.
         if (savedPreferences.getBoolean("swipe_to_refresh", true)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_dark);
             } else {
                 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_dark);
             } else {
                 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_light);
@@ -618,13 +668,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the scroll app bar preference icon.
         if (savedPreferences.getBoolean("scroll_app_bar", true)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
             } else {
                 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
             } else {
                 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
@@ -633,13 +683,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the display additional app bar icons preference icon.
         if (savedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_dark);
             } else {
                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_dark);
             } else {
                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_light);
@@ -648,13 +698,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the download with external app preference icon.
         if (savedPreferences.getBoolean("download_with_external_app", false)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_dark);
             } else {
                 downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_dark);
             } else {
                 downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_light);
@@ -670,13 +720,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the night mode preference icon.
         if (nightMode) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 nightModePreference.setIcon(R.drawable.night_mode_enabled_dark);
             } else {
                 nightModePreference.setIcon(R.drawable.night_mode_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 nightModePreference.setIcon(R.drawable.night_mode_disabled_dark);
             } else {
                 nightModePreference.setIcon(R.drawable.night_mode_disabled_light);
@@ -685,13 +735,13 @@ public class SettingsFragment extends PreferenceFragment {
 
         // Set the display webpage images preference icon.
         if (savedPreferences.getBoolean("display_webpage_images", true)) {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_dark);
             } else {
                 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_light);
             }
         } else {
-            if (MainWebViewActivity.darkTheme) {
+            if (darkTheme) {
                 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_dark);
             } else {
                 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_light);
@@ -715,7 +765,7 @@ public class SettingsFragment extends PreferenceFragment {
                         if (sharedPreferences.getBoolean("dom_storage", false)) {
                             domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
                         } else {
-                            if (MainWebViewActivity.darkTheme) {
+                            if (darkTheme) {
                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
                             } else {
                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
@@ -729,7 +779,7 @@ public class SettingsFragment extends PreferenceFragment {
                         domStoragePreference.setEnabled(false);
 
                         // Set the icon for DOM storage preference to be ghosted.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_dark);
                         } else {
                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_light);
@@ -748,14 +798,14 @@ public class SettingsFragment extends PreferenceFragment {
                             if (sharedPreferences.getBoolean("third_party_cookies", false)) {
                                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
                             } else {
-                                if (MainWebViewActivity.darkTheme) {
+                                if (darkTheme) {
                                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
                                 } else {
                                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
                                 }
                             }
                         } else {
-                            if (MainWebViewActivity.darkTheme) {
+                            if (darkTheme) {
                                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_dark);
                             } else {
                                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_light);
@@ -763,14 +813,14 @@ public class SettingsFragment extends PreferenceFragment {
                         }
                     } else {  // `first_party_cookies` is `false`.
                         // Update the icon for `first_party_cookies`.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
                         } else {
                             firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
                         }
 
                         // Set the icon for `third_party_cookies` to be ghosted.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_dark);
                         } else {
                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_light);
@@ -786,7 +836,7 @@ public class SettingsFragment extends PreferenceFragment {
                     if (sharedPreferences.getBoolean("third_party_cookies", false)) {
                         thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
                         } else {
                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
@@ -799,7 +849,7 @@ public class SettingsFragment extends PreferenceFragment {
                     if (sharedPreferences.getBoolean("dom_storage", false)) {
                         domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
                         } else {
                             domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
@@ -811,12 +861,12 @@ public class SettingsFragment extends PreferenceFragment {
                 case "save_form_data":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("save_form_data", false)) {
-                        saveFormDataPreference.setIcon(R.drawable.form_data_enabled);
+                        formDataPreference.setIcon(R.drawable.form_data_enabled);
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
-                            saveFormDataPreference.setIcon(R.drawable.form_data_disabled_dark);
+                        if (darkTheme) {
+                            formDataPreference.setIcon(R.drawable.form_data_disabled_dark);
                         } else {
-                            saveFormDataPreference.setIcon(R.drawable.form_data_disabled_light);
+                            formDataPreference.setIcon(R.drawable.form_data_disabled_light);
                         }
                     }
                     break;
@@ -841,7 +891,7 @@ public class SettingsFragment extends PreferenceFragment {
                             customUserAgentPreference.setEnabled(false);
 
                             // Set the custom user agent preference icon according to the theme.
-                            if (MainWebViewActivity.darkTheme) {
+                            if (darkTheme) {
                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_dark);
                             } else {
                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_light);
@@ -856,7 +906,7 @@ public class SettingsFragment extends PreferenceFragment {
                             customUserAgentPreference.setEnabled(true);
 
                             // Set the custom user agent preference icon according to the theme.
-                            if (MainWebViewActivity.darkTheme) {
+                            if (darkTheme) {
                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_dark);
                             } else {
                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_light);
@@ -871,7 +921,7 @@ public class SettingsFragment extends PreferenceFragment {
                             customUserAgentPreference.setEnabled(false);
 
                             // Set the custom user agent preference icon according to the theme.
-                            if (MainWebViewActivity.darkTheme) {
+                            if (darkTheme) {
                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_dark);
                             } else {
                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_light);
@@ -887,13 +937,13 @@ public class SettingsFragment extends PreferenceFragment {
                 case "incognito_mode":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("incognito_mode", false)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_dark);
                         } else {
                             incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_dark);
                         } else {
                             incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_light);
@@ -904,13 +954,13 @@ public class SettingsFragment extends PreferenceFragment {
                 case "do_not_track":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("do_not_track", false)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_dark);
                         } else {
                             doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_dark);
                         } else {
                             doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_light);
@@ -922,13 +972,13 @@ public class SettingsFragment extends PreferenceFragment {
                 case "allow_screenshots":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("allow_screenshots", false)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_dark);
                         } else {
                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_dark);
                         } else {
                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_light);
@@ -941,23 +991,35 @@ public class SettingsFragment extends PreferenceFragment {
                     // Assert that the intent is not null to remove the lint error below.
                     assert allowScreenshotsRestartIntent != null;
 
-                    // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.  TODO.
+                    // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
                     allowScreenshotsRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
 
-                    // Make it so.
-                    startActivity(allowScreenshotsRestartIntent);
+                    // Create a handler to restart the activity.
+                    Handler allowScreenshotsRestartHandler = new Handler();
+
+                    // Create a runnable to restart the activity.
+                    Runnable allowScreenshotsRestartRunnable = () -> {
+                        // Restart the activity.
+                        startActivity(allowScreenshotsRestartIntent);
+
+                        // Kill this instance of Privacy Browser.  Otherwise, the app exhibits sporadic behavior after the restart.
+                        System.exit(0);
+                    };
+
+                    // Restart the activity after 100 milliseconds, so that the app has enough time to save the change to the preference.
+                    allowScreenshotsRestartHandler.postDelayed(allowScreenshotsRestartRunnable, 100);
                     break;
 
                 case "easylist":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("easylist", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             easyListPreference.setIcon(R.drawable.block_ads_enabled_dark);
                         } else {
                             easyListPreference.setIcon(R.drawable.block_ads_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             easyListPreference.setIcon(R.drawable.block_ads_disabled_dark);
                         } else {
                             easyListPreference.setIcon(R.drawable.block_ads_disabled_light);
@@ -968,13 +1030,13 @@ public class SettingsFragment extends PreferenceFragment {
                 case "easyprivacy":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("easyprivacy", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
                         } else {
                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
                         } else {
                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
@@ -988,7 +1050,7 @@ public class SettingsFragment extends PreferenceFragment {
 
                     // Update the Fanboy icons.
                     if (currentFanboyAnnoyanceList) {  // Fanboy's annoyance list is enabled.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             // Update the Fanboy's annoyance list icon.
                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_dark);
 
@@ -1002,7 +1064,7 @@ public class SettingsFragment extends PreferenceFragment {
                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_light);
                         }
                     } else {  // Fanboy's annoyance list is disabled.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             // Update the Fanboy's annoyance list icon.
                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_dark);
 
@@ -1032,13 +1094,13 @@ public class SettingsFragment extends PreferenceFragment {
                 case "fanboys_social_blocking_list":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_dark);
                         } else {
                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_dark);
                         } else {
                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_light);
@@ -1049,13 +1111,13 @@ public class SettingsFragment extends PreferenceFragment {
                 case "ultraprivacy":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("ultraprivacy", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
                         } else {
                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
                         } else {
                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
@@ -1066,13 +1128,13 @@ public class SettingsFragment extends PreferenceFragment {
                 case "block_all_third_party_requests":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_dark);
                         } else {
                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_dark);
                         } else {
                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_light);
@@ -1080,6 +1142,40 @@ public class SettingsFragment extends PreferenceFragment {
                     }
                     break;
 
+                case "google_analytics":
+                    // Update the icon.
+                    if (sharedPreferences.getBoolean("google_analytics", true)) {
+                        if (darkTheme) {
+                            googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_dark);
+                        } else {
+                            googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_light);
+                        }
+                    } else {
+                        if (darkTheme) {
+                            googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_dark);
+                        } else {
+                            googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_light);
+                        }
+                    }
+                    break;
+
+                case "facebook_click_ids":
+                    // Update the icon.
+                    if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
+                        if (darkTheme) {
+                            facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_dark);
+                        } else {
+                            facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_light);
+                        }
+                    } else {
+                        if (darkTheme) {
+                            facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_dark);
+                        } else {
+                            facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_light);
+                        }
+                    }
+                    break;
+
                 case "proxy_through_orbot":
                     // Get current settings.
                     boolean currentProxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false);
@@ -1091,7 +1187,7 @@ public class SettingsFragment extends PreferenceFragment {
                     // Update the icons.
                     if (currentProxyThroughOrbot) {
                         // Set the Tor icons according to the theme.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             proxyThroughOrbotPreference.setIcon(R.drawable.orbot_enabled_dark);
                             torHomepagePreference.setIcon(R.drawable.home_enabled_dark);
                             torSearchPreference.setIcon(R.drawable.search_enabled_dark);
@@ -1115,7 +1211,7 @@ public class SettingsFragment extends PreferenceFragment {
                             }
                         }
                     } else {  // Proxy through Orbot is disabled.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             proxyThroughOrbotPreference.setIcon(R.drawable.orbot_disabled_dark);
                             torHomepagePreference.setIcon(R.drawable.home_ghosted_dark);
                             torSearchPreference.setIcon(R.drawable.search_ghosted_dark);
@@ -1147,7 +1243,7 @@ public class SettingsFragment extends PreferenceFragment {
                         torSearchCustomURLPreference.setEnabled(true);
 
                         // Update the `torSearchCustomURLPreference` icon.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
                         } else {
                             torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
@@ -1160,7 +1256,7 @@ public class SettingsFragment extends PreferenceFragment {
                         torSearchCustomURLPreference.setEnabled(false);
 
                         // Update the `torSearchCustomURLPreference` icon.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
                         } else {
                             torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
@@ -1186,7 +1282,7 @@ public class SettingsFragment extends PreferenceFragment {
                         searchCustomURLPreference.setEnabled(true);
 
                         // Set the `searchCustomURLPreference` according to the theme.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
                         } else {
                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
@@ -1199,7 +1295,7 @@ public class SettingsFragment extends PreferenceFragment {
                         searchCustomURLPreference.setEnabled(false);
 
                         // Set the `searchCustomURLPreference` according to the theme.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
                         } else {
                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
@@ -1215,7 +1311,7 @@ public class SettingsFragment extends PreferenceFragment {
                 case "full_screen_browsing_mode":
                     if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) {  // Full screen browsing is enabled.
                         // Set the full screen browsing mode preference icon according to the theme.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_dark);
                         } else {
                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_light);
@@ -1224,14 +1320,14 @@ public class SettingsFragment extends PreferenceFragment {
                         // Set the hide app bar preference icon.
                         if (sharedPreferences.getBoolean("hide_app_bar", true)) {  //  Hide app bar is enabled.
                             // Set the icon according to the theme.
-                            if (MainWebViewActivity.darkTheme) {
+                            if (darkTheme) {
                                 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
                             } else {
                                 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
                             }
                         } else {  // Hide app bar is disabled.
                             // Set the icon according to the theme.
-                            if (MainWebViewActivity.darkTheme) {
+                            if (darkTheme) {
                                 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
                             } else {
                                 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
@@ -1239,7 +1335,7 @@ public class SettingsFragment extends PreferenceFragment {
                         }
                     } else {  // Full screen browsing is disabled.
                         // Update the icons according to the theme.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_dark);
                             hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_dark);
                         } else {
@@ -1253,14 +1349,14 @@ public class SettingsFragment extends PreferenceFragment {
                     // Update the icon.
                     if (sharedPreferences.getBoolean("hide_app_bar", true)) {  // Hide app bar is enabled.
                         // Set the icon according to the theme.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
                         } else {
                             hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
                         }
                     } else {  // Hide app bar is disabled.
                         // Set the icon according to the theme.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
                         } else {
                             hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
@@ -1280,7 +1376,7 @@ public class SettingsFragment extends PreferenceFragment {
 
                     // Update the `clearEverythingPreference` icon.
                     if (newClearEverythingBoolean) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_dark);
                         } else {
                             clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_light);
@@ -1291,7 +1387,7 @@ public class SettingsFragment extends PreferenceFragment {
 
                     // Update the `clearCookiesPreference` icon.
                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_dark);
                         } else {
                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_light);
@@ -1302,7 +1398,7 @@ public class SettingsFragment extends PreferenceFragment {
 
                     // Update the `clearDomStoragePreference` icon.
                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_dark);
                         } else {
                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_light);
@@ -1314,7 +1410,7 @@ public class SettingsFragment extends PreferenceFragment {
                     // Update the clear form data preference icon if the API < 26.
                     if (Build.VERSION.SDK_INT < 26) {
                         if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) {
-                            if (MainWebViewActivity.darkTheme) {
+                            if (darkTheme) {
                                 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark);
                             } else {
                                 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light);
@@ -1326,7 +1422,7 @@ public class SettingsFragment extends PreferenceFragment {
 
                     // Update the `clearCachePreference` icon.
                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             clearCachePreference.setIcon(R.drawable.cache_cleared_dark);
                         } else {
                             clearCachePreference.setIcon(R.drawable.cache_cleared_light);
@@ -1339,7 +1435,7 @@ public class SettingsFragment extends PreferenceFragment {
                 case "clear_cookies":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("clear_cookies", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_dark);
                         } else {
                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_light);
@@ -1352,7 +1448,7 @@ public class SettingsFragment extends PreferenceFragment {
                 case "clear_dom_storage":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_dark);
                         } else {
                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_light);
@@ -1366,7 +1462,7 @@ public class SettingsFragment extends PreferenceFragment {
                 case "clear_form_data":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("clear_form_data", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark);
                         } else {
                             clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light);
@@ -1379,7 +1475,7 @@ public class SettingsFragment extends PreferenceFragment {
                 case "clear_cache":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("clear_cache", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             clearCachePreference.setIcon(R.drawable.cache_cleared_dark);
                         } else {
                             clearCachePreference.setIcon(R.drawable.cache_cleared_light);
@@ -1399,16 +1495,33 @@ public class SettingsFragment extends PreferenceFragment {
                     fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%%");
                     break;
 
+                case "open_intents_in_new_tab":
+                    // Update the icon.
+                    if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
+                        if (darkTheme) {
+                            openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_dark);
+                        } else {
+                            openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_light);
+                        }
+                    } else {
+                        if (darkTheme) {
+                            openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_dark);
+                        } else {
+                            openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_light);
+                        }
+                    }
+                    break;
+
                 case "swipe_to_refresh":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_dark);
                         } else {
                             swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_dark);
                         } else {
                             swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_light);
@@ -1419,13 +1532,13 @@ public class SettingsFragment extends PreferenceFragment {
                 case "scroll_app_bar":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
                         } else {
                             scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
                         } else {
                             scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
@@ -1436,13 +1549,13 @@ public class SettingsFragment extends PreferenceFragment {
                 case "display_additional_app_bar_icons":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_dark);
                         } else {
                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_dark);
                         } else {
                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_light);
@@ -1453,13 +1566,13 @@ public class SettingsFragment extends PreferenceFragment {
                 case "download_with_external_app":
                     // Update the icon.
                     if (sharedPreferences.getBoolean("download_with_external_app", false)) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_dark);
                         } else {
                             downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_dark);
                         } else {
                             downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_light);
@@ -1481,30 +1594,39 @@ public class SettingsFragment extends PreferenceFragment {
                     // Assert that the intent is not null to remove the lint error below.
                     assert changeThemeRestartIntent != null;
 
-                    // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.  TODO.
+                    // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
                     changeThemeRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
 
-                    // Make it so.
-                    startActivity(changeThemeRestartIntent);
+                    // Create a handler to restart the activity.
+                    Handler changeThemeRestartHandler = new Handler();
+
+                    // Create a runnable to restart the activity.
+                    Runnable changeThemeRestartRunnable = () -> {
+                        // Restart the activity.
+                        startActivity(changeThemeRestartIntent);
+
+                        // Kill this instance of Privacy Browser.  Otherwise, the app exhibits sporadic behavior after the restart.
+                        System.exit(0);
+                    };
+
+                    // Restart the activity after 100 milliseconds, so that the app has enough time to save the change to the preference.
+                    changeThemeRestartHandler.postDelayed(changeThemeRestartRunnable, 100);
                     break;
 
                 case "night_mode":
-                    // Set the URL to be reloaded on restart to apply the new night mode setting.
-                    MainWebViewActivity.loadUrlOnRestart = true;
-
                     // Store the current night mode status.
                     boolean currentNightModeBoolean = sharedPreferences.getBoolean("night_mode", false);
                     boolean currentJavaScriptBoolean = sharedPreferences.getBoolean("javascript", false);
 
                     // Update the icon.
                     if (currentNightModeBoolean) {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             nightModePreference.setIcon(R.drawable.night_mode_enabled_dark);
                         } else {
                             nightModePreference.setIcon(R.drawable.night_mode_enabled_light);
                         }
                     } else {
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             nightModePreference.setIcon(R.drawable.night_mode_disabled_dark);
                         } else {
                             nightModePreference.setIcon(R.drawable.night_mode_disabled_light);
@@ -1527,14 +1649,14 @@ public class SettingsFragment extends PreferenceFragment {
                         if (sharedPreferences.getBoolean("dom_storage", false)) {  // DOM storage is enabled.
                             domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
                         } else {  // DOM storage is disabled.
-                            if (MainWebViewActivity.darkTheme) {
+                            if (darkTheme) {
                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
                             } else {
                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
                             }
                         }
                     } else {  // The preference is disabled.  The icon should be ghosted.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_dark);
                         } else {
                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_light);
@@ -1545,24 +1667,18 @@ public class SettingsFragment extends PreferenceFragment {
                 case "display_webpage_images":
                     if (sharedPreferences.getBoolean("display_webpage_images", true)) {
                         // Update the icon.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_dark);
                         } else {
                             displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_light);
                         }
-
-                        // `mainWebView` does not need to be reloaded because unloaded images will load automatically.
-                        MainWebViewActivity.reloadOnRestart = false;
                     } else {
                         // Update the icon.
-                        if (MainWebViewActivity.darkTheme) {
+                        if (darkTheme) {
                             displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_dark);
                         } else {
                             displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_light);
                         }
-
-                        // Set `mainWebView` to reload on restart to remove the current images.
-                        MainWebViewActivity.reloadOnRestart = true;
                     }
                     break;
             }