2 * Copyright © 2016-2020 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
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.
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.
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/>.
20 package com.stoutner.privacybrowser.fragments;
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;
37 import androidx.appcompat.app.AppCompatDelegate;
38 import androidx.preference.Preference;
39 import androidx.preference.PreferenceCategory;
40 import androidx.preference.PreferenceFragmentCompat;
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;
47 public class SettingsFragment extends PreferenceFragmentCompat {
48 // Define the class variables.
49 private SharedPreferences.OnSharedPreferenceChangeListener preferencesListener;
50 private SharedPreferences savedPreferences;
51 private int currentThemeStatus;
54 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
55 // Load the preferences from the XML file.
56 setPreferencesFromResource(R.xml.preferences, rootKey);
58 // Get a handle for the activity.
59 Activity activity = getActivity();
61 // Remove the lint warning below that `getApplicationContext()` might produce a null pointer exception.
62 assert activity != null;
64 // Get a handle for the context and the resources.
65 Context context = activity.getApplicationContext();
66 Resources resources = getResources();
68 // Get the current theme status.
69 currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
71 // Initialize savedPreferences.
72 savedPreferences = getPreferenceScreen().getSharedPreferences();
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");
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;
166 // Set the preference dependencies.
167 hideAppBarPreference.setDependency("full_screen_browsing_mode");
168 domStoragePreference.setDependency("javascript");
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));
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);
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));
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");
193 // Remove the incorrect lint warnings below that the preference categories might be null.
194 assert privacyCategory != null;
195 assert clearAndExitCategory != null;
197 // Remove the form data preferences.
198 privacyCategory.removePreference(formDataPreference);
199 clearAndExitCategory.removePreference(clearFormDataPreference);
202 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled.
203 fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled);
206 // Inflate a WebView to get the default user agent.
207 LayoutInflater inflater = getActivity().getLayoutInflater();
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);
212 // Get a handle for a bare WebView.
213 WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
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);
220 // Get the array position of the user agent name.
221 int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
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);
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());
235 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
236 // Set the summary text.
237 userAgentPreference.setSummary(R.string.custom_user_agent);
241 // Get the user agent summary from the user agent data array.
242 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + userAgentDataArray[userAgentArrayPosition]);
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)));
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)));
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);
257 // Set the array value as the summary text.
258 searchPreference.setSummary(searchString);
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)));
264 // Only enable the search custom URL preference if the search is set to `Custom URL`.
265 searchCustomURLPreference.setEnabled(searchString.equals("Custom URL"));
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));
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));
278 proxyPreference.setSummary(getString(R.string.tor_enabled));
282 case ProxyHelper.I2P:
283 proxyPreference.setSummary(getString(R.string.i2p_enabled));
286 case ProxyHelper.CUSTOM:
287 proxyPreference.setSummary(getString(R.string.custom_proxy));
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)));
294 // Only enable the custom proxy URL if a custom proxy is selected.
295 proxyCustomUrlPreference.setEnabled(proxyString.equals("Custom"));
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);
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)));
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);
314 // Instantiate the download location helper.
315 DownloadLocationHelper downloadLocationHelper = new DownloadLocationHelper();
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));
325 // Disable the download custom location preference.
326 downloadCustomLocationPreference.setEnabled(false);
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)));
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)) + "%");
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);
341 // Get the current app theme.
342 String currentAppTheme = savedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
344 // Define an app theme entry number.
345 int appThemeEntryNumber;
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;
359 // Set the current theme as the summary text for the preference.
360 appThemePreference.setSummary(appThemeEntriesStringArray[appThemeEntryNumber]);
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);
367 // Get the current WebView theme.
368 String currentWebViewTheme = savedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
370 // Define a WebView theme entry number.
371 int webViewThemeEntryNumber;
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;
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");
390 // Remove the incorrect lint warning below that the general preference category might be null.
391 assert generalCategory != null;
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]);
401 // Set the JavaScript icon.
402 if (javaScriptEnabled) {
403 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
405 javaScriptPreference.setIcon(R.drawable.privacy_mode);
408 // Set the first-party cookies icon.
409 if (firstPartyCookiesEnabled) {
410 firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
412 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
413 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
415 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
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);
424 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
425 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
427 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
431 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
432 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
434 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
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);
446 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
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);
453 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
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);
462 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
463 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
465 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
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);
475 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
478 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
479 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
481 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
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);
490 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
493 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
494 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
496 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
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);
505 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_day);
508 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
509 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_night);
511 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_day);
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);
520 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
523 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
524 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
526 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
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);
535 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
538 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
539 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
541 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
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);
550 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
553 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
554 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
556 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
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);
566 // Set the Fanboy social blocking list icon.
567 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
569 // Set the Fanboy annoyance list icon.
570 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
572 // Set the Fanboy social blocking list icon.
573 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
576 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
577 // Set the Fanboy annoyance list icon.
578 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
580 // Set the Fanboy social blocking list icon.
581 if (fanboySocialBlockingEnabled) {
582 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
584 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
587 // Set the Fanboy annoyance list icon.
588 fanboyAnnoyanceListPreference.setIcon(R.drawable.block_ads_disabled_day);
590 // Set the Fanboy social blocking list icon.
591 if (fanboySocialBlockingEnabled) {
592 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
594 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
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);
604 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
607 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
608 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
610 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
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);
619 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
622 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
623 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
625 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
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);
634 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
637 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
638 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
640 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
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);
649 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
652 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
653 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
655 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
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);
664 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
667 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
668 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
670 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
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);
679 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
682 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
683 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
685 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
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);
694 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
697 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
698 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
700 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
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);
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);
716 // Set the custom proxy URL icon to be ghosted.
717 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
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);
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);
730 } else { // Light theme.
731 // Set the main proxy icon to be enabled.
732 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
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);
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);
749 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
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);
758 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
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);
765 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
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);
774 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
775 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
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);
784 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
787 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
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);
795 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
798 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
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);
806 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
809 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
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);
818 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
821 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
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);
830 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
833 clearLogcatPreference.setIcon(R.drawable.bug_warning);
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);
841 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
844 clearCachePreference.setIcon(R.drawable.cache_warning);
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);
852 downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_day);
855 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
856 downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_night);
858 downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_day);
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);
867 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
870 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
871 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
873 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
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);
882 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
885 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
886 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
888 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
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);
897 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
900 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
901 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
903 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
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);
912 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
915 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
916 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
918 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
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);
929 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
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);
938 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
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);
946 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
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);
956 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
959 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
960 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
962 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
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);
971 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
974 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
975 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
977 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
982 // Listen for preference changes.
983 preferencesListener = (SharedPreferences sharedPreferences, String key) -> {
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);
991 // Update the status of the DOM storage preference.
992 domStoragePreference.setEnabled(true);
994 // Update the icon for the DOM storage preference.
995 if (sharedPreferences.getBoolean("dom_storage", false)) {
996 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
998 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
999 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1001 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1004 } else { // The JavaScript preference is disabled.
1005 // Update the icon for the JavaScript preference.
1006 javaScriptPreference.setIcon(R.drawable.privacy_mode);
1008 // Update the status of the DOM storage preference.
1009 domStoragePreference.setEnabled(false);
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);
1015 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
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);
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);
1031 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1032 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
1034 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
1038 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1039 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
1041 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
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);
1049 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
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);
1056 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
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));
1064 case "third_party_cookies":
1066 if (sharedPreferences.getBoolean("third_party_cookies", false)) {
1067 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
1069 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1070 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
1072 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
1079 if (sharedPreferences.getBoolean("dom_storage", false)) {
1080 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1082 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1083 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1085 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1090 // Save form data can be removed once the minimum API >= 26.
1091 case "save_form_data":
1093 if (sharedPreferences.getBoolean("save_form_data", false)) {
1094 formDataPreference.setIcon(R.drawable.form_data_enabled);
1096 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1097 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
1099 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
1105 // Get the new user agent name.
1106 String newUserAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
1108 // Get the array position for the new user agent name.
1109 int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName);
1111 // Get the translated new user agent name.
1112 String translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition];
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());
1120 // Disable the custom user agent preference.
1121 customUserAgentPreference.setEnabled(false);
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);
1127 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1131 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
1132 // Set the summary text.
1133 userAgentPreference.setSummary(R.string.custom_user_agent);
1135 // Enable the custom user agent preference.
1136 customUserAgentPreference.setEnabled(true);
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);
1142 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
1147 // Get the user agent summary from the user agent data array.
1148 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + userAgentDataArray[newUserAgentArrayPosition]);
1150 // Disable the custom user agent preference.
1151 customUserAgentPreference.setEnabled(false);
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);
1157 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
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)));
1167 case "incognito_mode":
1169 if (sharedPreferences.getBoolean("incognito_mode", false)) {
1170 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1171 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
1173 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
1176 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1177 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
1179 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
1184 case "do_not_track":
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);
1190 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_day);
1193 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1194 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_night);
1196 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_day);
1202 case "allow_screenshots":
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);
1208 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
1211 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1212 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
1214 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
1218 // Create an intent to restart Privacy Browser.
1219 Intent allowScreenshotsRestartIntent = getActivity().getParentActivityIntent();
1221 // Assert that the intent is not null to remove the lint error below.
1222 assert allowScreenshotsRestartIntent != null;
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);
1227 // Create a handler to restart the activity.
1228 Handler allowScreenshotsRestartHandler = new Handler();
1230 // Create a runnable to restart the activity.
1231 Runnable allowScreenshotsRestartRunnable = () -> {
1232 // Restart the activity.
1233 startActivity(allowScreenshotsRestartIntent);
1235 // Kill this instance of Privacy Browser. Otherwise, the app exhibits sporadic behavior after the restart.
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);
1245 if (sharedPreferences.getBoolean("easylist", true)) {
1246 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1247 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
1249 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
1252 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1253 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
1255 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
1262 if (sharedPreferences.getBoolean("easyprivacy", true)) {
1263 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1264 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1266 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1269 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1270 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1272 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1277 case "fanboys_annoyance_list":
1278 boolean currentFanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
1279 boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
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);
1287 // Update the Fanboy's social blocking list icon.
1288 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
1290 // Update the Fanboy's annoyance list icon.
1291 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
1293 // Update the Fanboy's social blocking list icon.
1294 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
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);
1301 // Update the Fanboy's social blocking list icon.
1302 if (currentFanboySocialBlockingList) {
1303 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1305 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1308 // Update the Fanboy's annoyance list icon.
1309 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_day);
1311 // Update the Fanboy's social blocking list icon.
1312 if (currentFanboySocialBlockingList) {
1313 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1315 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1320 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled.
1321 fanboySocialBlockingListPreference.setEnabled(!currentFanboyAnnoyanceList);
1324 case "fanboys_social_blocking_list":
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);
1330 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1333 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1334 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1336 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1343 if (sharedPreferences.getBoolean("ultralist", true)) {
1344 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1345 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
1347 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
1350 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1351 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
1353 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
1358 case "ultraprivacy":
1360 if (sharedPreferences.getBoolean("ultraprivacy", true)) {
1361 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1362 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1364 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1367 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1368 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1370 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1375 case "block_all_third_party_requests":
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);
1381 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
1384 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1385 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
1387 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
1392 case "google_analytics":
1394 if (sharedPreferences.getBoolean("google_analytics", true)) {
1395 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1396 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
1398 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
1401 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1402 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
1404 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
1409 case "facebook_click_ids":
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);
1415 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
1418 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1419 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
1421 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
1426 case "twitter_amp_redirects":
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);
1432 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
1435 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1436 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
1438 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
1444 // Store the new search string.
1445 String newSearchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
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);
1452 // Enable `searchCustomURLPreference`.
1453 searchCustomURLPreference.setEnabled(true);
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);
1459 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
1461 } else { // `Custom URL` is not selected.
1462 // Set the summary text to `newSearchString`.
1463 searchPreference.setSummary(newSearchString);
1465 // Disable `searchCustomURLPreference`.
1466 searchCustomURLPreference.setEnabled(false);
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);
1472 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
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)));
1483 // Get current proxy string.
1484 String currentProxyString = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value));
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));
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));
1496 proxyPreference.setSummary(getString(R.string.tor_enabled));
1500 case ProxyHelper.I2P:
1501 proxyPreference.setSummary(getString(R.string.i2p_enabled));
1504 case ProxyHelper.CUSTOM:
1505 proxyPreference.setSummary(getString(R.string.custom_proxy));
1509 // Update the status of the custom URL preference.
1510 proxyCustomUrlPreference.setEnabled(currentProxyString.equals("Custom"));
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);
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);
1524 // Set the custom proxy URL icon to be ghosted.
1525 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
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);
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);
1538 } else { // Light theme.
1539 // Set the main proxy icon to be enabled.
1540 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
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);
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)));
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);
1563 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
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);
1572 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
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);
1579 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
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);
1588 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
1589 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
1594 case "hide_app_bar":
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);
1601 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
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);
1608 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1613 case "clear_everything":
1614 // Store the new clear everything status
1615 boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true);
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);
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);
1629 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
1632 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
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);
1640 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1643 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
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);
1651 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1654 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
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);
1663 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1666 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
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);
1675 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1678 clearLogcatPreference.setIcon(R.drawable.cache_warning);
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);
1686 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1689 clearCachePreference.setIcon(R.drawable.cache_warning);
1693 case "clear_cookies":
1695 if (sharedPreferences.getBoolean("clear_cookies", true)) {
1696 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1697 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1699 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1702 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1706 case "clear_dom_storage":
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);
1712 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1715 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1719 // This section can be removed once the minimum API >= 26.
1720 case "clear_form_data":
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);
1726 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1729 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1733 case "clear_logcat":
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);
1739 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1742 clearLogcatPreference.setIcon(R.drawable.bug_warning);
1748 if (sharedPreferences.getBoolean("clear_cache", true)) {
1749 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1750 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1752 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1755 clearCachePreference.setIcon(R.drawable.cache_warning);
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)));
1764 case "download_location":
1765 // Get the new download location.
1766 String newDownloadLocationString = sharedPreferences.getString("download_location", getString(R.string.download_location_default_value));
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]);
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));
1779 // Disable the download custom location.
1780 downloadCustomLocationPreference.setEnabled(newDownloadLocationString.equals(downloadLocationEntryValuesStringArray[3]));
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);
1788 downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_day);
1791 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1792 downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_night);
1794 downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_day);
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)));
1805 // Update the font size summary text.
1806 fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
1809 case "open_intents_in_new_tab":
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);
1815 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
1818 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1819 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
1821 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
1826 case "swipe_to_refresh":
1828 if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
1829 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1830 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
1832 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
1835 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1836 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
1838 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
1843 case "scroll_app_bar":
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);
1849 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1852 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1853 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1855 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1860 case "display_additional_app_bar_icons":
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);
1866 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
1869 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1870 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
1872 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
1878 // Get the new theme.
1879 String newAppTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
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]);
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]);
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]);
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);
1908 // Update the current theme status.
1909 currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
1912 case "webview_theme":
1913 // Get the new WebView theme.
1914 String newWebViewTheme = sharedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
1916 // Define a new WebView theme entry number.
1917 int newWebViewThemeEntryNumber;
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;
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);
1938 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
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);
1946 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
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);
1954 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1959 // Set the current theme as the summary text for the preference.
1960 webViewThemePreference.setSummary(webViewThemeEntriesStringArray[newWebViewThemeEntryNumber]);
1963 case "wide_viewport":
1965 if (sharedPreferences.getBoolean("wide_viewport", true)) {
1966 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1967 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
1969 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
1972 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1973 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
1975 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
1980 case "display_webpage_images":
1982 if (sharedPreferences.getBoolean("display_webpage_images", true)) {
1983 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1984 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
1986 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
1989 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1990 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
1992 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
1999 // Register the listener.
2000 savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);
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.
2005 public void onPause() {
2007 savedPreferences.unregisterOnSharedPreferenceChangeListener(preferencesListener);
2011 public void onResume() {
2013 savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);