Clear the logcat on exit. https://redmine.stoutner.com/issues/382
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / SettingsFragment.java
1 /*
2  * Copyright © 2016-2020 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.app.Activity;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.content.SharedPreferences;
27 import android.content.res.Configuration;
28 import android.content.res.Resources;
29 import android.os.Build;
30 import android.os.Bundle;
31 import android.os.Handler;
32 import android.view.LayoutInflater;
33 import android.view.View;
34 import android.webkit.WebView;
35 import android.widget.ArrayAdapter;
36
37 import androidx.appcompat.app.AppCompatDelegate;
38 import androidx.preference.Preference;
39 import androidx.preference.PreferenceCategory;
40 import androidx.preference.PreferenceFragmentCompat;
41
42 import com.stoutner.privacybrowser.R;
43 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
44 import com.stoutner.privacybrowser.helpers.DownloadLocationHelper;
45 import com.stoutner.privacybrowser.helpers.ProxyHelper;
46
47 public class SettingsFragment extends PreferenceFragmentCompat {
48     // Define the class variables.
49     private SharedPreferences.OnSharedPreferenceChangeListener preferencesListener;
50     private SharedPreferences savedPreferences;
51     private int currentThemeStatus;
52
53     @Override
54     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
55         // Load the preferences from the XML file.
56         setPreferencesFromResource(R.xml.preferences, rootKey);
57
58         // Get a handle for the activity.
59         Activity activity = getActivity();
60
61         // Remove the lint warning below that `getApplicationContext()` might produce a null pointer exception.
62         assert activity != null;
63
64         // Get a handle for the context and the resources.
65         Context context = activity.getApplicationContext();
66         Resources resources = getResources();
67
68         // Get the current theme status.
69         currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
70
71         // Initialize savedPreferences.
72         savedPreferences = getPreferenceScreen().getSharedPreferences();
73
74         // Get handles for the preferences.
75         Preference javaScriptPreference = findPreference("javascript");
76         Preference firstPartyCookiesPreference = findPreference("first_party_cookies");
77         Preference thirdPartyCookiesPreference = findPreference("third_party_cookies");
78         Preference domStoragePreference = findPreference("dom_storage");
79         Preference formDataPreference = findPreference("save_form_data");  // The form data preference can be removed once the minimum API >= 26.
80         Preference userAgentPreference = findPreference("user_agent");
81         Preference customUserAgentPreference = findPreference("custom_user_agent");
82         Preference incognitoModePreference = findPreference("incognito_mode");
83         Preference doNotTrackPreference = findPreference("do_not_track");
84         Preference allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key));
85         Preference easyListPreference = findPreference("easylist");
86         Preference easyPrivacyPreference = findPreference("easyprivacy");
87         Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
88         Preference fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
89         Preference ultraListPreference = findPreference("ultralist");
90         Preference ultraPrivacyPreference = findPreference("ultraprivacy");
91         Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
92         Preference googleAnalyticsPreference = findPreference("google_analytics");
93         Preference facebookClickIdsPreference = findPreference("facebook_click_ids");
94         Preference twitterAmpRedirectsPreference = findPreference("twitter_amp_redirects");
95         Preference searchPreference = findPreference("search");
96         Preference searchCustomURLPreference = findPreference("search_custom_url");
97         Preference proxyPreference = findPreference("proxy");
98         Preference proxyCustomUrlPreference = findPreference("proxy_custom_url");
99         Preference fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
100         Preference hideAppBarPreference = findPreference("hide_app_bar");
101         Preference clearEverythingPreference = findPreference("clear_everything");
102         Preference clearCookiesPreference = findPreference("clear_cookies");
103         Preference clearDomStoragePreference = findPreference("clear_dom_storage");
104         Preference clearFormDataPreference = findPreference("clear_form_data");  // The clear form data preference can be removed once the minimum API >= 26.
105         Preference clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key));
106         Preference clearCachePreference = findPreference("clear_cache");
107         Preference homepagePreference = findPreference("homepage");
108         Preference downloadLocationPreference = findPreference("download_location");
109         Preference downloadCustomLocationPreference = findPreference("download_custom_location");
110         Preference fontSizePreference = findPreference("font_size");
111         Preference openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
112         Preference swipeToRefreshPreference = findPreference("swipe_to_refresh");
113         Preference scrollAppBarPreference = findPreference("scroll_app_bar");
114         Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons");
115         Preference appThemePreference = findPreference("app_theme");
116         Preference webViewThemePreference = findPreference("webview_theme");
117         Preference wideViewportPreference = findPreference("wide_viewport");
118         Preference displayWebpageImagesPreference = findPreference("display_webpage_images");
119
120         // Remove the lint warnings below that the preferences might be null.
121         assert javaScriptPreference != null;
122         assert firstPartyCookiesPreference != null;
123         assert thirdPartyCookiesPreference != null;
124         assert domStoragePreference != null;
125         assert formDataPreference != null;
126         assert userAgentPreference != null;
127         assert customUserAgentPreference != null;
128         assert incognitoModePreference != null;
129         assert doNotTrackPreference != null;
130         assert allowScreenshotsPreference != null;
131         assert easyListPreference != null;
132         assert easyPrivacyPreference != null;
133         assert fanboyAnnoyanceListPreference != null;
134         assert fanboySocialBlockingListPreference != null;
135         assert ultraListPreference != null;
136         assert ultraPrivacyPreference != null;
137         assert blockAllThirdPartyRequestsPreference != null;
138         assert googleAnalyticsPreference != null;
139         assert facebookClickIdsPreference != null;
140         assert twitterAmpRedirectsPreference != null;
141         assert searchPreference != null;
142         assert searchCustomURLPreference != null;
143         assert proxyPreference != null;
144         assert proxyCustomUrlPreference != null;
145         assert fullScreenBrowsingModePreference != null;
146         assert hideAppBarPreference != null;
147         assert clearEverythingPreference != null;
148         assert clearCookiesPreference != null;
149         assert clearDomStoragePreference != null;
150         assert clearFormDataPreference != null;
151         assert clearLogcatPreference != null;
152         assert clearCachePreference != null;
153         assert homepagePreference != null;
154         assert downloadLocationPreference != null;
155         assert downloadCustomLocationPreference != null;
156         assert fontSizePreference != null;
157         assert openIntentsInNewTabPreference != null;
158         assert swipeToRefreshPreference != null;
159         assert scrollAppBarPreference != null;
160         assert displayAdditionalAppBarIconsPreference != null;
161         assert appThemePreference != null;
162         assert webViewThemePreference != null;
163         assert wideViewportPreference != null;
164         assert displayWebpageImagesPreference != null;
165
166         // Set the preference dependencies.
167         hideAppBarPreference.setDependency("full_screen_browsing_mode");
168         domStoragePreference.setDependency("javascript");
169
170         // Get strings from the preferences.
171         String userAgentName = savedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
172         String searchString = savedPreferences.getString("search", getString(R.string.search_default_value));
173         String proxyString = savedPreferences.getString("proxy", getString(R.string.proxy_default_value));
174         String downloadLocationString = savedPreferences.getString("download_location", getString(R.string.download_location_default_value));
175
176         // Get booleans that are used in multiple places from the preferences.
177         boolean javaScriptEnabled = savedPreferences.getBoolean("javascript", false);
178         boolean firstPartyCookiesEnabled = savedPreferences.getBoolean("first_party_cookies", false);
179         boolean fanboyAnnoyanceListEnabled = savedPreferences.getBoolean("fanboys_annoyance_list", true);
180         boolean fanboySocialBlockingEnabled = savedPreferences.getBoolean("fanboys_social_blocking_list", true);
181         boolean fullScreenBrowsingMode = savedPreferences.getBoolean("full_screen_browsing_mode", false);
182         boolean clearEverything = savedPreferences.getBoolean("clear_everything", true);
183
184         // Only enable the third-party cookies preference if first-party cookies are enabled and API >= 21.
185         thirdPartyCookiesPreference.setEnabled(firstPartyCookiesEnabled && (Build.VERSION.SDK_INT >= 21));
186
187         // Remove the form data preferences if the API is >= 26 as they no longer do anything.
188         if (Build.VERSION.SDK_INT >= 26) {
189             // Get handles for the categories.
190             PreferenceCategory privacyCategory = findPreference("privacy");
191             PreferenceCategory clearAndExitCategory = findPreference("clear_and_exit");
192
193             // Remove the incorrect lint warnings below that the preference categories might be null.
194             assert privacyCategory != null;
195             assert clearAndExitCategory != null;
196
197             // Remove the form data preferences.
198             privacyCategory.removePreference(formDataPreference);
199             clearAndExitCategory.removePreference(clearFormDataPreference);
200         }
201
202         // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled.
203         fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled);
204
205
206         // Inflate a WebView to get the default user agent.
207         LayoutInflater inflater = getActivity().getLayoutInflater();
208
209         // `@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.
210         @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
211
212         // Get a handle for a bare WebView.
213         WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
214
215         // Get the user agent arrays.
216         ArrayAdapter<CharSequence> userAgentNamesArray = ArrayAdapter.createFromResource(context, R.array.user_agent_names, R.layout.spinner_item);
217         String[] translatedUserAgentNamesArray = resources.getStringArray(R.array.translated_user_agent_names);
218         String[] userAgentDataArray = resources.getStringArray(R.array.user_agent_data);
219
220         // Get the array position of the user agent name.
221         int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
222
223         // Populate the user agent summary.
224         switch (userAgentArrayPosition) {
225             case MainWebViewActivity.UNRECOGNIZED_USER_AGENT:  // The user agent name is not on the canonical list.
226                 // 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.
227                 userAgentPreference.setSummary(userAgentName);
228                 break;
229
230             case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
231                 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
232                 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + bareWebView.getSettings().getUserAgentString());
233                 break;
234
235             case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
236                 // Set the summary text.
237                 userAgentPreference.setSummary(R.string.custom_user_agent);
238                 break;
239
240             default:
241                 // Get the user agent summary from the user agent data array.
242                 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + userAgentDataArray[userAgentArrayPosition]);
243         }
244
245         // Set the summary text for the custom user agent preference.
246         customUserAgentPreference.setSummary(savedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
247
248         // Only enable the custom user agent preference if the user agent is set to `Custom`.
249         customUserAgentPreference.setEnabled(userAgentPreference.getSummary().equals(getString(R.string.custom_user_agent)));
250
251
252         // Set the search URL as the summary text for the search preference when the preference screen is loaded.
253         if (searchString.equals("Custom URL")) {
254             // Use R.string.custom_url, which will be translated, instead of the array value, which will not.
255             searchPreference.setSummary(R.string.custom_url);
256         } else {
257             // Set the array value as the summary text.
258             searchPreference.setSummary(searchString);
259         }
260
261         // Set the summary text for the search custom URL (the default is `""`).
262         searchCustomURLPreference.setSummary(savedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
263
264         // Only enable the search custom URL preference if the search is set to `Custom URL`.
265         searchCustomURLPreference.setEnabled(searchString.equals("Custom URL"));
266
267
268         // Set the summary text for the proxy preference when the preference screen is loaded.
269         switch (proxyString) {
270             case ProxyHelper.NONE:
271                 proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
272                 break;
273
274             case ProxyHelper.TOR:
275                 if (Build.VERSION.SDK_INT == 19) {  // Proxying through SOCKS doesn't work on Android KitKat.
276                     proxyPreference.setSummary(getString(R.string.tor_enabled_kitkat));
277                 } else {
278                     proxyPreference.setSummary(getString(R.string.tor_enabled));
279                 }
280                 break;
281
282             case ProxyHelper.I2P:
283                 proxyPreference.setSummary(getString(R.string.i2p_enabled));
284                 break;
285
286             case ProxyHelper.CUSTOM:
287                 proxyPreference.setSummary(getString(R.string.custom_proxy));
288                 break;
289         }
290
291         // Set the summary text for the custom proxy URL.
292         proxyCustomUrlPreference.setSummary(savedPreferences.getString("proxy_custom_url", getString(R.string.proxy_custom_url_default_value)));
293
294         // Only enable the custom proxy URL if a custom proxy is selected.
295         proxyCustomUrlPreference.setEnabled(proxyString.equals("Custom"));
296
297
298         // Set the status of the clear and exit preferences.
299         clearCookiesPreference.setEnabled(!clearEverything);
300         clearDomStoragePreference.setEnabled(!clearEverything);
301         clearFormDataPreference.setEnabled(!clearEverything);  // The form data line can be removed once the minimum API is >= 26.
302         clearLogcatPreference.setEnabled(!clearEverything);
303         clearCachePreference.setEnabled(!clearEverything);
304
305
306         // Set the homepage URL as the summary text for the homepage preference.
307         homepagePreference.setSummary(savedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
308
309
310         // Get the download location string arrays.
311         String[] downloadLocationEntriesStringArray = resources.getStringArray(R.array.download_location_entries);
312         String[] downloadLocationEntryValuesStringArray = resources.getStringArray(R.array.download_location_entry_values);
313
314         // Instantiate the download location helper.
315         DownloadLocationHelper downloadLocationHelper = new DownloadLocationHelper();
316
317         // Check to see if a download custom location is selected.
318         if (downloadLocationString.equals(downloadLocationEntryValuesStringArray[3])) {  // A download custom location is selected.
319             // Set the download location summary text to be `Custom`.
320             downloadLocationPreference.setSummary(downloadLocationEntriesStringArray[3]);
321         } else {  // A custom download location is not selected.
322             // Set the download location summary text to be the download location.
323             downloadLocationPreference.setSummary(downloadLocationHelper.getDownloadLocation(context));
324
325             // Disable the download custom location preference.
326             downloadCustomLocationPreference.setEnabled(false);
327         }
328
329         // Set the summary text for the download custom location (the default is `"`).
330         downloadCustomLocationPreference.setSummary(savedPreferences.getString("download_custom_location", getString(R.string.download_custom_location_default_value)));
331
332
333         // Set the font size as the summary text for the preference.
334         fontSizePreference.setSummary(savedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
335
336
337         // Get the app theme string arrays.
338         String[] appThemeEntriesStringArray = resources.getStringArray(R.array.app_theme_entries);
339         String[] appThemeEntryValuesStringArray = resources.getStringArray(R.array.app_theme_entry_values);
340
341         // Get the current app theme.
342         String currentAppTheme = savedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
343
344         // Define an app theme entry number.
345         int appThemeEntryNumber;
346
347         // Get the app theme entry number that matches the current app theme.  A switch statement cannot be used because the theme entry values string array is not a compile time constant.
348         if (currentAppTheme.equals(appThemeEntryValuesStringArray[1])) {  // The light theme is selected.
349             // Store the app theme entry number.
350             appThemeEntryNumber = 1;
351         } else if (currentAppTheme.equals(appThemeEntryValuesStringArray[2])) {  // The dark theme is selected.
352             // Store the app theme entry number.
353             appThemeEntryNumber = 2;
354         } else {  // The system default theme is selected.
355             // Store the app theme entry number.
356             appThemeEntryNumber = 0;
357         }
358
359         // Set the current theme as the summary text for the preference.
360         appThemePreference.setSummary(appThemeEntriesStringArray[appThemeEntryNumber]);
361
362
363         // Get the WebView theme string arrays.
364         String[] webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries);
365         String[] webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values);
366
367         // Get the current WebView theme.
368         String currentWebViewTheme = savedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
369
370         // Define a WebView theme entry number.
371         int webViewThemeEntryNumber;
372
373         // Get the WebView theme entry number that matches the current WebView theme.  A switch statement cannot be used because the WebView theme entry values string array is not a compile time constant.
374         if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[1])) {  // The light theme is selected.
375             // Store the WebView theme entry number.
376             webViewThemeEntryNumber = 1;
377         } else if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) {  // The dark theme is selected.
378             // Store the WebView theme entry number.
379             webViewThemeEntryNumber = 2;
380         } else {  // The system default theme is selected.
381             // Store the WebView theme entry number.
382             webViewThemeEntryNumber = 0;
383         }
384
385         // Set the visibility of the WebView theme preference.
386         if (Build.VERSION.SDK_INT < 21) {  // The device is running API 19.
387             // Get a handle for the general category.
388             PreferenceCategory generalCategory = findPreference("general");
389
390             // Remove the incorrect lint warning below that the general preference category might be null.
391             assert generalCategory != null;
392
393             // Remove the WebView theme preference.
394             generalCategory.removePreference(webViewThemePreference);
395         } else {  // The device is running API >= 21
396             // Set the current theme as the summary text for the preference.
397             webViewThemePreference.setSummary(webViewThemeEntriesStringArray[webViewThemeEntryNumber]);
398         }
399
400
401         // Set the JavaScript icon.
402         if (javaScriptEnabled) {
403             javaScriptPreference.setIcon(R.drawable.javascript_enabled);
404         } else {
405             javaScriptPreference.setIcon(R.drawable.privacy_mode);
406         }
407
408         // Set the first-party cookies icon.
409         if (firstPartyCookiesEnabled) {
410             firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
411         } else {
412             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
413                 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
414             } else {
415                 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
416             }
417         }
418
419         // Set the third party cookies icon.
420         if (firstPartyCookiesEnabled && Build.VERSION.SDK_INT >= 21) {
421             if (savedPreferences.getBoolean("third_party_cookies", false)) {
422                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
423             } else {
424                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
425                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
426                 } else {
427                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
428                 }
429             }
430         } else {
431             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
432                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
433             } else {
434                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
435             }
436         }
437
438         // Set the DOM storage icon.
439         if (javaScriptEnabled) {  // The preference is enabled.
440             if (savedPreferences.getBoolean("dom_storage", false)) {  // DOM storage is enabled.
441                 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
442             } else {  // DOM storage is disabled.
443                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
444                     domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
445                 } else {
446                     domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
447                 }
448             }
449         } else {  // The preference is disabled.  The icon should be ghosted.
450             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
451                 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
452             } else {
453                 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
454             }
455         }
456
457         // Set the save form data icon if API < 26.  Save form data has no effect on API >= 26.
458         if (Build.VERSION.SDK_INT < 26) {
459             if (savedPreferences.getBoolean("save_form_data", false)) {
460                 formDataPreference.setIcon(R.drawable.form_data_enabled);
461             } else {
462                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
463                     formDataPreference.setIcon(R.drawable.form_data_disabled_night);
464                 } else {
465                     formDataPreference.setIcon(R.drawable.form_data_disabled_day);
466                 }
467             }
468         }
469
470         // Set the custom user agent icon.
471         if (customUserAgentPreference.isEnabled()) {
472             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
473                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
474             } else {
475                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
476             }
477         } else {
478             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
479                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
480             } else {
481                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
482             }
483         }
484
485         // Set the incognito mode icon.
486         if (savedPreferences.getBoolean("incognito_mode", false)) {
487             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
488                 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
489             } else {
490                 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
491             }
492         } else {
493             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
494                 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
495             } else {
496                 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
497             }
498         }
499
500         // Set the Do Not Track icon.
501         if (savedPreferences.getBoolean("do_not_track", false)) {
502             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
503                 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_night);
504             } else {
505                 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_day);
506             }
507         } else {
508             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
509                 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_night);
510             } else {
511                 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_day);
512             }
513         }
514
515         // Set the allow screenshots icon.
516         if (savedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) {
517             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
518                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
519             } else {
520                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
521             }
522         } else {
523             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
524                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
525             } else {
526                 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
527             }
528         }
529
530         // Set the EasyList icon.
531         if (savedPreferences.getBoolean("easylist", true)) {
532             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
533                 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
534             } else {
535                 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
536             }
537         } else {
538             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
539                 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
540             } else {
541                 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
542             }
543         }
544
545         // Set the EasyPrivacy icon.
546         if (savedPreferences.getBoolean("easyprivacy", true)) {
547             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
548                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
549             } else {
550                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
551             }
552         } else {
553             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
554                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
555             } else {
556                 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
557             }
558         }
559
560         // Set the Fanboy lists icons.
561         if (fanboyAnnoyanceListEnabled) {
562             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
563                 // Set the Fanboy annoyance list icon.
564                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
565
566                 // Set the Fanboy social blocking list icon.
567                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
568             } else {
569                 // Set the Fanboy annoyance list icon.
570                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
571
572                 // Set the Fanboy social blocking list icon.
573                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
574             }
575         } else {
576             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
577                 // Set the Fanboy annoyance list icon.
578                 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
579
580                 // Set the Fanboy social blocking list icon.
581                 if (fanboySocialBlockingEnabled) {
582                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
583                 } else {
584                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
585                 }
586             } else {
587                 // Set the Fanboy annoyance list icon.
588                 fanboyAnnoyanceListPreference.setIcon(R.drawable.block_ads_disabled_day);
589
590                 // Set the Fanboy social blocking list icon.
591                 if (fanboySocialBlockingEnabled) {
592                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
593                 } else {
594                     fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
595                 }
596             }
597         }
598
599         // Set the UltraList icon.
600         if (savedPreferences.getBoolean("ultralist", true)){
601             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
602                 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
603             } else {
604                 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
605             }
606         } else {
607             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
608                 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
609             } else {
610                 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
611             }
612         }
613
614         // Set the UltraPrivacy icon.
615         if (savedPreferences.getBoolean("ultraprivacy", true)) {
616             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
617                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
618             } else {
619                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
620             }
621         } else {
622             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
623                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
624             } else {
625                 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
626             }
627         }
628
629         // Set the block all third-party requests icon.
630         if (savedPreferences.getBoolean("block_all_third_party_requests", false)) {
631             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
632                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
633             } else {
634                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
635             }
636         } else {
637             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
638                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
639             } else {
640                 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
641             }
642         }
643
644         // Set the Google Analytics icon according to the theme.
645         if (savedPreferences.getBoolean("google_analytics", true)) {
646             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
647                 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
648             } else {
649                 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
650             }
651         } else {
652             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
653                 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
654             } else {
655                 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
656             }
657         }
658
659         // Set the Facebook Click IDs icon according to the theme.
660         if (savedPreferences.getBoolean("facebook_click_ids", true)) {
661             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
662                 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
663             } else {
664                 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
665             }
666         } else {
667             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
668                 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
669             } else {
670                 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
671             }
672         }
673
674         // Set the Twitter AMP redirects icon according to the theme.
675         if (savedPreferences.getBoolean("twitter_amp_redirects", true)) {
676             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
677                 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
678             } else {
679                 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
680             }
681         } else {
682             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
683                 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
684             } else {
685                 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
686             }
687         }
688
689         // Set the search custom URL icon.
690         if (searchCustomURLPreference.isEnabled()) {
691             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
692                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
693             } else {
694                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
695             }
696         } else {
697             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
698                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
699             } else {
700                 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
701             }
702         }
703
704         // Set the Proxy icons according to the theme and status.
705         if (proxyString.equals("None")) {  // Proxying is disabled.
706             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {  // Dark theme.
707                 // Set the main proxy icon to be disabled.
708                 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
709
710                 // Set the custom proxy URL icon to be ghosted.
711                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
712             } else {  // Light theme.
713                 // Set the main proxy icon to be disabled.
714                 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
715
716                 // Set the custom proxy URL icon to be ghosted.
717                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
718             }
719         } else {  // Proxying is enabled.
720             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {  // Dark theme.
721                 // Set the main proxy icon to be enabled.
722                 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
723
724                 // Set the custom proxy URL icon according to its status.
725                 if (proxyCustomUrlPreference.isEnabled()) {  // Custom proxy is enabled.
726                     proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
727                 } else {  // Custom proxy is disabled.
728                     proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
729                 }
730             } else {  // Light theme.
731                 // Set the main proxy icon to be enabled.
732                 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
733
734                 // Set the custom proxy URL icon according to its status.
735                 if (proxyCustomUrlPreference.isEnabled()) {  // Custom proxy is enabled.
736                     proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
737                 } else {  // Custom proxy is disabled.
738                     proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
739                 }
740             }
741         }
742
743         // Set the full screen browsing mode icons.
744         if (fullScreenBrowsingMode) {  // Full screen browsing mode is enabled.
745             // Set the `fullScreenBrowsingModePreference` icon according to the theme.
746             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
747                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
748             } else {
749                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
750             }
751
752             // Set the hide app bar icon.
753             if (savedPreferences.getBoolean("hide_app_bar", true)) {  // Hide app bar is enabled.
754                 // Set the icon according to the theme.
755                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
756                     hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
757                 } else {
758                     hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
759                 }
760             } else {  // Hide app bar is disabled.
761                 // Set the icon according to the theme.
762                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
763                     hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
764                 } else {
765                     hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
766                 }
767             }
768         } else {  // Full screen browsing mode is disabled.
769             // Set the icons according to the theme.
770             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
771                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
772                 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
773             } else {
774                 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
775                 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
776             }
777         }
778
779         // Set the clear everything preference icon.
780         if (clearEverything) {
781             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
782                 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
783             } else {
784                 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
785             }
786         } else {
787             clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
788         }
789
790         // Set the clear cookies preference icon.
791         if (clearEverything || savedPreferences.getBoolean("clear_cookies", true)) {
792             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
793                 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
794             } else {
795                 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
796             }
797         } else {
798             clearCookiesPreference.setIcon(R.drawable.cookies_warning);
799         }
800
801         // Set the clear DOM storage preference icon.
802         if (clearEverything || savedPreferences.getBoolean("clear_dom_storage", true)) {
803             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
804                 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
805             } else {
806                 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
807             }
808         } else {
809             clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
810         }
811
812         // Set the clear form data preference icon if the API < 26.  It has no effect on newer versions of Android.
813         if (Build.VERSION.SDK_INT < 26) {
814             if (clearEverything || savedPreferences.getBoolean("clear_form_data", true)) {
815                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
816                     clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
817                 } else {
818                     clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
819                 }
820             } else {
821                 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
822             }
823         }
824
825         // Set the clear logcat preference icon.
826         if (clearEverything || savedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
827             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
828                 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
829             } else {
830                 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
831             }
832         } else {
833             clearLogcatPreference.setIcon(R.drawable.bug_warning);
834         }
835
836         // Set the clear cache preference icon.
837         if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) {
838             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
839                 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
840             } else {
841                 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
842             }
843         } else {
844             clearCachePreference.setIcon(R.drawable.cache_warning);
845         }
846
847         // Set the download custom location icon.
848         if (downloadCustomLocationPreference.isEnabled()) {
849             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
850                 downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_night);
851             } else {
852                 downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_day);
853             }
854         } else {
855             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
856                 downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_night);
857             } else {
858                 downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_day);
859             }
860         }
861
862         // Set the open intents in new tab preference icon.
863         if (savedPreferences.getBoolean("open_intents_in_new_tab", true)) {
864             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
865                 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
866             } else {
867                 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
868             }
869         } else {
870             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
871                 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
872             } else {
873                 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
874             }
875         }
876
877         // Set the swipe to refresh preference icon.
878         if (savedPreferences.getBoolean("swipe_to_refresh", true)) {
879             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
880                 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
881             } else {
882                 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
883             }
884         } else {
885             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
886                 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
887             } else {
888                 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
889             }
890         }
891
892         // Set the scroll app bar preference icon.
893         if (savedPreferences.getBoolean("scroll_app_bar", true)) {
894             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
895                 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
896             } else {
897                 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
898             }
899         } else {
900             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
901                 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
902             } else {
903                 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
904             }
905         }
906
907         // Set the display additional app bar icons preference icon.
908         if (savedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
909             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
910                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
911             } else {
912                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
913             }
914         } else {
915             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
916                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
917             } else {
918                 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
919             }
920         }
921
922         // Set the WebView theme preference icon.
923         switch (webViewThemeEntryNumber) {
924             case 0:  // The system default WebView theme is selected.
925                 // Set the icon according to the app theme.
926                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
927                     webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
928                 } else {
929                     webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
930                 }
931                 break;
932
933             case 1:  // The light WebView theme is selected.
934                 // Set the icon according to the app theme.
935                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
936                     webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
937                 } else {
938                     webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
939                 }
940                 break;
941
942             case 2:  // The dark WebView theme is selected.
943                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
944                     webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
945                 } else {
946                     webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
947                 }
948                 break;
949         }
950
951         // Set the wide viewport preference icon.
952         if (savedPreferences.getBoolean("wide_viewport", true)) {
953             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
954                 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
955             } else {
956                 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
957             }
958         } else {
959             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
960                 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
961             } else {
962                 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
963             }
964         }
965
966         // Set the display webpage images preference icon.
967         if (savedPreferences.getBoolean("display_webpage_images", true)) {
968             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
969                 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
970             } else {
971                 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
972             }
973         } else {
974             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
975                 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
976             } else {
977                 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
978             }
979         }
980
981
982         // Listen for preference changes.
983         preferencesListener = (SharedPreferences sharedPreferences, String key) -> {
984             switch (key) {
985                 case "javascript":
986                     // Update the icons and the DOM storage preference status.
987                     if (sharedPreferences.getBoolean("javascript", false)) {  // The JavaScript preference is enabled.
988                         // Update the icon for the JavaScript preference.
989                         javaScriptPreference.setIcon(R.drawable.javascript_enabled);
990
991                         // Update the status of the DOM storage preference.
992                         domStoragePreference.setEnabled(true);
993
994                         // Update the icon for the DOM storage preference.
995                         if (sharedPreferences.getBoolean("dom_storage", false)) {
996                             domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
997                         } else {
998                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
999                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1000                             } else {
1001                                 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1002                             }
1003                         }
1004                     } else {  // The JavaScript preference is disabled.
1005                         // Update the icon for the JavaScript preference.
1006                         javaScriptPreference.setIcon(R.drawable.privacy_mode);
1007
1008                         // Update the status of the DOM storage preference.
1009                         domStoragePreference.setEnabled(false);
1010
1011                         // Set the icon for DOM storage preference to be ghosted.
1012                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1013                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
1014                         } else {
1015                             domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
1016                         }
1017                     }
1018                     break;
1019
1020                 case "first_party_cookies":
1021                     // Update the icons for `first_party_cookies` and `third_party_cookies`.
1022                     if (sharedPreferences.getBoolean("first_party_cookies", false)) {
1023                         // Set the icon for `first_party_cookies`.
1024                         firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
1025
1026                         // Update the icon for `third_party_cookies`.
1027                         if (Build.VERSION.SDK_INT >= 21) {
1028                             if (sharedPreferences.getBoolean("third_party_cookies", false)) {
1029                                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
1030                             } else {
1031                                 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1032                                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
1033                                 } else {
1034                                     thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
1035                                 }
1036                             }
1037                         } else {
1038                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1039                                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
1040                             } else {
1041                                 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
1042                             }
1043                         }
1044                     } else {  // `first_party_cookies` is `false`.
1045                         // Update the icon for `first_party_cookies`.
1046                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1047                             firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
1048                         } else {
1049                             firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
1050                         }
1051
1052                         // Set the icon for `third_party_cookies` to be ghosted.
1053                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1054                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
1055                         } else {
1056                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
1057                         }
1058                     }
1059
1060                     // Enable `third_party_cookies` if `first_party_cookies` is `true` and API >= 21.
1061                     thirdPartyCookiesPreference.setEnabled(sharedPreferences.getBoolean("first_party_cookies", false) && (Build.VERSION.SDK_INT >= 21));
1062                     break;
1063
1064                 case "third_party_cookies":
1065                     // Update the icon.
1066                     if (sharedPreferences.getBoolean("third_party_cookies", false)) {
1067                         thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
1068                     } else {
1069                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1070                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
1071                         } else {
1072                             thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
1073                         }
1074                     }
1075                     break;
1076
1077                 case "dom_storage":
1078                     // Update the icon.
1079                     if (sharedPreferences.getBoolean("dom_storage", false)) {
1080                         domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1081                     } else {
1082                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1083                             domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1084                         } else {
1085                             domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1086                         }
1087                     }
1088                     break;
1089
1090                 // Save form data can be removed once the minimum API >= 26.
1091                 case "save_form_data":
1092                     // Update the icon.
1093                     if (sharedPreferences.getBoolean("save_form_data", false)) {
1094                         formDataPreference.setIcon(R.drawable.form_data_enabled);
1095                     } else {
1096                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1097                             formDataPreference.setIcon(R.drawable.form_data_disabled_night);
1098                         } else {
1099                             formDataPreference.setIcon(R.drawable.form_data_disabled_day);
1100                         }
1101                     }
1102                     break;
1103
1104                 case "user_agent":
1105                     // Get the new user agent name.
1106                     String newUserAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
1107
1108                     // Get the array position for the new user agent name.
1109                     int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName);
1110
1111                     // Get the translated new user agent name.
1112                     String translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition];
1113
1114                     // Populate the user agent summary.
1115                     switch (newUserAgentArrayPosition) {
1116                         case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
1117                             // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
1118                             userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + bareWebView.getSettings().getUserAgentString());
1119
1120                             // Disable the custom user agent preference.
1121                             customUserAgentPreference.setEnabled(false);
1122
1123                             // Set the custom user agent preference icon according to the theme.
1124                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1125                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1126                             } else {
1127                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1128                             }
1129                             break;
1130
1131                         case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
1132                             // Set the summary text.
1133                             userAgentPreference.setSummary(R.string.custom_user_agent);
1134
1135                             // Enable the custom user agent preference.
1136                             customUserAgentPreference.setEnabled(true);
1137
1138                             // Set the custom user agent preference icon according to the theme.
1139                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1140                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
1141                             } else {
1142                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
1143                             }
1144                             break;
1145
1146                         default:
1147                             // Get the user agent summary from the user agent data array.
1148                             userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + userAgentDataArray[newUserAgentArrayPosition]);
1149
1150                             // Disable the custom user agent preference.
1151                             customUserAgentPreference.setEnabled(false);
1152
1153                             // Set the custom user agent preference icon according to the theme.
1154                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1155                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1156                             } else {
1157                                 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1158                             }
1159                     }
1160                     break;
1161
1162                 case "custom_user_agent":
1163                     // Set the new custom user agent as the summary text for the preference.
1164                     customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
1165                     break;
1166
1167                 case "incognito_mode":
1168                     // Update the icon.
1169                     if (sharedPreferences.getBoolean("incognito_mode", false)) {
1170                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1171                             incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
1172                         } else {
1173                             incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
1174                         }
1175                     } else {
1176                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1177                             incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
1178                         } else {
1179                             incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
1180                         }
1181                     }
1182                     break;
1183
1184                 case "do_not_track":
1185                     // Update the icon.
1186                     if (sharedPreferences.getBoolean("do_not_track", false)) {
1187                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1188                             doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_night);
1189                         } else {
1190                             doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_day);
1191                         }
1192                     } else {
1193                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1194                             doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_night);
1195                         } else {
1196                             doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_day);
1197                         }
1198                     }
1199
1200                     break;
1201
1202                 case "allow_screenshots":
1203                     // Update the icon.
1204                     if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) {
1205                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1206                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
1207                         } else {
1208                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
1209                         }
1210                     } else {
1211                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1212                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
1213                         } else {
1214                             allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
1215                         }
1216                     }
1217
1218                     // Create an intent to restart Privacy Browser.
1219                     Intent allowScreenshotsRestartIntent = getActivity().getParentActivityIntent();
1220
1221                     // Assert that the intent is not null to remove the lint error below.
1222                     assert allowScreenshotsRestartIntent != null;
1223
1224                     // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack.  It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
1225                     allowScreenshotsRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
1226
1227                     // Create a handler to restart the activity.
1228                     Handler allowScreenshotsRestartHandler = new Handler();
1229
1230                     // Create a runnable to restart the activity.
1231                     Runnable allowScreenshotsRestartRunnable = () -> {
1232                         // Restart the activity.
1233                         startActivity(allowScreenshotsRestartIntent);
1234
1235                         // Kill this instance of Privacy Browser.  Otherwise, the app exhibits sporadic behavior after the restart.
1236                         System.exit(0);
1237                     };
1238
1239                     // Restart the activity after 150 milliseconds, so that the app has enough time to save the change to the preference.
1240                     allowScreenshotsRestartHandler.postDelayed(allowScreenshotsRestartRunnable, 150);
1241                     break;
1242
1243                 case "easylist":
1244                     // Update the icon.
1245                     if (sharedPreferences.getBoolean("easylist", true)) {
1246                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1247                             easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
1248                         } else {
1249                             easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
1250                         }
1251                     } else {
1252                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1253                             easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
1254                         } else {
1255                             easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
1256                         }
1257                     }
1258                     break;
1259
1260                 case "easyprivacy":
1261                     // Update the icon.
1262                     if (sharedPreferences.getBoolean("easyprivacy", true)) {
1263                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1264                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1265                         } else {
1266                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1267                         }
1268                     } else {
1269                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1270                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1271                         } else {
1272                             easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1273                         }
1274                     }
1275                     break;
1276
1277                 case "fanboys_annoyance_list":
1278                     boolean currentFanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
1279                     boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
1280
1281                     // Update the Fanboy icons.
1282                     if (currentFanboyAnnoyanceList) {  // Fanboy's annoyance list is enabled.
1283                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1284                             // Update the Fanboy's annoyance list icon.
1285                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
1286
1287                             // Update the Fanboy's social blocking list icon.
1288                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
1289                         } else {
1290                             // Update the Fanboy's annoyance list icon.
1291                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
1292
1293                             // Update the Fanboy's social blocking list icon.
1294                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
1295                         }
1296                     } else {  // Fanboy's annoyance list is disabled.
1297                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1298                             // Update the Fanboy's annoyance list icon.
1299                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
1300
1301                             // Update the Fanboy's social blocking list icon.
1302                             if (currentFanboySocialBlockingList) {
1303                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1304                             } else {
1305                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1306                             }
1307                         } else {
1308                             // Update the Fanboy's annoyance list icon.
1309                             fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_day);
1310
1311                             // Update the Fanboy's social blocking list icon.
1312                             if (currentFanboySocialBlockingList) {
1313                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1314                             } else {
1315                                 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1316                             }
1317                         }
1318                     }
1319
1320                     // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled.
1321                     fanboySocialBlockingListPreference.setEnabled(!currentFanboyAnnoyanceList);
1322                     break;
1323
1324                 case "fanboys_social_blocking_list":
1325                     // Update the icon.
1326                     if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) {
1327                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1328                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1329                         } else {
1330                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1331                         }
1332                     } else {
1333                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1334                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1335                         } else {
1336                             fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1337                         }
1338                     }
1339                     break;
1340
1341                 case "ultralist":
1342                     // Update the icon.
1343                     if (sharedPreferences.getBoolean("ultralist", true)) {
1344                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1345                             ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
1346                         } else {
1347                             ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
1348                         }
1349                     } else {
1350                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1351                             ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
1352                         } else {
1353                             ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
1354                         }
1355                     }
1356                     break;
1357
1358                 case "ultraprivacy":
1359                     // Update the icon.
1360                     if (sharedPreferences.getBoolean("ultraprivacy", true)) {
1361                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1362                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1363                         } else {
1364                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1365                         }
1366                     } else {
1367                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1368                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1369                         } else {
1370                             ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1371                         }
1372                     }
1373                     break;
1374
1375                 case "block_all_third_party_requests":
1376                     // Update the icon.
1377                     if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
1378                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1379                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
1380                         } else {
1381                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
1382                         }
1383                     } else {
1384                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1385                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
1386                         } else {
1387                             blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
1388                         }
1389                     }
1390                     break;
1391
1392                 case "google_analytics":
1393                     // Update the icon.
1394                     if (sharedPreferences.getBoolean("google_analytics", true)) {
1395                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1396                             googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
1397                         } else {
1398                             googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
1399                         }
1400                     } else {
1401                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1402                             googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
1403                         } else {
1404                             googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
1405                         }
1406                     }
1407                     break;
1408
1409                 case "facebook_click_ids":
1410                     // Update the icon.
1411                     if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
1412                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1413                             facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
1414                         } else {
1415                             facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
1416                         }
1417                     } else {
1418                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1419                             facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
1420                         } else {
1421                             facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
1422                         }
1423                     }
1424                     break;
1425
1426                 case "twitter_amp_redirects":
1427                     // Update the icon.
1428                     if (sharedPreferences.getBoolean("twitter_amp_redirects", true)) {
1429                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1430                             twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
1431                         } else {
1432                             twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
1433                         }
1434                     } else {
1435                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1436                             twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
1437                         } else {
1438                             twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
1439                         }
1440                     }
1441                     break;
1442
1443                 case "search":
1444                     // Store the new search string.
1445                     String newSearchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
1446
1447                     // Update the search and search custom URL preferences.
1448                     if (newSearchString.equals("Custom URL")) {  // `Custom URL` is selected.
1449                         // Set the summary text to `R.string.custom_url`, which is translated.
1450                         searchPreference.setSummary(R.string.custom_url);
1451
1452                         // Enable `searchCustomURLPreference`.
1453                         searchCustomURLPreference.setEnabled(true);
1454
1455                         // Set the `searchCustomURLPreference` according to the theme.
1456                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1457                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
1458                         } else {
1459                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
1460                         }
1461                     } else {  // `Custom URL` is not selected.
1462                         // Set the summary text to `newSearchString`.
1463                         searchPreference.setSummary(newSearchString);
1464
1465                         // Disable `searchCustomURLPreference`.
1466                         searchCustomURLPreference.setEnabled(false);
1467
1468                         // Set the `searchCustomURLPreference` according to the theme.
1469                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1470                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
1471                         } else {
1472                             searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
1473                         }
1474                     }
1475                     break;
1476
1477                 case "search_custom_url":
1478                     // Set the new search custom URL as the summary text for the preference.
1479                     searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
1480                     break;
1481
1482                 case "proxy":
1483                     // Get current proxy string.
1484                     String currentProxyString = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value));
1485
1486                     // Update the summary text for the proxy preference.
1487                     switch (currentProxyString) {
1488                         case ProxyHelper.NONE:
1489                             proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
1490                             break;
1491
1492                         case ProxyHelper.TOR:
1493                             if (Build.VERSION.SDK_INT == 19) {  // Proxying through SOCKS doesn't work on Android KitKat.
1494                                 proxyPreference.setSummary(getString(R.string.tor_enabled_kitkat));
1495                             } else {
1496                                 proxyPreference.setSummary(getString(R.string.tor_enabled));
1497                             }
1498                             break;
1499
1500                         case ProxyHelper.I2P:
1501                             proxyPreference.setSummary(getString(R.string.i2p_enabled));
1502                             break;
1503
1504                         case ProxyHelper.CUSTOM:
1505                             proxyPreference.setSummary(getString(R.string.custom_proxy));
1506                             break;
1507                     }
1508
1509                     // Update the status of the custom URL preference.
1510                     proxyCustomUrlPreference.setEnabled(currentProxyString.equals("Custom"));
1511
1512                     // Update the icons.
1513                     if (currentProxyString.equals("None")) {  // Proxying is disabled.
1514                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {  // Dark theme.
1515                             // Set the main proxy icon to be disabled
1516                             proxyPreference.setIcon(R.drawable.proxy_disabled_night);
1517
1518                             // Set the custom proxy URL icon to be ghosted.
1519                             proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1520                         } else {  // Light theme.
1521                             // Set the main proxy icon to be disabled.
1522                             proxyPreference.setIcon(R.drawable.proxy_disabled_day);
1523
1524                             // Set the custom proxy URL icon to be ghosted.
1525                             proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1526                         }
1527                     } else {  // Proxying is enabled.
1528                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {  // Dark theme.
1529                             // Set the main proxy icon to be enabled.
1530                             proxyPreference.setIcon(R.drawable.proxy_enabled_night);
1531
1532                             /// Set the custom proxy URL icon according to its status.
1533                             if (proxyCustomUrlPreference.isEnabled()) {  // Custom proxy is enabled.
1534                                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
1535                             } else {  // Custom proxy is disabled.
1536                                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1537                             }
1538                         } else {  // Light theme.
1539                             // Set the main proxy icon to be enabled.
1540                             proxyPreference.setIcon(R.drawable.proxy_enabled_day);
1541
1542                             // Set the custom proxy URL icon according to its status.
1543                             if (proxyCustomUrlPreference.isEnabled()) {  // Custom proxy is enabled.
1544                                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
1545                             } else {  // Custom proxy is disabled.
1546                                 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1547                             }
1548                         }
1549                     }
1550                     break;
1551
1552                 case "proxy_custom_url":
1553                     // Set the summary text for the proxy custom URL.
1554                     proxyCustomUrlPreference.setSummary(sharedPreferences.getString("proxy_custom_url", getString(R.string.proxy_custom_url_default_value)));
1555                     break;
1556
1557                 case "full_screen_browsing_mode":
1558                     if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) {  // Full screen browsing is enabled.
1559                         // Set the full screen browsing mode preference icon according to the theme.
1560                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1561                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
1562                         } else {
1563                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
1564                         }
1565
1566                         // Set the hide app bar preference icon.
1567                         if (sharedPreferences.getBoolean("hide_app_bar", true)) {  //  Hide app bar is enabled.
1568                             // Set the icon according to the theme.
1569                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1570                                 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1571                             } else {
1572                                 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1573                             }
1574                         } else {  // Hide app bar is disabled.
1575                             // Set the icon according to the theme.
1576                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1577                                 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1578                             } else {
1579                                 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1580                             }
1581                         }
1582                     } else {  // Full screen browsing is disabled.
1583                         // Update the icons according to the theme.
1584                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1585                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
1586                             hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
1587                         } else {
1588                             fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
1589                             hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
1590                         }
1591                     }
1592                     break;
1593
1594                 case "hide_app_bar":
1595                     // Update the icon.
1596                     if (sharedPreferences.getBoolean("hide_app_bar", true)) {  // Hide app bar is enabled.
1597                         // Set the icon according to the theme.
1598                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1599                             hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1600                         } else {
1601                             hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1602                         }
1603                     } else {  // Hide app bar is disabled.
1604                         // Set the icon according to the theme.
1605                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1606                             hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1607                         } else {
1608                             hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1609                         }
1610                     }
1611                     break;
1612
1613                 case "clear_everything":
1614                     // Store the new clear everything status
1615                     boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true);
1616
1617                     // Update the status of the clear and exit preferences.
1618                     clearCookiesPreference.setEnabled(!newClearEverythingBoolean);
1619                     clearDomStoragePreference.setEnabled(!newClearEverythingBoolean);
1620                     clearFormDataPreference.setEnabled(!newClearEverythingBoolean);  // This line can be removed once the minimum API >= 26.
1621                     clearLogcatPreference.setEnabled(!newClearEverythingBoolean);
1622                     clearCachePreference.setEnabled(!newClearEverythingBoolean);
1623
1624                     // Update the clear everything preference icon.
1625                     if (newClearEverythingBoolean) {
1626                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1627                             clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
1628                         } else {
1629                             clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
1630                         }
1631                     } else {
1632                         clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
1633                     }
1634
1635                     // Update the clear cookies preference icon.
1636                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) {
1637                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1638                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1639                         } else {
1640                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1641                         }
1642                     } else {
1643                         clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1644                     }
1645
1646                     // Update the clear dom storage preference icon.
1647                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) {
1648                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1649                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1650                         } else {
1651                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1652                         }
1653                     } else {
1654                         clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1655                     }
1656
1657                     // Update the clear form data preference icon if the API < 26.
1658                     if (Build.VERSION.SDK_INT < 26) {
1659                         if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) {
1660                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1661                                 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1662                             } else {
1663                                 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1664                             }
1665                         } else {
1666                             clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1667                         }
1668                     }
1669
1670                     // Update the clear logcat preference icon.
1671                     if (newClearEverythingBoolean || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
1672                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1673                             clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1674                         } else {
1675                             clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1676                         }
1677                     } else {
1678                         clearLogcatPreference.setIcon(R.drawable.cache_warning);
1679                     }
1680
1681                     // Update the clear cache preference icon.
1682                     if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) {
1683                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1684                             clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1685                         } else {
1686                             clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1687                         }
1688                     } else {
1689                         clearCachePreference.setIcon(R.drawable.cache_warning);
1690                     }
1691                     break;
1692
1693                 case "clear_cookies":
1694                     // Update the icon.
1695                     if (sharedPreferences.getBoolean("clear_cookies", true)) {
1696                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1697                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1698                         } else {
1699                             clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1700                         }
1701                     } else {
1702                         clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1703                     }
1704                     break;
1705
1706                 case "clear_dom_storage":
1707                     // Update the icon.
1708                     if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
1709                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1710                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1711                         } else {
1712                             clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1713                         }
1714                     } else {
1715                         clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1716                     }
1717                     break;
1718
1719                 // This section can be removed once the minimum API >= 26.
1720                 case "clear_form_data":
1721                     // Update the icon.
1722                     if (sharedPreferences.getBoolean("clear_form_data", true)) {
1723                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1724                             clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1725                         } else {
1726                             clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1727                         }
1728                     } else {
1729                         clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1730                     }
1731                     break;
1732
1733                 case "clear_logcat":
1734                     // Update the icon.
1735                     if (sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
1736                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1737                             clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1738                         } else {
1739                             clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1740                         }
1741                     } else {
1742                         clearLogcatPreference.setIcon(R.drawable.bug_warning);
1743                     }
1744                     break;
1745
1746                 case "clear_cache":
1747                     // Update the icon.
1748                     if (sharedPreferences.getBoolean("clear_cache", true)) {
1749                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1750                             clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1751                         } else {
1752                             clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1753                         }
1754                     } else {
1755                         clearCachePreference.setIcon(R.drawable.cache_warning);
1756                     }
1757                     break;
1758
1759                 case "homepage":
1760                     // Set the new homepage URL as the summary text for the Homepage preference.
1761                     homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
1762                     break;
1763
1764                 case "download_location":
1765                     // Get the new download location.
1766                     String newDownloadLocationString = sharedPreferences.getString("download_location", getString(R.string.download_location_default_value));
1767
1768                     // Check to see if a download custom location is selected.
1769                     if (newDownloadLocationString.equals(downloadLocationEntryValuesStringArray[3])) {  // A download custom location is selected.
1770                         // Set the download location summary text to be `Custom`.
1771                         downloadLocationPreference.setSummary(downloadLocationEntriesStringArray[3]);
1772
1773                         // Enable the download custom location preference.
1774                         downloadCustomLocationPreference.setEnabled(true);
1775                     } else {  // A download custom location is not selected.
1776                         // Set the download location summary text to be the download location.
1777                         downloadLocationPreference.setSummary(downloadLocationHelper.getDownloadLocation(context));
1778
1779                         // Disable the download custom location.
1780                         downloadCustomLocationPreference.setEnabled(newDownloadLocationString.equals(downloadLocationEntryValuesStringArray[3]));
1781                     }
1782
1783                     // Update the download custom location icon.
1784                     if (downloadCustomLocationPreference.isEnabled()) {
1785                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1786                             downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_night);
1787                         } else {
1788                             downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_day);
1789                         }
1790                     } else {
1791                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1792                             downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_night);
1793                         } else {
1794                             downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_day);
1795                         }
1796                     }
1797                     break;
1798
1799                 case "download_custom_location":
1800                     // Set the new download custom location as the summary text for the preference.
1801                     downloadCustomLocationPreference.setSummary(sharedPreferences.getString("download_custom_location", getString(R.string.download_custom_location_default_value)));
1802                     break;
1803
1804                 case "font_size":
1805                     // Update the font size summary text.
1806                     fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
1807                     break;
1808
1809                 case "open_intents_in_new_tab":
1810                     // Update the icon.
1811                     if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
1812                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1813                             openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
1814                         } else {
1815                             openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
1816                         }
1817                     } else {
1818                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1819                             openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
1820                         } else {
1821                             openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
1822                         }
1823                     }
1824                     break;
1825
1826                 case "swipe_to_refresh":
1827                     // Update the icon.
1828                     if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
1829                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1830                             swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
1831                         } else {
1832                             swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
1833                         }
1834                     } else {
1835                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1836                             swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
1837                         } else {
1838                             swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
1839                         }
1840                     }
1841                     break;
1842
1843                 case "scroll_app_bar":
1844                     // Update the icon.
1845                     if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
1846                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1847                             scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1848                         } else {
1849                             scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1850                         }
1851                     } else {
1852                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1853                             scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1854                         } else {
1855                             scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1856                         }
1857                     }
1858                     break;
1859
1860                 case "display_additional_app_bar_icons":
1861                     // Update the icon.
1862                     if (sharedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
1863                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1864                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
1865                         } else {
1866                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
1867                         }
1868                     } else {
1869                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1870                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
1871                         } else {
1872                             displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
1873                         }
1874                     }
1875                     break;
1876
1877                 case "app_theme":
1878                     // Get the new theme.
1879                     String newAppTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
1880
1881                     // Update the system according to the new theme.  A switch statement cannot be used because the theme entry values string array is not a compile time constant.
1882                     if (newAppTheme.equals(appThemeEntryValuesStringArray[1])) {  // The light theme is selected.
1883                         // Update the theme preference summary text.
1884                         appThemePreference.setSummary(appThemeEntriesStringArray[1]);
1885
1886                         // Apply the new theme.
1887                         AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
1888                     } else if (newAppTheme.equals(appThemeEntryValuesStringArray[2])) {  // The dark theme is selected.
1889                         // Update the theme preference summary text.
1890                         appThemePreference.setSummary(appThemeEntriesStringArray[2]);
1891
1892                         // Apply the new theme.
1893                         AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
1894                     } else {  // The system default theme is selected.
1895                         // Update the theme preference summary text.
1896                         appThemePreference.setSummary(appThemeEntriesStringArray[0]);
1897
1898                         // Apply the new theme.
1899                         if (Build.VERSION.SDK_INT >= 28) {  // The system default theme is supported.
1900                             // Follow the system default theme.
1901                             AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
1902                         } else {// The system default theme is not supported.
1903                             // Follow the battery saver mode.
1904                             AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
1905                         }
1906                     }
1907
1908                     // Update the current theme status.
1909                     currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
1910                     break;
1911
1912                 case "webview_theme":
1913                     // Get the new WebView theme.
1914                     String newWebViewTheme = sharedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
1915
1916                     // Define a new WebView theme entry number.
1917                     int newWebViewThemeEntryNumber;
1918
1919                     // Get the webView theme entry number that matches the new WebView theme.  A switch statement cannot be used because the theme entry values string array is not a compile time constant.
1920                     if (newWebViewTheme.equals(webViewThemeEntriesStringArray[1])) {  // The light theme is selected.
1921                         // Store the new WebView theme entry number.
1922                         newWebViewThemeEntryNumber = 1;
1923                     } else if (newWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) {  // The dark theme is selected.
1924                         // Store the WebView theme entry number.
1925                         newWebViewThemeEntryNumber = 2;
1926                     } else {  // The system default theme is selected.
1927                         // Store the WebView theme entry number.
1928                         newWebViewThemeEntryNumber = 0;
1929                     }
1930
1931                     // Update the icon.
1932                     switch (newWebViewThemeEntryNumber) {
1933                         case 0:  // The system default WebView theme is selected.
1934                             // Set the icon according to the app theme.
1935                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1936                                 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1937                             } else {
1938                                 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1939                             }
1940                             break;
1941
1942                         case 1:  // The system default WebView theme is selected.
1943                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1944                                 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1945                             } else {
1946                                 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
1947                             }
1948                             break;
1949
1950                         case 2:  // The system default WebView theme is selected.
1951                             if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1952                                 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
1953                             } else {
1954                                 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1955                             }
1956                             break;
1957                     }
1958
1959                     // Set the current theme as the summary text for the preference.
1960                     webViewThemePreference.setSummary(webViewThemeEntriesStringArray[newWebViewThemeEntryNumber]);
1961                     break;
1962
1963                 case "wide_viewport":
1964                     // Update the icon.
1965                     if (sharedPreferences.getBoolean("wide_viewport", true)) {
1966                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1967                             wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
1968                         } else {
1969                             wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
1970                         }
1971                     } else {
1972                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1973                             wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
1974                         } else {
1975                             wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
1976                         }
1977                     }
1978                     break;
1979
1980                 case "display_webpage_images":
1981                     // Update the icon.
1982                     if (sharedPreferences.getBoolean("display_webpage_images", true)) {
1983                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1984                             displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
1985                         } else {
1986                             displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
1987                         }
1988                     } else {
1989                         if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1990                             displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
1991                         } else {
1992                             displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
1993                         }
1994                     }
1995                     break;
1996             }
1997         };
1998
1999         // Register the listener.
2000         savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);
2001     }
2002
2003     // It is necessary to re-register the listener on every resume or it will randomly stop working because apps can be paused and resumed at any time, even while running in the foreground.
2004     @Override
2005     public void onPause() {
2006         super.onPause();
2007         savedPreferences.unregisterOnSharedPreferenceChangeListener(preferencesListener);
2008     }
2009
2010     @Override
2011     public void onResume() {
2012         super.onResume();
2013         savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);
2014     }
2015 }