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