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