4001345b14037b1497f734f58b6e30b4b1b42c2f
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / SettingsFragment.java
1 /*
2  * Copyright © 2016-2019 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
5  *
6  * Privacy Browser is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacybrowser.fragments;
21
22 import android.annotation.SuppressLint;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.content.SharedPreferences;
26 import android.os.Build;
27 import android.os.Bundle;
28 import android.os.Handler;
29 import android.preference.Preference;
30 import android.preference.PreferenceCategory;
31 import android.preference.PreferenceFragment;
32 import android.view.LayoutInflater;
33 import android.view.View;
34 import android.webkit.WebView;
35 import android.widget.ArrayAdapter;
36
37 import com.stoutner.privacybrowser.R;
38 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
39
40 public class SettingsFragment extends PreferenceFragment {
41     private SharedPreferences.OnSharedPreferenceChangeListener preferencesListener;
42     private SharedPreferences savedPreferences;
43
44     @Override
45     public void onCreate(Bundle savedInstanceState) {
46         // Run the default commands.
47         super.onCreate(savedInstanceState);
48
49         // Load the preferences from the XML file.
50         addPreferencesFromResource(R.xml.preferences);
51
52         // Get a handle for the context.
53         Context context = getActivity().getApplicationContext();
54
55         // Initialize savedPreferences.
56         savedPreferences = getPreferenceScreen().getSharedPreferences();
57
58         // Get handles for the preferences.
59         final Preference javaScriptPreference = findPreference("javascript");
60         final Preference firstPartyCookiesPreference = findPreference("first_party_cookies");
61         final Preference thirdPartyCookiesPreference = findPreference("third_party_cookies");
62         final Preference domStoragePreference = findPreference("dom_storage");
63         final Preference saveFormDataPreference = findPreference("save_form_data");  // The form data preference can be removed once the minimum API >= 26.
64         final Preference userAgentPreference = findPreference("user_agent");
65         final Preference customUserAgentPreference = findPreference("custom_user_agent");
66         final Preference incognitoModePreference = findPreference("incognito_mode");
67         final Preference doNotTrackPreference = findPreference("do_not_track");
68         final Preference allowScreenshotsPreference = findPreference("allow_screenshots");
69         final Preference easyListPreference = findPreference("easylist");
70         final Preference easyPrivacyPreference = findPreference("easyprivacy");
71         final Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
72         final Preference fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
73         final Preference ultraPrivacyPreference = findPreference("ultraprivacy");
74         final Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
75         final Preference proxyThroughOrbotPreference = findPreference("proxy_through_orbot");
76         final Preference torHomepagePreference = findPreference("tor_homepage");
77         final Preference torSearchPreference = findPreference("tor_search");
78         final Preference torSearchCustomURLPreference = findPreference("tor_search_custom_url");
79         final Preference searchPreference = findPreference("search");
80         final Preference searchCustomURLPreference = findPreference("search_custom_url");
81         final Preference fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
82         final Preference hideAppBarPreference = findPreference("hide_app_bar");
83         final Preference clearEverythingPreference = findPreference("clear_everything");
84         final Preference clearCookiesPreference = findPreference("clear_cookies");
85         final Preference clearDomStoragePreference = findPreference("clear_dom_storage");
86         final Preference clearFormDataPreference = findPreference("clear_form_data");  // The clear form data preference can be removed once the minimum API >= 26.
87         final Preference clearCachePreference = findPreference("clear_cache");
88         final Preference homepagePreference = findPreference("homepage");
89         final Preference fontSizePreference = findPreference("font_size");
90         final Preference swipeToRefreshPreference = findPreference("swipe_to_refresh");
91         final Preference scrollAppBarPreference = findPreference("scroll_app_bar");
92         final Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons");
93         final Preference downloadWithExternalAppPreference = findPreference("download_with_external_app");
94         final Preference darkThemePreference = findPreference("dark_theme");
95         final Preference nightModePreference = findPreference("night_mode");
96         final Preference displayWebpageImagesPreference = findPreference("display_webpage_images");
97
98         // Set dependencies.
99         torHomepagePreference.setDependency("proxy_through_orbot");
100         torSearchPreference.setDependency("proxy_through_orbot");
101         hideAppBarPreference.setDependency("full_screen_browsing_mode");
102
103         // Get strings from the preferences.
104         String torSearchString = savedPreferences.getString("tor_search", getString(R.string.tor_search_default_value));
105         String searchString = savedPreferences.getString("search", getString(R.string.search_default_value));
106
107         // Get booleans that are used in multiple places from the preferences.
108         final boolean javaScriptEnabled = savedPreferences.getBoolean("javascript", false);
109         boolean firstPartyCookiesEnabled = savedPreferences.getBoolean("first_party_cookies", false);
110         boolean thirdPartyCookiesEnabled = savedPreferences.getBoolean("third_party_cookies", false);
111         boolean fanboyAnnoyanceListEnabled = savedPreferences.getBoolean("fanboys_annoyance_list", true);
112         boolean fanboySocialBlockingEnabled = savedPreferences.getBoolean("fanboys_social_blocking_list", true);
113         boolean proxyThroughOrbot = savedPreferences.getBoolean("proxy_through_orbot", false);
114         boolean fullScreenBrowsingMode = savedPreferences.getBoolean("full_screen_browsing_mode", false);
115         boolean clearEverything = savedPreferences.getBoolean("clear_everything", true);
116         boolean darkTheme = savedPreferences.getBoolean("dark_theme", false);
117         final boolean nightMode = savedPreferences.getBoolean("night_mode", false);
118
119         // Only enable the third-party cookies preference if first-party cookies are enabled and API >= 21.
120         thirdPartyCookiesPreference.setEnabled(firstPartyCookiesEnabled && (Build.VERSION.SDK_INT >= 21));
121
122         // Only enable the DOM storage preference if either JavaScript or Night Mode is enabled.
123         domStoragePreference.setEnabled(javaScriptEnabled || nightMode);
124
125         // Remove the form data preferences if the API is >= 26 as they no longer do anything.
126         if (Build.VERSION.SDK_INT >= 26) {
127             // Get the categories.
128             PreferenceCategory privacyCategory = (PreferenceCategory) findPreference("privacy");
129             PreferenceCategory clearAndExitCategory = (PreferenceCategory) findPreference("clear_and_exit");
130
131             // Remove the form data preferences.
132             privacyCategory.removePreference(saveFormDataPreference);
133             clearAndExitCategory.removePreference(clearFormDataPreference);
134         }
135
136         // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled.
137         fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled);
138
139         // Inflate a WebView to get the default user agent.
140         LayoutInflater inflater = getActivity().getLayoutInflater();
141         // `@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.
142         @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
143         final WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
144
145         // Get the user agent arrays.
146         ArrayAdapter<CharSequence> userAgentNamesArray = ArrayAdapter.createFromResource(context, R.array.user_agent_names, R.layout.spinner_item);
147         String[] translatedUserAgentNamesArray = getResources().getStringArray(R.array.translated_user_agent_names);
148         String[] userAgentDataArray = getResources().getStringArray(R.array.user_agent_data);
149
150         // Get the current user agent name from the preference.
151         String userAgentName = savedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
152
153         // Get the array position of the user agent name.
154         int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
155
156         // Populate the user agent summary.
157         switch (userAgentArrayPosition) {
158             case MainWebViewActivity.UNRECOGNIZED_USER_AGENT:  // The user agent name is not on the canonical list.
159                 // This is probably because it was set in an older version of Privacy Browser before the switch to persistent user agent names.  Use the current user agent entry name as the summary.
160                 userAgentPreference.setSummary(userAgentName);
161                 break;
162
163             case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
164                 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
165                 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + bareWebView.getSettings().getUserAgentString());
166                 break;
167
168             case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
169                 // Set the summary text.
170                 userAgentPreference.setSummary(R.string.custom_user_agent);
171                 break;
172
173             default:
174                 // Get the user agent summary from the user agent data array.
175                 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + userAgentDataArray[userAgentArrayPosition]);
176         }
177
178         // Set the summary text for the custom user agent preference and enable it if user agent preference is set to custom.
179         customUserAgentPreference.setSummary(savedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
180         customUserAgentPreference.setEnabled(userAgentPreference.getSummary().equals(getString(R.string.custom_user_agent)));
181
182
183         // Set the Tor homepage URL as the summary text for the `tor_homepage` preference when the preference screen is loaded.  The default is Searx: `http://ulrn6sryqaifefld.onion/`.
184         torHomepagePreference.setSummary(savedPreferences.getString("tor_homepage", getString(R.string.tor_homepage_default_value)));
185
186
187         // Set the Tor search URL as the summary text for the Tor preference when the preference screen is loaded.
188         if (torSearchString.equals("Custom URL")) {
189             // Use R.string.custom_url, which will be translated, instead of the array value, which will not.
190             torSearchPreference.setSummary(R.string.custom_url);
191         } else {
192             // Set the array value as the summary text.
193             torSearchPreference.setSummary(torSearchString);
194         }
195
196         // Set the summary text for `tor_search_custom_url`.  The default is `""`.
197         torSearchCustomURLPreference.setSummary(savedPreferences.getString("tor_search_custom_url", getString(R.string.tor_search_custom_url_default_value)));
198
199         // Enable the Tor custom URL search options only if proxying through Orbot and the search is set to `Custom URL`.
200         torSearchCustomURLPreference.setEnabled(proxyThroughOrbot && torSearchString.equals("Custom URL"));
201
202
203         // Set the search URL as the summary text for the search preference when the preference screen is loaded.
204         if (searchString.equals("Custom URL")) {
205             // Use R.string.custom_url, which will be translated, instead of the array value, which will not.
206             searchPreference.setSummary(R.string.custom_url);
207         } else {
208             // Set the array value as the summary text.
209             searchPreference.setSummary(searchString);
210         }
211
212         // Set the summary text for `search_custom_url` (the default is `""`) and enable it if `search` is set to `Custom URL`.
213         searchCustomURLPreference.setSummary(savedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
214         searchCustomURLPreference.setEnabled(searchString.equals("Custom URL"));
215
216         // Set the status of the Clear and Exit preferences.
217         clearCookiesPreference.setEnabled(!clearEverything);
218         clearDomStoragePreference.setEnabled(!clearEverything);
219         clearFormDataPreference.setEnabled(!clearEverything);  // The form data line can be removed once the minimum API is >= 26.
220         clearCachePreference.setEnabled(!clearEverything);
221
222         // Set the homepage URL as the summary text for the homepage preference.
223         homepagePreference.setSummary(savedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
224
225         // Set the font size as the summary text for the preference.
226         fontSizePreference.setSummary(savedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%%");
227
228         // Disable the JavaScript preference if Night Mode is enabled.  JavaScript will be enabled for all web pages.
229         javaScriptPreference.setEnabled(!nightMode);
230
231         // Set the JavaScript icon.
232         if (javaScriptEnabled || nightMode) {
233             javaScriptPreference.setIcon(R.drawable.javascript_enabled);
234         } else {
235             javaScriptPreference.setIcon(R.drawable.privacy_mode);
236         }
237
238         // Set the first-party cookies icon.
239         if (firstPartyCookiesEnabled) {
240             firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
241         } else {
242             if (darkTheme) {
243                 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
244             } else {
245                 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
246             }
247         }
248
249         // Set the third party cookies icon.
250         if (firstPartyCookiesEnabled && Build.VERSION.SDK_INT >= 21) {
251             if (thirdPartyCookiesEnabled) {
252                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
253             } else {
254                 if (darkTheme) {
255                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
256                 } else {
257                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
258                 }
259             }
260         } else {
261             if (darkTheme) {
262                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_dark);
263             } else {
264                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_light);
265             }
266         }
267
268         // Set the DOM storage icon.
269         if (javaScriptEnabled || nightMode) {  // The preference is enabled.
270             if (savedPreferences.getBoolean("dom_storage", false)) {  // DOM storage is enabled.
271                 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
272             } else {  // DOM storage is disabled.
273                 if (darkTheme) {
274                     domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
275                 } else {
276                     domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
277                 }
278             }
279         } else {  // The preference is disabled.  The icon should be ghosted.
280             if (darkTheme) {
281                 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_dark);
282             } else {
283                 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_light);
284             }
285         }
286
287         // Set the save form data icon if API < 26.  Save form data has no effect on API >= 26.
288         if (Build.VERSION.SDK_INT < 26) {
289             if (savedPreferences.getBoolean("save_form_data", false)) {
290                 saveFormDataPreference.setIcon(R.drawable.form_data_enabled);
291             } else {
292                 if (darkTheme) {
293                     saveFormDataPreference.setIcon(R.drawable.form_data_disabled_dark);
294                 } else {
295                     saveFormDataPreference.setIcon(R.drawable.form_data_disabled_light);
296                 }
297             }
298         }
299
300         // Set the custom user agent icon.
301         if (customUserAgentPreference.isEnabled()) {
302             if (darkTheme) {
303                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_dark);
304             } else {
305                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_light);
306             }
307         } else {
308             if (darkTheme) {
309                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_dark);
310             } else {
311                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_light);
312             }
313         }
314
315         // Set the incognito mode icon.
316         if (savedPreferences.getBoolean("incognito_mode", false)) {
317             if (darkTheme) {
318                 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_dark);
319             } else {
320                 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_light);
321             }
322         } else {
323             if (darkTheme) {
324                 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_dark);
325             } else {
326                 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_light);
327             }
328         }
329
330         // Set the Do Not Track icon.
331         if (savedPreferences.getBoolean("do_not_track", false)) {
332             if (darkTheme) {
333                 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_dark);
334             } else {
335                 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_light);
336             }
337         } else {
338             if (darkTheme) {
339                 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_dark);
340             } else {
341                 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_light);
342             }
343         }
344
345         // Set the allow screenshots icon.
346         if (savedPreferences.getBoolean("allow_screenshots", false)) {
347             if (darkTheme) {
348                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_dark);
349             } else {
350                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_light);
351             }
352         } else {
353             if (darkTheme) {
354                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_dark);
355             } else {
356                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_light);
357             }
358         }
359
360         // Set the EasyList icon.
361         if (savedPreferences.getBoolean("easylist", true)) {
362             if (darkTheme) {
363                 easyListPreference.setIcon(R.drawable.block_ads_enabled_dark);
364             } else {
365                 easyListPreference.setIcon(R.drawable.block_ads_enabled_light);
366             }
367         } else {
368             if (darkTheme) {
369                 easyListPreference.setIcon(R.drawable.block_ads_disabled_dark);
370             } else {
371                 easyListPreference.setIcon(R.drawable.block_ads_disabled_light);
372             }
373         }
374
375         // Set the EasyPrivacy icon.
376         if (savedPreferences.getBoolean("easyprivacy", true)) {
377             if (darkTheme) {
378                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
379             } else {
380                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
381             }
382         } else {
383             if (darkTheme) {
384                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
385             } else {
386                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
387             }
388         }
389
390         // Set the Fanboy lists icons.
391         if (fanboyAnnoyanceListEnabled) {
392             if (darkTheme) {
393                 // Set the Fanboy annoyance list icon.
394                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_dark);
395
396                 // Set the Fanboy social blocking list icon.
397                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_dark);
398             } else {
399                 // Set the Fanboy annoyance list icon.
400                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_light);
401
402                 // Set the Fanboy social blocking list icon.
403                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_light);
404             }
405         } else {
406             if (darkTheme) {
407                 // Set the Fanboy annoyance list icon.
408                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_dark);
409
410                 // Set the Fanboy social blocking list icon.
411                 if (fanboySocialBlockingEnabled) {
412                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_dark);
413                 } else {
414                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_dark);
415                 }
416             } else {
417                 // Set the Fanboy annoyance list icon.
418                 fanboyAnnoyanceListPreference.setIcon(R.drawable.block_ads_disabled_light);
419
420                 // Set the Fanboy social blocking list icon.
421                 if (fanboySocialBlockingEnabled) {
422                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_light);
423                 } else {
424                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_light);
425                 }
426             }
427         }
428
429         // Set the UltraPrivacy icon.
430         if (savedPreferences.getBoolean("ultraprivacy", true)) {
431             if (darkTheme) {
432                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
433             } else {
434                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
435             }
436         } else {
437             if (darkTheme) {
438                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
439             } else {
440                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
441             }
442         }
443
444         // Set the block all third-party requests icon.
445         if (savedPreferences.getBoolean("block_all_third_party_requests", false)) {
446             if (darkTheme) {
447                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_dark);
448             } else {
449                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_light);
450             }
451         } else {
452             if (darkTheme) {
453                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_dark);
454             } else {
455                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_light);
456             }
457         }
458
459         // Set the Tor icons according to the theme.
460         if (proxyThroughOrbot) {  // Proxying is enabled.
461             if (darkTheme) {
462                 proxyThroughOrbotPreference.setIcon(R.drawable.orbot_enabled_dark);
463                 torHomepagePreference.setIcon(R.drawable.home_enabled_dark);
464                 torSearchPreference.setIcon(R.drawable.search_enabled_dark);
465
466                 // Set the custom search icon.
467                 if (torSearchCustomURLPreference.isEnabled()) {
468                     torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
469                 } else {
470                     torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
471                 }
472             } else {
473                 proxyThroughOrbotPreference.setIcon(R.drawable.orbot_enabled_light);
474                 torHomepagePreference.setIcon(R.drawable.home_enabled_light);
475                 torSearchPreference.setIcon(R.drawable.search_enabled_light);
476
477                 // Set the custom search icon.
478                 if (torSearchCustomURLPreference.isEnabled()) {
479                     torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
480                 } else {
481                     torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
482                 }
483             }
484         } else {  // Proxying is disabled.
485             if (darkTheme) {
486                 proxyThroughOrbotPreference.setIcon(R.drawable.orbot_disabled_dark);
487                 torHomepagePreference.setIcon(R.drawable.home_ghosted_dark);
488                 torSearchPreference.setIcon(R.drawable.search_ghosted_dark);
489                 torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
490             } else {
491                 proxyThroughOrbotPreference.setIcon(R.drawable.orbot_disabled_light);
492                 torHomepagePreference.setIcon(R.drawable.home_ghosted_light);
493                 torSearchPreference.setIcon(R.drawable.search_ghosted_light);
494                 torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
495             }
496         }
497
498         // Set the search custom URL icon.
499         if (searchCustomURLPreference.isEnabled()) {
500             if (darkTheme) {
501                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
502             } else {
503                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
504             }
505         } else {
506             if (darkTheme) {
507                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
508             } else {
509                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
510             }
511         }
512
513         // Set the full screen browsing mode icons.
514         if (fullScreenBrowsingMode) {  // Full screen browsing mode is enabled.
515             // Set the `fullScreenBrowsingModePreference` icon according to the theme.
516             if (darkTheme) {
517                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_dark);
518             } else {
519                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_light);
520             }
521
522             // Set the hide app bar icon.
523             if (savedPreferences.getBoolean("hide_app_bar", true)) {  // Hide app bar is enabled.
524                 // Set the icon according to the theme.
525                 if (darkTheme) {
526                     hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
527                 } else {
528                     hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
529                 }
530             } else {  // Hide app bar is disabled.
531                 // Set the icon according to the theme.
532                 if (darkTheme) {
533                     hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
534                 } else {
535                     hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
536                 }
537             }
538         } else {  // Full screen browsing mode is disabled.
539             // Set the icons according to the theme.
540             if (darkTheme) {
541                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_dark);
542                 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_dark);
543             } else {
544                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_light);
545                 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_light);
546             }
547         }
548
549         // Set the clear everything preference icon.
550         if (clearEverything) {
551             if (darkTheme) {
552                 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_dark);
553             } else {
554                 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_light);
555             }
556         } else {
557             clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
558         }
559
560         // Set the clear cookies preference icon.
561         if (clearEverything || savedPreferences.getBoolean("clear_cookies", true)) {
562             if (darkTheme) {
563                 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_dark);
564             } else {
565                 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_light);
566             }
567         } else {
568             clearCookiesPreference.setIcon(R.drawable.cookies_warning);
569         }
570
571         // Set the clear DOM storage preference icon.
572         if (clearEverything || savedPreferences.getBoolean("clear_dom_storage", true)) {
573             if (darkTheme) {
574                 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_dark);
575             } else {
576                 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_light);
577             }
578         } else {
579             clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
580         }
581
582         // Set the clear form data preference icon if the API < 26.  It has no effect on newer versions of Android.
583         if (Build.VERSION.SDK_INT < 26) {
584             if (clearEverything || savedPreferences.getBoolean("clear_form_data", true)) {
585                 if (darkTheme) {
586                     clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark);
587                 } else {
588                     clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light);
589                 }
590             } else {
591                 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
592             }
593         }
594
595         // Set the clear cache preference icon.
596         if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) {
597             if (darkTheme) {
598                 clearCachePreference.setIcon(R.drawable.cache_cleared_dark);
599             } else {
600                 clearCachePreference.setIcon(R.drawable.cache_cleared_light);
601             }
602         } else {
603             clearCachePreference.setIcon(R.drawable.cache_warning);
604         }
605
606         // Set the swipe to refresh preference icon.
607         if (savedPreferences.getBoolean("swipe_to_refresh", true)) {
608             if (darkTheme) {
609                 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_dark);
610             } else {
611                 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_light);
612             }
613         } else {
614             if (darkTheme) {
615                 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_dark);
616             } else {
617                 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_light);
618             }
619         }
620
621         // Set the scroll app bar preference icon.
622         if (savedPreferences.getBoolean("scroll_app_bar", true)) {
623             if (darkTheme) {
624                 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
625             } else {
626                 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
627             }
628         } else {
629             if (darkTheme) {
630                 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
631             } else {
632                 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
633             }
634         }
635
636         // Set the display additional app bar icons preference icon.
637         if (savedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
638             if (darkTheme) {
639                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_dark);
640             } else {
641                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_light);
642             }
643         } else {
644             if (darkTheme) {
645                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_dark);
646             } else {
647                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_light);
648             }
649         }
650
651         // Set the download with external app preference icon.
652         if (savedPreferences.getBoolean("download_with_external_app", false)) {
653             if (darkTheme) {
654                 downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_dark);
655             } else {
656                 downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_light);
657             }
658         } else {
659             if (darkTheme) {
660                 downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_dark);
661             } else {
662                 downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_light);
663             }
664         }
665
666         // Set the dark theme preference icon.
667         if (savedPreferences.getBoolean("dark_theme", false)) {
668             darkThemePreference.setIcon(R.drawable.theme_dark);
669         } else {
670             darkThemePreference.setIcon(R.drawable.theme_light);
671         }
672
673         // Set the night mode preference icon.
674         if (nightMode) {
675             if (darkTheme) {
676                 nightModePreference.setIcon(R.drawable.night_mode_enabled_dark);
677             } else {
678                 nightModePreference.setIcon(R.drawable.night_mode_enabled_light);
679             }
680         } else {
681             if (darkTheme) {
682                 nightModePreference.setIcon(R.drawable.night_mode_disabled_dark);
683             } else {
684                 nightModePreference.setIcon(R.drawable.night_mode_disabled_light);
685             }
686         }
687
688         // Set the display webpage images preference icon.
689         if (savedPreferences.getBoolean("display_webpage_images", true)) {
690             if (darkTheme) {
691                 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_dark);
692             } else {
693                 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_light);
694             }
695         } else {
696             if (darkTheme) {
697                 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_dark);
698             } else {
699                 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_light);
700             }
701         }
702
703
704         // Listen for preference changes.
705         preferencesListener = (SharedPreferences sharedPreferences, String key) -> {
706             switch (key) {
707                 case "javascript":
708                     // Update the icons and the DOM storage preference status.
709                     if (sharedPreferences.getBoolean("javascript", false)) {  // The JavaScript preference is enabled.
710                         // Update the icon for the JavaScript preference.
711                         javaScriptPreference.setIcon(R.drawable.javascript_enabled);
712
713                         // Update the status of the DOM storage preference.
714                         domStoragePreference.setEnabled(true);
715
716                         // Update the icon for the DOM storage preference.
717                         if (sharedPreferences.getBoolean("dom_storage", false)) {
718                             domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
719                         } else {
720                             if (darkTheme) {
721                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
722                             } else {
723                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
724                             }
725                         }
726                     } else {  // The JavaScript preference is disabled.
727                         // Update the icon for the JavaScript preference.
728                         javaScriptPreference.setIcon(R.drawable.privacy_mode);
729
730                         // Update the status of the DOM storage preference.
731                         domStoragePreference.setEnabled(false);
732
733                         // Set the icon for DOM storage preference to be ghosted.
734                         if (darkTheme) {
735                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_dark);
736                         } else {
737                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_light);
738                         }
739                     }
740                     break;
741
742                 case "first_party_cookies":
743                     // Update the icons for `first_party_cookies` and `third_party_cookies`.
744                     if (sharedPreferences.getBoolean("first_party_cookies", false)) {
745                         // Set the icon for `first_party_cookies`.
746                         firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
747
748                         // Update the icon for `third_party_cookies`.
749                         if (Build.VERSION.SDK_INT >= 21) {
750                             if (sharedPreferences.getBoolean("third_party_cookies", false)) {
751                                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
752                             } else {
753                                 if (darkTheme) {
754                                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
755                                 } else {
756                                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
757                                 }
758                             }
759                         } else {
760                             if (darkTheme) {
761                                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_dark);
762                             } else {
763                                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_light);
764                             }
765                         }
766                     } else {  // `first_party_cookies` is `false`.
767                         // Update the icon for `first_party_cookies`.
768                         if (darkTheme) {
769                             firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
770                         } else {
771                             firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
772                         }
773
774                         // Set the icon for `third_party_cookies` to be ghosted.
775                         if (darkTheme) {
776                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_dark);
777                         } else {
778                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_light);
779                         }
780                     }
781
782                     // Enable `third_party_cookies` if `first_party_cookies` is `true` and API >= 21.
783                     thirdPartyCookiesPreference.setEnabled(sharedPreferences.getBoolean("first_party_cookies", false) && (Build.VERSION.SDK_INT >= 21));
784                     break;
785
786                 case "third_party_cookies":
787                     // Update the icon.
788                     if (sharedPreferences.getBoolean("third_party_cookies", false)) {
789                         thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
790                     } else {
791                         if (darkTheme) {
792                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_dark);
793                         } else {
794                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_light);
795                         }
796                     }
797                     break;
798
799                 case "dom_storage":
800                     // Update the icon.
801                     if (sharedPreferences.getBoolean("dom_storage", false)) {
802                         domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
803                     } else {
804                         if (darkTheme) {
805                             domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
806                         } else {
807                             domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
808                         }
809                     }
810                     break;
811
812                 // Save form data can be removed once the minimum API >= 26.
813                 case "save_form_data":
814                     // Update the icon.
815                     if (sharedPreferences.getBoolean("save_form_data", false)) {
816                         saveFormDataPreference.setIcon(R.drawable.form_data_enabled);
817                     } else {
818                         if (darkTheme) {
819                             saveFormDataPreference.setIcon(R.drawable.form_data_disabled_dark);
820                         } else {
821                             saveFormDataPreference.setIcon(R.drawable.form_data_disabled_light);
822                         }
823                     }
824                     break;
825
826                 case "user_agent":
827                     // Get the new user agent name.
828                     String newUserAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
829
830                     // Get the array position for the new user agent name.
831                     int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName);
832
833                     // Get the translated new user agent name.
834                     String translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition];
835
836                     // Populate the user agent summary.
837                     switch (newUserAgentArrayPosition) {
838                         case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
839                             // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
840                             userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + bareWebView.getSettings().getUserAgentString());
841
842                             // Disable the custom user agent preference.
843                             customUserAgentPreference.setEnabled(false);
844
845                             // Set the custom user agent preference icon according to the theme.
846                             if (darkTheme) {
847                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_dark);
848                             } else {
849                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_light);
850                             }
851                             break;
852
853                         case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
854                             // Set the summary text.
855                             userAgentPreference.setSummary(R.string.custom_user_agent);
856
857                             // Enable the custom user agent preference.
858                             customUserAgentPreference.setEnabled(true);
859
860                             // Set the custom user agent preference icon according to the theme.
861                             if (darkTheme) {
862                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_dark);
863                             } else {
864                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_light);
865                             }
866                             break;
867
868                         default:
869                             // Get the user agent summary from the user agent data array.
870                             userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + userAgentDataArray[newUserAgentArrayPosition]);
871
872                             // Disable the custom user agent preference.
873                             customUserAgentPreference.setEnabled(false);
874
875                             // Set the custom user agent preference icon according to the theme.
876                             if (darkTheme) {
877                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_dark);
878                             } else {
879                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_light);
880                             }
881                     }
882                     break;
883
884                 case "custom_user_agent":
885                     // Set the new custom user agent as the summary text for the preference.
886                     customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
887                     break;
888
889                 case "incognito_mode":
890                     // Update the icon.
891                     if (sharedPreferences.getBoolean("incognito_mode", false)) {
892                         if (darkTheme) {
893                             incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_dark);
894                         } else {
895                             incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_light);
896                         }
897                     } else {
898                         if (darkTheme) {
899                             incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_dark);
900                         } else {
901                             incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_light);
902                         }
903                     }
904                     break;
905
906                 case "do_not_track":
907                     // Update the icon.
908                     if (sharedPreferences.getBoolean("do_not_track", false)) {
909                         if (darkTheme) {
910                             doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_dark);
911                         } else {
912                             doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_light);
913                         }
914                     } else {
915                         if (darkTheme) {
916                             doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_dark);
917                         } else {
918                             doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_light);
919                         }
920                     }
921
922                     break;
923
924                 case "allow_screenshots":
925                     // Update the icon.
926                     if (sharedPreferences.getBoolean("allow_screenshots", false)) {
927                         if (darkTheme) {
928                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_dark);
929                         } else {
930                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_light);
931                         }
932                     } else {
933                         if (darkTheme) {
934                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_dark);
935                         } else {
936                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_light);
937                         }
938                     }
939
940                     // Create an intent to restart Privacy Browser.
941                     Intent allowScreenshotsRestartIntent = getActivity().getParentActivityIntent();
942
943                     // Assert that the intent is not null to remove the lint error below.
944                     assert allowScreenshotsRestartIntent != null;
945
946                     // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
947                     allowScreenshotsRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
948
949                     // Create a handler to restart the activity.
950                     Handler allowScreenshotsRestartHandler = new Handler();
951
952                     // Create a runnable to restart the activity.
953                     Runnable allowScreenshotsRestartRunnable = () -> {
954                         // Restart the activity.
955                         startActivity(allowScreenshotsRestartIntent);
956
957                         // Kill this instance of Privacy Browser.  Otherwise, the app exhibits sporadic behavior after the restart.
958                         System.exit(0);
959                     };
960
961                     // Restart the activity after 100 milliseconds, so that the app has enough time to save the change to the preference.
962                     allowScreenshotsRestartHandler.postDelayed(allowScreenshotsRestartRunnable, 100);
963                     break;
964
965                 case "easylist":
966                     // Update the icon.
967                     if (sharedPreferences.getBoolean("easylist", true)) {
968                         if (darkTheme) {
969                             easyListPreference.setIcon(R.drawable.block_ads_enabled_dark);
970                         } else {
971                             easyListPreference.setIcon(R.drawable.block_ads_enabled_light);
972                         }
973                     } else {
974                         if (darkTheme) {
975                             easyListPreference.setIcon(R.drawable.block_ads_disabled_dark);
976                         } else {
977                             easyListPreference.setIcon(R.drawable.block_ads_disabled_light);
978                         }
979                     }
980                     break;
981
982                 case "easyprivacy":
983                     // Update the icon.
984                     if (sharedPreferences.getBoolean("easyprivacy", true)) {
985                         if (darkTheme) {
986                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
987                         } else {
988                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
989                         }
990                     } else {
991                         if (darkTheme) {
992                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
993                         } else {
994                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
995                         }
996                     }
997                     break;
998
999                 case "fanboys_annoyance_list":
1000                     boolean currentFanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
1001                     boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
1002
1003                     // Update the Fanboy icons.
1004                     if (currentFanboyAnnoyanceList) {  // Fanboy's annoyance list is enabled.
1005                         if (darkTheme) {
1006                             // Update the Fanboy's annoyance list icon.
1007                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_dark);
1008
1009                             // Update the Fanboy's social blocking list icon.
1010                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_dark);
1011                         } else {
1012                             // Update the Fanboy's annoyance list icon.
1013                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_light);
1014
1015                             // Update the Fanboy's social blocking list icon.
1016                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_light);
1017                         }
1018                     } else {  // Fanboy's annoyance list is disabled.
1019                         if (darkTheme) {
1020                             // Update the Fanboy's annoyance list icon.
1021                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_dark);
1022
1023                             // Update the Fanboy's social blocking list icon.
1024                             if (currentFanboySocialBlockingList) {
1025                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_dark);
1026                             } else {
1027                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_dark);
1028                             }
1029                         } else {
1030                             // Update the Fanboy's annoyance list icon.
1031                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_light);
1032
1033                             // Update the Fanboy's social blocking list icon.
1034                             if (currentFanboySocialBlockingList) {
1035                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_light);
1036                             } else {
1037                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_light);
1038                             }
1039                         }
1040                     }
1041
1042                     // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled.
1043                     fanboySocialBlockingListPreference.setEnabled(!currentFanboyAnnoyanceList);
1044                     break;
1045
1046                 case "fanboys_social_blocking_list":
1047                     // Update the icon.
1048                     if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) {
1049                         if (darkTheme) {
1050                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_dark);
1051                         } else {
1052                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_light);
1053                         }
1054                     } else {
1055                         if (darkTheme) {
1056                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_dark);
1057                         } else {
1058                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_light);
1059                         }
1060                     }
1061                     break;
1062
1063                 case "ultraprivacy":
1064                     // Update the icon.
1065                     if (sharedPreferences.getBoolean("ultraprivacy", true)) {
1066                         if (darkTheme) {
1067                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_dark);
1068                         } else {
1069                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_light);
1070                         }
1071                     } else {
1072                         if (darkTheme) {
1073                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_dark);
1074                         } else {
1075                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_light);
1076                         }
1077                     }
1078                     break;
1079
1080                 case "block_all_third_party_requests":
1081                     // Update the icon.
1082                     if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
1083                         if (darkTheme) {
1084                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_dark);
1085                         } else {
1086                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_light);
1087                         }
1088                     } else {
1089                         if (darkTheme) {
1090                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_dark);
1091                         } else {
1092                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_light);
1093                         }
1094                     }
1095                     break;
1096
1097                 case "proxy_through_orbot":
1098                     // Get current settings.
1099                     boolean currentProxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false);
1100                     String currentTorSearchString = sharedPreferences.getString("tor_search", getString(R.string.tor_search_default_value));
1101
1102                     // Enable the Tor custom URL search option only if `currentProxyThroughOrbot` is true and the search is set to `Custom URL`.
1103                     torSearchCustomURLPreference.setEnabled(currentProxyThroughOrbot && currentTorSearchString.equals("Custom URL"));
1104
1105                     // Update the icons.
1106                     if (currentProxyThroughOrbot) {
1107                         // Set the Tor icons according to the theme.
1108                         if (darkTheme) {
1109                             proxyThroughOrbotPreference.setIcon(R.drawable.orbot_enabled_dark);
1110                             torHomepagePreference.setIcon(R.drawable.home_enabled_dark);
1111                             torSearchPreference.setIcon(R.drawable.search_enabled_dark);
1112
1113                             // Set the `torSearchCustomURLPreference` icon.
1114                             if (torSearchCustomURLPreference.isEnabled()) {
1115                                 torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
1116                             } else {
1117                                 torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
1118                             }
1119                         } else {
1120                             proxyThroughOrbotPreference.setIcon(R.drawable.orbot_enabled_light);
1121                             torHomepagePreference.setIcon(R.drawable.home_enabled_light);
1122                             torSearchPreference.setIcon(R.drawable.search_enabled_light);
1123
1124                             // Set the `torSearchCustomURLPreference` icon.
1125                             if (torSearchCustomURLPreference.isEnabled()) {
1126                                 torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
1127                             } else {
1128                                 torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
1129                             }
1130                         }
1131                     } else {  // Proxy through Orbot is disabled.
1132                         if (darkTheme) {
1133                             proxyThroughOrbotPreference.setIcon(R.drawable.orbot_disabled_dark);
1134                             torHomepagePreference.setIcon(R.drawable.home_ghosted_dark);
1135                             torSearchPreference.setIcon(R.drawable.search_ghosted_dark);
1136                             torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
1137                         } else {
1138                             proxyThroughOrbotPreference.setIcon(R.drawable.orbot_disabled_light);
1139                             torHomepagePreference.setIcon(R.drawable.home_ghosted_light);
1140                             torSearchPreference.setIcon(R.drawable.search_ghosted_light);
1141                             torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
1142                         }
1143                     }
1144                     break;
1145
1146                 case "tor_homepage":
1147                     // Set the new tor homepage URL as the summary text for the `tor_homepage` preference.  The default is Searx:  `http://ulrn6sryqaifefld.onion/`.
1148                     torHomepagePreference.setSummary(sharedPreferences.getString("tor_homepage", getString(R.string.tor_homepage_default_value)));
1149                     break;
1150
1151                 case "tor_search":
1152                     // Get the present search string.
1153                     String presentTorSearchString = sharedPreferences.getString("tor_search", getString(R.string.tor_search_default_value));
1154
1155                     // Update the preferences.
1156                     if (presentTorSearchString.equals("Custom URL")) {
1157                         // Use `R.string.custom_url`, which is translated, as the summary instead of the array value, which isn't.
1158                         torSearchPreference.setSummary(R.string.custom_url);
1159
1160                         // Enable `torSearchCustomURLPreference`.
1161                         torSearchCustomURLPreference.setEnabled(true);
1162
1163                         // Update the `torSearchCustomURLPreference` icon.
1164                         if (darkTheme) {
1165                             torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
1166                         } else {
1167                             torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
1168                         }
1169                     } else {
1170                         // Set the array value as the summary text.
1171                         torSearchPreference.setSummary(presentTorSearchString);
1172
1173                         // Disable `torSearchCustomURLPreference`.
1174                         torSearchCustomURLPreference.setEnabled(false);
1175
1176                         // Update the `torSearchCustomURLPreference` icon.
1177                         if (darkTheme) {
1178                             torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
1179                         } else {
1180                             torSearchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
1181                         }
1182                     }
1183                     break;
1184
1185                 case "tor_search_custom_url":
1186                     // Set the summary text for `tor_search_custom_url`.
1187                     torSearchCustomURLPreference.setSummary(sharedPreferences.getString("tor_search_custom_url", getString(R.string.tor_search_custom_url_default_value)));
1188                     break;
1189
1190                 case "search":
1191                     // Store the new search string.
1192                     String newSearchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
1193
1194                     // Update `searchPreference` and `searchCustomURLPreference`.
1195                     if (newSearchString.equals("Custom URL")) {  // `Custom URL` is selected.
1196                         // Set the summary text to `R.string.custom_url`, which is translated.
1197                         searchPreference.setSummary(R.string.custom_url);
1198
1199                         // Enable `searchCustomURLPreference`.
1200                         searchCustomURLPreference.setEnabled(true);
1201
1202                         // Set the `searchCustomURLPreference` according to the theme.
1203                         if (darkTheme) {
1204                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_dark);
1205                         } else {
1206                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_light);
1207                         }
1208                     } else {  // `Custom URL` is not selected.
1209                         // Set the summary text to `newSearchString`.
1210                         searchPreference.setSummary(newSearchString);
1211
1212                         // Disable `searchCustomURLPreference`.
1213                         searchCustomURLPreference.setEnabled(false);
1214
1215                         // Set the `searchCustomURLPreference` according to the theme.
1216                         if (darkTheme) {
1217                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_dark);
1218                         } else {
1219                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_light);
1220                         }
1221                     }
1222                     break;
1223
1224                 case "search_custom_url":
1225                     // Set the new custom search URL as the summary text for `search_custom_url`.  The default is `""`.
1226                     searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
1227                     break;
1228
1229                 case "full_screen_browsing_mode":
1230                     if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) {  // Full screen browsing is enabled.
1231                         // Set the full screen browsing mode preference icon according to the theme.
1232                         if (darkTheme) {
1233                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_dark);
1234                         } else {
1235                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_light);
1236                         }
1237
1238                         // Set the hide app bar preference icon.
1239                         if (sharedPreferences.getBoolean("hide_app_bar", true)) {  //  Hide app bar is enabled.
1240                             // Set the icon according to the theme.
1241                             if (darkTheme) {
1242                                 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
1243                             } else {
1244                                 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
1245                             }
1246                         } else {  // Hide app bar is disabled.
1247                             // Set the icon according to the theme.
1248                             if (darkTheme) {
1249                                 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
1250                             } else {
1251                                 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
1252                             }
1253                         }
1254                     } else {  // Full screen browsing is disabled.
1255                         // Update the icons according to the theme.
1256                         if (darkTheme) {
1257                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_dark);
1258                             hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_dark);
1259                         } else {
1260                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_light);
1261                             hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_light);
1262                         }
1263                     }
1264                     break;
1265
1266                 case "hide_app_bar":
1267                     // Update the icon.
1268                     if (sharedPreferences.getBoolean("hide_app_bar", true)) {  // Hide app bar is enabled.
1269                         // Set the icon according to the theme.
1270                         if (darkTheme) {
1271                             hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
1272                         } else {
1273                             hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
1274                         }
1275                     } else {  // Hide app bar is disabled.
1276                         // Set the icon according to the theme.
1277                         if (darkTheme) {
1278                             hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
1279                         } else {
1280                             hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
1281                         }
1282                     }
1283                     break;
1284
1285                 case "clear_everything":
1286                     // Store the new `clear_everything` status
1287                     boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true);
1288
1289                     // Update the status of the `Clear and Exit` preferences.
1290                     clearCookiesPreference.setEnabled(!newClearEverythingBoolean);
1291                     clearDomStoragePreference.setEnabled(!newClearEverythingBoolean);
1292                     clearFormDataPreference.setEnabled(!newClearEverythingBoolean);  // This line can be removed once the minimum API >= 26.
1293                     clearCachePreference.setEnabled(!newClearEverythingBoolean);
1294
1295                     // Update the `clearEverythingPreference` icon.
1296                     if (newClearEverythingBoolean) {
1297                         if (darkTheme) {
1298                             clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_dark);
1299                         } else {
1300                             clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_light);
1301                         }
1302                     } else {
1303                         clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
1304                     }
1305
1306                     // Update the `clearCookiesPreference` icon.
1307                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) {
1308                         if (darkTheme) {
1309                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_dark);
1310                         } else {
1311                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_light);
1312                         }
1313                     } else {
1314                         clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1315                     }
1316
1317                     // Update the `clearDomStoragePreference` icon.
1318                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) {
1319                         if (darkTheme) {
1320                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_dark);
1321                         } else {
1322                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_light);
1323                         }
1324                     } else {
1325                         clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1326                     }
1327
1328                     // Update the clear form data preference icon if the API < 26.
1329                     if (Build.VERSION.SDK_INT < 26) {
1330                         if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) {
1331                             if (darkTheme) {
1332                                 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark);
1333                             } else {
1334                                 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light);
1335                             }
1336                         } else {
1337                             clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1338                         }
1339                     }
1340
1341                     // Update the `clearCachePreference` icon.
1342                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) {
1343                         if (darkTheme) {
1344                             clearCachePreference.setIcon(R.drawable.cache_cleared_dark);
1345                         } else {
1346                             clearCachePreference.setIcon(R.drawable.cache_cleared_light);
1347                         }
1348                     } else {
1349                         clearCachePreference.setIcon(R.drawable.cache_warning);
1350                     }
1351                     break;
1352
1353                 case "clear_cookies":
1354                     // Update the icon.
1355                     if (sharedPreferences.getBoolean("clear_cookies", true)) {
1356                         if (darkTheme) {
1357                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_dark);
1358                         } else {
1359                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_light);
1360                         }
1361                     } else {
1362                         clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1363                     }
1364                     break;
1365
1366                 case "clear_dom_storage":
1367                     // Update the icon.
1368                     if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
1369                         if (darkTheme) {
1370                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_dark);
1371                         } else {
1372                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_light);
1373                         }
1374                     } else {
1375                         clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1376                     }
1377                     break;
1378
1379                 // This section can be removed once the minimum API >= 26.
1380                 case "clear_form_data":
1381                     // Update the icon.
1382                     if (sharedPreferences.getBoolean("clear_form_data", true)) {
1383                         if (darkTheme) {
1384                             clearFormDataPreference.setIcon(R.drawable.form_data_cleared_dark);
1385                         } else {
1386                             clearFormDataPreference.setIcon(R.drawable.form_data_cleared_light);
1387                         }
1388                     } else {
1389                         clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1390                     }
1391                     break;
1392
1393                 case "clear_cache":
1394                     // Update the icon.
1395                     if (sharedPreferences.getBoolean("clear_cache", true)) {
1396                         if (darkTheme) {
1397                             clearCachePreference.setIcon(R.drawable.cache_cleared_dark);
1398                         } else {
1399                             clearCachePreference.setIcon(R.drawable.cache_cleared_light);
1400                         }
1401                     } else {
1402                         clearCachePreference.setIcon(R.drawable.cache_warning);
1403                     }
1404                     break;
1405
1406                 case "homepage":
1407                     // Set the new homepage URL as the summary text for the Homepage preference.
1408                     homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
1409                     break;
1410
1411                 case "font_size":
1412                     // Update the font size summary text.
1413                     fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%%");
1414                     break;
1415
1416                 case "swipe_to_refresh":
1417                     // Update the icon.
1418                     if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
1419                         if (darkTheme) {
1420                             swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_dark);
1421                         } else {
1422                             swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_light);
1423                         }
1424                     } else {
1425                         if (darkTheme) {
1426                             swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_dark);
1427                         } else {
1428                             swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_light);
1429                         }
1430                     }
1431                     break;
1432
1433                 case "scroll_app_bar":
1434                     // Update the icon.
1435                     if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
1436                         if (darkTheme) {
1437                             scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_dark);
1438                         } else {
1439                             scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_light);
1440                         }
1441                     } else {
1442                         if (darkTheme) {
1443                             scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_dark);
1444                         } else {
1445                             scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_light);
1446                         }
1447                     }
1448                     break;
1449
1450                 case "display_additional_app_bar_icons":
1451                     // Update the icon.
1452                     if (sharedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
1453                         if (darkTheme) {
1454                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_dark);
1455                         } else {
1456                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_light);
1457                         }
1458                     } else {
1459                         if (darkTheme) {
1460                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_dark);
1461                         } else {
1462                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_light);
1463                         }
1464                     }
1465                     break;
1466
1467                 case "download_with_external_app":
1468                     // Update the icon.
1469                     if (sharedPreferences.getBoolean("download_with_external_app", false)) {
1470                         if (darkTheme) {
1471                             downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_dark);
1472                         } else {
1473                             downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_enabled_light);
1474                         }
1475                     } else {
1476                         if (darkTheme) {
1477                             downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_dark);
1478                         } else {
1479                             downloadWithExternalAppPreference.setIcon(R.drawable.open_with_external_app_disabled_light);
1480                         }
1481                     }
1482                     break;
1483
1484                 case "dark_theme":
1485                     // Update the icon.
1486                     if (sharedPreferences.getBoolean("dark_theme", false)) {
1487                         darkThemePreference.setIcon(R.drawable.theme_dark);
1488                     } else {
1489                         darkThemePreference.setIcon(R.drawable.theme_light);
1490                     }
1491
1492                     // Create an intent to restart Privacy Browser.
1493                     Intent changeThemeRestartIntent = getActivity().getParentActivityIntent();
1494
1495                     // Assert that the intent is not null to remove the lint error below.
1496                     assert changeThemeRestartIntent != null;
1497
1498                     // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
1499                     changeThemeRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
1500
1501                     // Create a handler to restart the activity.
1502                     Handler changeThemeRestartHandler = new Handler();
1503
1504                     // Create a runnable to restart the activity.
1505                     Runnable changeThemeRestartRunnable = () -> {
1506                         // Restart the activity.
1507                         startActivity(changeThemeRestartIntent);
1508
1509                         // Kill this instance of Privacy Browser.  Otherwise, the app exhibits sporadic behavior after the restart.
1510                         System.exit(0);
1511                     };
1512
1513                     // Restart the activity after 100 milliseconds, so that the app has enought time to save the change to the preference.
1514                     changeThemeRestartHandler.postDelayed(changeThemeRestartRunnable, 100);
1515                     break;
1516
1517                 case "night_mode":
1518                     // Store the current night mode status.
1519                     boolean currentNightModeBoolean = sharedPreferences.getBoolean("night_mode", false);
1520                     boolean currentJavaScriptBoolean = sharedPreferences.getBoolean("javascript", false);
1521
1522                     // Update the icon.
1523                     if (currentNightModeBoolean) {
1524                         if (darkTheme) {
1525                             nightModePreference.setIcon(R.drawable.night_mode_enabled_dark);
1526                         } else {
1527                             nightModePreference.setIcon(R.drawable.night_mode_enabled_light);
1528                         }
1529                     } else {
1530                         if (darkTheme) {
1531                             nightModePreference.setIcon(R.drawable.night_mode_disabled_dark);
1532                         } else {
1533                             nightModePreference.setIcon(R.drawable.night_mode_disabled_light);
1534                         }
1535                     }
1536
1537                     // Update the status of `javaScriptPreference` and `domStoragePreference`.
1538                     javaScriptPreference.setEnabled(!currentNightModeBoolean);
1539                     domStoragePreference.setEnabled(currentNightModeBoolean || currentJavaScriptBoolean);
1540
1541                     // Update the `javaScriptPreference` icon.
1542                     if (currentNightModeBoolean || currentJavaScriptBoolean) {
1543                         javaScriptPreference.setIcon(R.drawable.javascript_enabled);
1544                     } else {
1545                         javaScriptPreference.setIcon(R.drawable.privacy_mode);
1546                     }
1547
1548                     // Update the DOM storage preference icon.
1549                     if (currentNightModeBoolean || currentJavaScriptBoolean) {  // The preference is enabled.
1550                         if (sharedPreferences.getBoolean("dom_storage", false)) {  // DOM storage is enabled.
1551                             domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1552                         } else {  // DOM storage is disabled.
1553                             if (darkTheme) {
1554                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_dark);
1555                             } else {
1556                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_light);
1557                             }
1558                         }
1559                     } else {  // The preference is disabled.  The icon should be ghosted.
1560                         if (darkTheme) {
1561                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_dark);
1562                         } else {
1563                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_light);
1564                         }
1565                     }
1566                     break;
1567
1568                 case "display_webpage_images":
1569                     if (sharedPreferences.getBoolean("display_webpage_images", true)) {
1570                         // Update the icon.
1571                         if (darkTheme) {
1572                             displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_dark);
1573                         } else {
1574                             displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_light);
1575                         }
1576                     } else {
1577                         // Update the icon.
1578                         if (darkTheme) {
1579                             displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_dark);
1580                         } else {
1581                             displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_light);
1582                         }
1583                     }
1584                     break;
1585             }
1586         };
1587
1588         // Register the listener.
1589         savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);
1590     }
1591
1592     // It is necessary to re-register the listener on every resume or it will randomly stop working because apps can be paused and resumed at any time, even while running in the foreground.
1593     @Override
1594     public void onPause() {
1595         super.onPause();
1596         savedPreferences.unregisterOnSharedPreferenceChangeListener(preferencesListener);
1597     }
1598
1599     @Override
1600     public void onResume() {
1601         super.onResume();
1602         savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);
1603     }
1604 }