2 * Copyright © 2016-2021 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.os.Looper;
33 import android.view.LayoutInflater;
34 import android.view.View;
35 import android.webkit.WebView;
36 import android.widget.ArrayAdapter;
38 import androidx.appcompat.app.AppCompatDelegate;
39 import androidx.preference.Preference;
40 import androidx.preference.PreferenceCategory;
41 import androidx.preference.PreferenceFragmentCompat;
43 import com.stoutner.privacybrowser.R;
44 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
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 allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key));
84 Preference easyListPreference = findPreference("easylist");
85 Preference easyPrivacyPreference = findPreference("easyprivacy");
86 Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
87 Preference fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
88 Preference ultraListPreference = findPreference("ultralist");
89 Preference ultraPrivacyPreference = findPreference("ultraprivacy");
90 Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
91 Preference googleAnalyticsPreference = findPreference("google_analytics");
92 Preference facebookClickIdsPreference = findPreference("facebook_click_ids");
93 Preference twitterAmpRedirectsPreference = findPreference("twitter_amp_redirects");
94 Preference searchPreference = findPreference("search");
95 Preference searchCustomURLPreference = findPreference("search_custom_url");
96 Preference proxyPreference = findPreference("proxy");
97 Preference proxyCustomUrlPreference = findPreference("proxy_custom_url");
98 Preference fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
99 Preference hideAppBarPreference = findPreference("hide_app_bar");
100 Preference clearEverythingPreference = findPreference("clear_everything");
101 Preference clearCookiesPreference = findPreference("clear_cookies");
102 Preference clearDomStoragePreference = findPreference("clear_dom_storage");
103 Preference clearFormDataPreference = findPreference("clear_form_data"); // The clear form data preference can be removed once the minimum API >= 26.
104 Preference clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key));
105 Preference clearCachePreference = findPreference("clear_cache");
106 Preference homepagePreference = findPreference("homepage");
107 Preference fontSizePreference = findPreference("font_size");
108 Preference openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
109 Preference swipeToRefreshPreference = findPreference("swipe_to_refresh");
110 Preference scrollAppBarPreference = findPreference("scroll_app_bar");
111 Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons");
112 Preference appThemePreference = findPreference("app_theme");
113 Preference webViewThemePreference = findPreference("webview_theme");
114 Preference wideViewportPreference = findPreference("wide_viewport");
115 Preference displayWebpageImagesPreference = findPreference("display_webpage_images");
117 // Remove the lint warnings below that the preferences might be null.
118 assert javaScriptPreference != null;
119 assert firstPartyCookiesPreference != null;
120 assert thirdPartyCookiesPreference != null;
121 assert domStoragePreference != null;
122 assert formDataPreference != null;
123 assert userAgentPreference != null;
124 assert customUserAgentPreference != null;
125 assert incognitoModePreference != null;
126 assert allowScreenshotsPreference != null;
127 assert easyListPreference != null;
128 assert easyPrivacyPreference != null;
129 assert fanboyAnnoyanceListPreference != null;
130 assert fanboySocialBlockingListPreference != null;
131 assert ultraListPreference != null;
132 assert ultraPrivacyPreference != null;
133 assert blockAllThirdPartyRequestsPreference != null;
134 assert googleAnalyticsPreference != null;
135 assert facebookClickIdsPreference != null;
136 assert twitterAmpRedirectsPreference != null;
137 assert searchPreference != null;
138 assert searchCustomURLPreference != null;
139 assert proxyPreference != null;
140 assert proxyCustomUrlPreference != null;
141 assert fullScreenBrowsingModePreference != null;
142 assert hideAppBarPreference != null;
143 assert clearEverythingPreference != null;
144 assert clearCookiesPreference != null;
145 assert clearDomStoragePreference != null;
146 assert clearFormDataPreference != null;
147 assert clearLogcatPreference != null;
148 assert clearCachePreference != null;
149 assert homepagePreference != null;
150 assert fontSizePreference != null;
151 assert openIntentsInNewTabPreference != null;
152 assert swipeToRefreshPreference != null;
153 assert scrollAppBarPreference != null;
154 assert displayAdditionalAppBarIconsPreference != null;
155 assert appThemePreference != null;
156 assert webViewThemePreference != null;
157 assert wideViewportPreference != null;
158 assert displayWebpageImagesPreference != null;
160 // Set the preference dependencies.
161 hideAppBarPreference.setDependency("full_screen_browsing_mode");
162 domStoragePreference.setDependency("javascript");
164 // Get strings from the preferences.
165 String userAgentName = savedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
166 String searchString = savedPreferences.getString("search", getString(R.string.search_default_value));
167 String proxyString = savedPreferences.getString("proxy", getString(R.string.proxy_default_value));
169 // Get booleans that are used in multiple places from the preferences.
170 boolean javaScriptEnabled = savedPreferences.getBoolean("javascript", false);
171 boolean firstPartyCookiesEnabled = savedPreferences.getBoolean("first_party_cookies", false);
172 boolean fanboyAnnoyanceListEnabled = savedPreferences.getBoolean("fanboys_annoyance_list", true);
173 boolean fanboySocialBlockingEnabled = savedPreferences.getBoolean("fanboys_social_blocking_list", true);
174 boolean fullScreenBrowsingMode = savedPreferences.getBoolean("full_screen_browsing_mode", false);
175 boolean clearEverything = savedPreferences.getBoolean("clear_everything", true);
177 // Only enable the third-party cookies preference if first-party cookies are enabled and API >= 21.
178 thirdPartyCookiesPreference.setEnabled(firstPartyCookiesEnabled && (Build.VERSION.SDK_INT >= 21));
180 // Remove the form data preferences if the API is >= 26 as they no longer do anything.
181 if (Build.VERSION.SDK_INT >= 26) {
182 // Get handles for the categories.
183 PreferenceCategory privacyCategory = findPreference("privacy");
184 PreferenceCategory clearAndExitCategory = findPreference("clear_and_exit");
186 // Remove the incorrect lint warnings below that the preference categories might be null.
187 assert privacyCategory != null;
188 assert clearAndExitCategory != null;
190 // Remove the form data preferences.
191 privacyCategory.removePreference(formDataPreference);
192 clearAndExitCategory.removePreference(clearFormDataPreference);
195 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled.
196 fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled);
199 // Inflate a WebView to get the default user agent.
200 LayoutInflater inflater = getActivity().getLayoutInflater();
202 // `@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.
203 @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
205 // Get a handle for a bare WebView.
206 WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
208 // Get the user agent arrays.
209 ArrayAdapter<CharSequence> userAgentNamesArray = ArrayAdapter.createFromResource(context, R.array.user_agent_names, R.layout.spinner_item);
210 String[] translatedUserAgentNamesArray = resources.getStringArray(R.array.translated_user_agent_names);
211 String[] userAgentDataArray = resources.getStringArray(R.array.user_agent_data);
213 // Get the array position of the user agent name.
214 int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
216 // Populate the user agent summary.
217 switch (userAgentArrayPosition) {
218 case MainWebViewActivity.UNRECOGNIZED_USER_AGENT: // The user agent name is not on the canonical list.
219 // 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.
220 userAgentPreference.setSummary(userAgentName);
223 case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
224 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
225 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + bareWebView.getSettings().getUserAgentString());
228 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
229 // Set the summary text.
230 userAgentPreference.setSummary(R.string.custom_user_agent);
234 // Get the user agent summary from the user agent data array.
235 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + userAgentDataArray[userAgentArrayPosition]);
238 // Set the summary text for the custom user agent preference.
239 customUserAgentPreference.setSummary(savedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
241 // Only enable the custom user agent preference if the user agent is set to `Custom`.
242 customUserAgentPreference.setEnabled(userAgentPreference.getSummary().equals(getString(R.string.custom_user_agent)));
245 // Set the search URL as the summary text for the search preference when the preference screen is loaded.
246 if (searchString.equals("Custom URL")) {
247 // Use R.string.custom_url, which will be translated, instead of the array value, which will not.
248 searchPreference.setSummary(R.string.custom_url);
250 // Set the array value as the summary text.
251 searchPreference.setSummary(searchString);
254 // Set the summary text for the search custom URL (the default is `""`).
255 searchCustomURLPreference.setSummary(savedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
257 // Only enable the search custom URL preference if the search is set to `Custom URL`.
258 searchCustomURLPreference.setEnabled(searchString.equals("Custom URL"));
261 // Set the summary text for the proxy preference when the preference screen is loaded.
262 switch (proxyString) {
263 case ProxyHelper.NONE:
264 proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
267 case ProxyHelper.TOR:
268 if (Build.VERSION.SDK_INT == 19) { // Proxying through SOCKS doesn't work on Android KitKat.
269 proxyPreference.setSummary(getString(R.string.tor_enabled_kitkat));
271 proxyPreference.setSummary(getString(R.string.tor_enabled));
275 case ProxyHelper.I2P:
276 proxyPreference.setSummary(getString(R.string.i2p_enabled));
279 case ProxyHelper.CUSTOM:
280 proxyPreference.setSummary(getString(R.string.custom_proxy));
284 // Set the summary text for the custom proxy URL.
285 proxyCustomUrlPreference.setSummary(savedPreferences.getString("proxy_custom_url", getString(R.string.proxy_custom_url_default_value)));
287 // Only enable the custom proxy URL if a custom proxy is selected.
288 proxyCustomUrlPreference.setEnabled(proxyString.equals("Custom"));
291 // Set the status of the clear and exit preferences.
292 clearCookiesPreference.setEnabled(!clearEverything);
293 clearDomStoragePreference.setEnabled(!clearEverything);
294 clearFormDataPreference.setEnabled(!clearEverything); // The form data line can be removed once the minimum API is >= 26.
295 clearLogcatPreference.setEnabled(!clearEverything);
296 clearCachePreference.setEnabled(!clearEverything);
299 // Set the homepage URL as the summary text for the homepage preference.
300 homepagePreference.setSummary(savedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
303 // Set the font size as the summary text for the preference.
304 fontSizePreference.setSummary(savedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
307 // Get the app theme string arrays.
308 String[] appThemeEntriesStringArray = resources.getStringArray(R.array.app_theme_entries);
309 String[] appThemeEntryValuesStringArray = resources.getStringArray(R.array.app_theme_entry_values);
311 // Get the current app theme.
312 String currentAppTheme = savedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
314 // Define an app theme entry number.
315 int appThemeEntryNumber;
317 // 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.
318 if (currentAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected.
319 // Store the app theme entry number.
320 appThemeEntryNumber = 1;
321 } else if (currentAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected.
322 // Store the app theme entry number.
323 appThemeEntryNumber = 2;
324 } else { // The system default theme is selected.
325 // Store the app theme entry number.
326 appThemeEntryNumber = 0;
329 // Set the current theme as the summary text for the preference.
330 appThemePreference.setSummary(appThemeEntriesStringArray[appThemeEntryNumber]);
333 // Get the WebView theme string arrays.
334 String[] webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries);
335 String[] webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values);
337 // Get the current WebView theme.
338 String currentWebViewTheme = savedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
340 // Define a WebView theme entry number.
341 int webViewThemeEntryNumber;
343 // 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.
344 if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[1])) { // The light theme is selected.
345 // Store the WebView theme entry number.
346 webViewThemeEntryNumber = 1;
347 } else if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
348 // Store the WebView theme entry number.
349 webViewThemeEntryNumber = 2;
350 } else { // The system default theme is selected.
351 // Store the WebView theme entry number.
352 webViewThemeEntryNumber = 0;
355 // Set the visibility of the WebView theme preference.
356 if (Build.VERSION.SDK_INT < 21) { // The device is running API 19.
357 // Get a handle for the general category.
358 PreferenceCategory generalCategory = findPreference("general");
360 // Remove the incorrect lint warning below that the general preference category might be null.
361 assert generalCategory != null;
363 // Remove the WebView theme preference.
364 generalCategory.removePreference(webViewThemePreference);
365 } else { // The device is running API >= 21
366 // Set the current theme as the summary text for the preference.
367 webViewThemePreference.setSummary(webViewThemeEntriesStringArray[webViewThemeEntryNumber]);
371 // Set the JavaScript icon.
372 if (javaScriptEnabled) {
373 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
375 javaScriptPreference.setIcon(R.drawable.privacy_mode);
378 // Set the first-party cookies icon.
379 if (firstPartyCookiesEnabled) {
380 firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
382 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
383 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
385 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
389 // Set the third party cookies icon.
390 if (firstPartyCookiesEnabled && Build.VERSION.SDK_INT >= 21) {
391 if (savedPreferences.getBoolean("third_party_cookies", false)) {
392 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
394 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
395 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
397 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
401 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
402 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
404 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
408 // Set the DOM storage icon.
409 if (javaScriptEnabled) { // The preference is enabled.
410 if (savedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled.
411 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
412 } else { // DOM storage is disabled.
413 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
414 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
416 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
419 } else { // The preference is disabled. The icon should be ghosted.
420 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
421 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
423 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
427 // Set the save form data icon if API < 26. Save form data has no effect on API >= 26.
428 if (Build.VERSION.SDK_INT < 26) {
429 if (savedPreferences.getBoolean("save_form_data", false)) {
430 formDataPreference.setIcon(R.drawable.form_data_enabled);
432 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
433 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
435 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
440 // Set the custom user agent icon.
441 if (customUserAgentPreference.isEnabled()) {
442 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
443 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
445 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
448 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
449 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
451 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
455 // Set the incognito mode icon.
456 if (savedPreferences.getBoolean("incognito_mode", false)) {
457 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
458 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
460 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
463 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
464 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
466 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
470 // Set the allow screenshots icon.
471 if (savedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) {
472 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
473 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
475 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
478 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
479 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
481 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
485 // Set the EasyList icon.
486 if (savedPreferences.getBoolean("easylist", true)) {
487 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
488 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
490 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
493 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
494 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
496 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
500 // Set the EasyPrivacy icon.
501 if (savedPreferences.getBoolean("easyprivacy", true)) {
502 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
503 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
505 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
508 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
509 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
511 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
515 // Set the Fanboy lists icons.
516 if (fanboyAnnoyanceListEnabled) {
517 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
518 // Set the Fanboy annoyance list icon.
519 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
521 // Set the Fanboy social blocking list icon.
522 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
524 // Set the Fanboy annoyance list icon.
525 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
527 // Set the Fanboy social blocking list icon.
528 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
531 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
532 // Set the Fanboy annoyance list icon.
533 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
535 // Set the Fanboy social blocking list icon.
536 if (fanboySocialBlockingEnabled) {
537 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
539 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
542 // Set the Fanboy annoyance list icon.
543 fanboyAnnoyanceListPreference.setIcon(R.drawable.block_ads_disabled_day);
545 // Set the Fanboy social blocking list icon.
546 if (fanboySocialBlockingEnabled) {
547 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
549 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
554 // Set the UltraList icon.
555 if (savedPreferences.getBoolean("ultralist", true)){
556 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
557 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
559 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
562 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
563 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
565 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
569 // Set the UltraPrivacy icon.
570 if (savedPreferences.getBoolean("ultraprivacy", true)) {
571 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
572 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
574 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
577 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
578 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
580 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
584 // Set the block all third-party requests icon.
585 if (savedPreferences.getBoolean("block_all_third_party_requests", false)) {
586 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
587 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
589 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
592 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
593 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
595 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
599 // Set the Google Analytics icon according to the theme.
600 if (savedPreferences.getBoolean("google_analytics", true)) {
601 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
602 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
604 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
607 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
608 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
610 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
614 // Set the Facebook Click IDs icon according to the theme.
615 if (savedPreferences.getBoolean("facebook_click_ids", true)) {
616 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
617 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
619 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
622 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
623 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
625 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
629 // Set the Twitter AMP redirects icon according to the theme.
630 if (savedPreferences.getBoolean("twitter_amp_redirects", true)) {
631 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
632 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
634 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
637 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
638 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
640 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
644 // Set the search custom URL icon.
645 if (searchCustomURLPreference.isEnabled()) {
646 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
647 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
649 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
652 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
653 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
655 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
659 // Set the Proxy icons according to the theme and status.
660 if (proxyString.equals("None")) { // Proxying is disabled.
661 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
662 // Set the main proxy icon to be disabled.
663 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
665 // Set the custom proxy URL icon to be ghosted.
666 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
667 } else { // Light theme.
668 // Set the main proxy icon to be disabled.
669 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
671 // Set the custom proxy URL icon to be ghosted.
672 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
674 } else { // Proxying is enabled.
675 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
676 // Set the main proxy icon to be enabled.
677 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
679 // Set the custom proxy URL icon according to its status.
680 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
681 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
682 } else { // Custom proxy is disabled.
683 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
685 } else { // Light theme.
686 // Set the main proxy icon to be enabled.
687 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
689 // Set the custom proxy URL icon according to its status.
690 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
691 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
692 } else { // Custom proxy is disabled.
693 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
698 // Set the full screen browsing mode icons.
699 if (fullScreenBrowsingMode) { // Full screen browsing mode is enabled.
700 // Set the `fullScreenBrowsingModePreference` icon according to the theme.
701 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
702 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
704 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
707 // Set the hide app bar icon.
708 if (savedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
709 // Set the icon according to the theme.
710 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
711 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
713 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
715 } else { // Hide app bar is disabled.
716 // Set the icon according to the theme.
717 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
718 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
720 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
723 } else { // Full screen browsing mode is disabled.
724 // Set the icons according to the theme.
725 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
726 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
727 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
729 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
730 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
734 // Set the clear everything preference icon.
735 if (clearEverything) {
736 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
737 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
739 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
742 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
745 // Set the clear cookies preference icon.
746 if (clearEverything || savedPreferences.getBoolean("clear_cookies", true)) {
747 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
748 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
750 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
753 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
756 // Set the clear DOM storage preference icon.
757 if (clearEverything || savedPreferences.getBoolean("clear_dom_storage", true)) {
758 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
759 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
761 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
764 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
767 // Set the clear form data preference icon if the API < 26. It has no effect on newer versions of Android.
768 if (Build.VERSION.SDK_INT < 26) {
769 if (clearEverything || savedPreferences.getBoolean("clear_form_data", true)) {
770 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
771 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
773 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
776 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
780 // Set the clear logcat preference icon.
781 if (clearEverything || savedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
782 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
783 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
785 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
788 clearLogcatPreference.setIcon(R.drawable.bug_warning);
791 // Set the clear cache preference icon.
792 if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) {
793 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
794 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
796 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
799 clearCachePreference.setIcon(R.drawable.cache_warning);
802 // Set the open intents in new tab preference icon.
803 if (savedPreferences.getBoolean("open_intents_in_new_tab", true)) {
804 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
805 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
807 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
810 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
811 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
813 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
817 // Set the swipe to refresh preference icon.
818 if (savedPreferences.getBoolean("swipe_to_refresh", true)) {
819 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
820 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
822 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
825 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
826 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
828 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
832 // Set the scroll app bar preference icon.
833 if (savedPreferences.getBoolean("scroll_app_bar", true)) {
834 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
835 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
837 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
840 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
841 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
843 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
847 // Set the display additional app bar icons preference icon.
848 if (savedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
849 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
850 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
852 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
855 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
856 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
858 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
862 // Set the WebView theme preference icon.
863 switch (webViewThemeEntryNumber) {
864 case 0: // The system default WebView theme is selected.
865 // Set the icon according to the app theme.
866 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
867 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
869 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
873 case 1: // The light WebView theme is selected.
874 // Set the icon according to the app theme.
875 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
876 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
878 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
882 case 2: // The dark WebView theme is selected.
883 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
884 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
886 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
891 // Set the wide viewport preference icon.
892 if (savedPreferences.getBoolean("wide_viewport", true)) {
893 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
894 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
896 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
899 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
900 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
902 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
906 // Set the display webpage images preference icon.
907 if (savedPreferences.getBoolean("display_webpage_images", true)) {
908 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
909 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
911 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
914 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
915 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
917 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
922 // Listen for preference changes.
923 preferencesListener = (SharedPreferences sharedPreferences, String key) -> {
926 // Update the icons and the DOM storage preference status.
927 if (sharedPreferences.getBoolean("javascript", false)) { // The JavaScript preference is enabled.
928 // Update the icon for the JavaScript preference.
929 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
931 // Update the status of the DOM storage preference.
932 domStoragePreference.setEnabled(true);
934 // Update the icon for the DOM storage preference.
935 if (sharedPreferences.getBoolean("dom_storage", false)) {
936 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
938 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
939 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
941 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
944 } else { // The JavaScript preference is disabled.
945 // Update the icon for the JavaScript preference.
946 javaScriptPreference.setIcon(R.drawable.privacy_mode);
948 // Update the status of the DOM storage preference.
949 domStoragePreference.setEnabled(false);
951 // Set the icon for DOM storage preference to be ghosted.
952 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
953 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
955 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
960 case "first_party_cookies":
961 // Update the icons for `first_party_cookies` and `third_party_cookies`.
962 if (sharedPreferences.getBoolean("first_party_cookies", false)) {
963 // Set the icon for `first_party_cookies`.
964 firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
966 // Update the icon for `third_party_cookies`.
967 if (Build.VERSION.SDK_INT >= 21) {
968 if (sharedPreferences.getBoolean("third_party_cookies", false)) {
969 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
971 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
972 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
974 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
978 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
979 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
981 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
984 } else { // `first_party_cookies` is `false`.
985 // Update the icon for `first_party_cookies`.
986 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
987 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
989 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
992 // Set the icon for `third_party_cookies` to be ghosted.
993 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
994 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
996 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
1000 // Enable `third_party_cookies` if `first_party_cookies` is `true` and API >= 21.
1001 thirdPartyCookiesPreference.setEnabled(sharedPreferences.getBoolean("first_party_cookies", false) && (Build.VERSION.SDK_INT >= 21));
1004 case "third_party_cookies":
1006 if (sharedPreferences.getBoolean("third_party_cookies", false)) {
1007 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
1009 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1010 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
1012 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
1019 if (sharedPreferences.getBoolean("dom_storage", false)) {
1020 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1022 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1023 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1025 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1030 // Save form data can be removed once the minimum API >= 26.
1031 case "save_form_data":
1033 if (sharedPreferences.getBoolean("save_form_data", false)) {
1034 formDataPreference.setIcon(R.drawable.form_data_enabled);
1036 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1037 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
1039 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
1045 // Get the new user agent name.
1046 String newUserAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
1048 // Get the array position for the new user agent name.
1049 int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName);
1051 // Get the translated new user agent name.
1052 String translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition];
1054 // Populate the user agent summary.
1055 switch (newUserAgentArrayPosition) {
1056 case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
1057 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
1058 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + bareWebView.getSettings().getUserAgentString());
1060 // Disable the custom user agent preference.
1061 customUserAgentPreference.setEnabled(false);
1063 // Set the custom user agent preference icon according to the theme.
1064 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1065 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1067 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1071 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
1072 // Set the summary text.
1073 userAgentPreference.setSummary(R.string.custom_user_agent);
1075 // Enable the custom user agent preference.
1076 customUserAgentPreference.setEnabled(true);
1078 // Set the custom user agent preference icon according to the theme.
1079 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1080 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
1082 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
1087 // Get the user agent summary from the user agent data array.
1088 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + userAgentDataArray[newUserAgentArrayPosition]);
1090 // Disable the custom user agent preference.
1091 customUserAgentPreference.setEnabled(false);
1093 // Set the custom user agent preference icon according to the theme.
1094 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1095 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1097 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1102 case "custom_user_agent":
1103 // Set the new custom user agent as the summary text for the preference.
1104 customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
1107 case "incognito_mode":
1109 if (sharedPreferences.getBoolean("incognito_mode", false)) {
1110 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1111 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
1113 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
1116 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1117 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
1119 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
1124 case "allow_screenshots":
1126 if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) {
1127 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1128 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
1130 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
1133 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1134 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
1136 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
1140 // Create an intent to restart Privacy Browser.
1141 Intent allowScreenshotsRestartIntent = getActivity().getParentActivityIntent();
1143 // Assert that the intent is not null to remove the lint error below.
1144 assert allowScreenshotsRestartIntent != null;
1146 // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack. It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
1147 allowScreenshotsRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
1149 // Create a handler to restart the activity.
1150 Handler allowScreenshotsRestartHandler = new Handler(Looper.getMainLooper());
1152 // Create a runnable to restart the activity.
1153 Runnable allowScreenshotsRestartRunnable = () -> {
1154 // Restart the activity.
1155 startActivity(allowScreenshotsRestartIntent);
1157 // Kill this instance of Privacy Browser. Otherwise, the app exhibits sporadic behavior after the restart.
1161 // Restart the activity after 150 milliseconds, so that the app has enough time to save the change to the preference.
1162 allowScreenshotsRestartHandler.postDelayed(allowScreenshotsRestartRunnable, 150);
1167 if (sharedPreferences.getBoolean("easylist", true)) {
1168 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1169 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
1171 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
1174 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1175 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
1177 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
1184 if (sharedPreferences.getBoolean("easyprivacy", true)) {
1185 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1186 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1188 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1191 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1192 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1194 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1199 case "fanboys_annoyance_list":
1200 boolean currentFanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
1201 boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
1203 // Update the Fanboy icons.
1204 if (currentFanboyAnnoyanceList) { // Fanboy's annoyance list is enabled.
1205 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1206 // Update the Fanboy's annoyance list icon.
1207 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
1209 // Update the Fanboy's social blocking list icon.
1210 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
1212 // Update the Fanboy's annoyance list icon.
1213 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
1215 // Update the Fanboy's social blocking list icon.
1216 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
1218 } else { // Fanboy's annoyance list is disabled.
1219 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1220 // Update the Fanboy's annoyance list icon.
1221 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
1223 // Update the Fanboy's social blocking list icon.
1224 if (currentFanboySocialBlockingList) {
1225 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1227 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1230 // Update the Fanboy's annoyance list icon.
1231 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_day);
1233 // Update the Fanboy's social blocking list icon.
1234 if (currentFanboySocialBlockingList) {
1235 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1237 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1242 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled.
1243 fanboySocialBlockingListPreference.setEnabled(!currentFanboyAnnoyanceList);
1246 case "fanboys_social_blocking_list":
1248 if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) {
1249 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1250 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1252 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1255 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1256 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1258 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1265 if (sharedPreferences.getBoolean("ultralist", true)) {
1266 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1267 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
1269 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
1272 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1273 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
1275 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
1280 case "ultraprivacy":
1282 if (sharedPreferences.getBoolean("ultraprivacy", true)) {
1283 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1284 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1286 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1289 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1290 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1292 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1297 case "block_all_third_party_requests":
1299 if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
1300 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1301 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
1303 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
1306 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1307 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
1309 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
1314 case "google_analytics":
1316 if (sharedPreferences.getBoolean("google_analytics", true)) {
1317 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1318 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
1320 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
1323 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1324 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
1326 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
1331 case "facebook_click_ids":
1333 if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
1334 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1335 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
1337 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
1340 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1341 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
1343 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
1348 case "twitter_amp_redirects":
1350 if (sharedPreferences.getBoolean("twitter_amp_redirects", true)) {
1351 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1352 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
1354 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
1357 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1358 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
1360 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
1366 // Store the new search string.
1367 String newSearchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
1369 // Update the search and search custom URL preferences.
1370 if (newSearchString.equals("Custom URL")) { // `Custom URL` is selected.
1371 // Set the summary text to `R.string.custom_url`, which is translated.
1372 searchPreference.setSummary(R.string.custom_url);
1374 // Enable `searchCustomURLPreference`.
1375 searchCustomURLPreference.setEnabled(true);
1377 // Set the `searchCustomURLPreference` according to the theme.
1378 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1379 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
1381 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
1383 } else { // `Custom URL` is not selected.
1384 // Set the summary text to `newSearchString`.
1385 searchPreference.setSummary(newSearchString);
1387 // Disable `searchCustomURLPreference`.
1388 searchCustomURLPreference.setEnabled(false);
1390 // Set the `searchCustomURLPreference` according to the theme.
1391 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1392 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
1394 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
1399 case "search_custom_url":
1400 // Set the new search custom URL as the summary text for the preference.
1401 searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
1405 // Get current proxy string.
1406 String currentProxyString = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value));
1408 // Update the summary text for the proxy preference.
1409 switch (currentProxyString) {
1410 case ProxyHelper.NONE:
1411 proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
1414 case ProxyHelper.TOR:
1415 if (Build.VERSION.SDK_INT == 19) { // Proxying through SOCKS doesn't work on Android KitKat.
1416 proxyPreference.setSummary(getString(R.string.tor_enabled_kitkat));
1418 proxyPreference.setSummary(getString(R.string.tor_enabled));
1422 case ProxyHelper.I2P:
1423 proxyPreference.setSummary(getString(R.string.i2p_enabled));
1426 case ProxyHelper.CUSTOM:
1427 proxyPreference.setSummary(getString(R.string.custom_proxy));
1431 // Update the status of the custom URL preference.
1432 proxyCustomUrlPreference.setEnabled(currentProxyString.equals("Custom"));
1434 // Update the icons.
1435 if (currentProxyString.equals("None")) { // Proxying is disabled.
1436 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
1437 // Set the main proxy icon to be disabled
1438 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
1440 // Set the custom proxy URL icon to be ghosted.
1441 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1442 } else { // Light theme.
1443 // Set the main proxy icon to be disabled.
1444 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
1446 // Set the custom proxy URL icon to be ghosted.
1447 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1449 } else { // Proxying is enabled.
1450 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
1451 // Set the main proxy icon to be enabled.
1452 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
1454 /// Set the custom proxy URL icon according to its status.
1455 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
1456 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
1457 } else { // Custom proxy is disabled.
1458 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1460 } else { // Light theme.
1461 // Set the main proxy icon to be enabled.
1462 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
1464 // Set the custom proxy URL icon according to its status.
1465 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
1466 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
1467 } else { // Custom proxy is disabled.
1468 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1474 case "proxy_custom_url":
1475 // Set the summary text for the proxy custom URL.
1476 proxyCustomUrlPreference.setSummary(sharedPreferences.getString("proxy_custom_url", getString(R.string.proxy_custom_url_default_value)));
1479 case "full_screen_browsing_mode":
1480 if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) { // Full screen browsing is enabled.
1481 // Set the full screen browsing mode preference icon according to the theme.
1482 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1483 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
1485 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
1488 // Set the hide app bar preference icon.
1489 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
1490 // Set the icon according to the theme.
1491 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1492 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1494 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1496 } else { // Hide app bar is disabled.
1497 // Set the icon according to the theme.
1498 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1499 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1501 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1504 } else { // Full screen browsing is disabled.
1505 // Update the icons according to the theme.
1506 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1507 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
1508 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
1510 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
1511 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
1516 case "hide_app_bar":
1518 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
1519 // Set the icon according to the theme.
1520 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1521 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1523 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1525 } else { // Hide app bar is disabled.
1526 // Set the icon according to the theme.
1527 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1528 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1530 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1535 case "clear_everything":
1536 // Store the new clear everything status
1537 boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true);
1539 // Update the status of the clear and exit preferences.
1540 clearCookiesPreference.setEnabled(!newClearEverythingBoolean);
1541 clearDomStoragePreference.setEnabled(!newClearEverythingBoolean);
1542 clearFormDataPreference.setEnabled(!newClearEverythingBoolean); // This line can be removed once the minimum API >= 26.
1543 clearLogcatPreference.setEnabled(!newClearEverythingBoolean);
1544 clearCachePreference.setEnabled(!newClearEverythingBoolean);
1546 // Update the clear everything preference icon.
1547 if (newClearEverythingBoolean) {
1548 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1549 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
1551 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
1554 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
1557 // Update the clear cookies preference icon.
1558 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) {
1559 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1560 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1562 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1565 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1568 // Update the clear dom storage preference icon.
1569 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) {
1570 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1571 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1573 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1576 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1579 // Update the clear form data preference icon if the API < 26.
1580 if (Build.VERSION.SDK_INT < 26) {
1581 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) {
1582 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1583 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1585 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1588 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1592 // Update the clear logcat preference icon.
1593 if (newClearEverythingBoolean || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
1594 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1595 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1597 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1600 clearLogcatPreference.setIcon(R.drawable.cache_warning);
1603 // Update the clear cache preference icon.
1604 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) {
1605 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1606 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1608 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1611 clearCachePreference.setIcon(R.drawable.cache_warning);
1615 case "clear_cookies":
1617 if (sharedPreferences.getBoolean("clear_cookies", true)) {
1618 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1619 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1621 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1624 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1628 case "clear_dom_storage":
1630 if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
1631 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1632 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1634 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1637 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1641 // This section can be removed once the minimum API >= 26.
1642 case "clear_form_data":
1644 if (sharedPreferences.getBoolean("clear_form_data", true)) {
1645 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1646 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1648 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1651 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1655 case "clear_logcat":
1657 if (sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
1658 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1659 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1661 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1664 clearLogcatPreference.setIcon(R.drawable.bug_warning);
1670 if (sharedPreferences.getBoolean("clear_cache", true)) {
1671 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1672 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1674 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1677 clearCachePreference.setIcon(R.drawable.cache_warning);
1682 // Set the new homepage URL as the summary text for the Homepage preference.
1683 homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
1687 // Update the font size summary text.
1688 fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
1691 case "open_intents_in_new_tab":
1693 if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
1694 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1695 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
1697 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
1700 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1701 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
1703 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
1708 case "swipe_to_refresh":
1710 if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
1711 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1712 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
1714 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
1717 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1718 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
1720 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
1725 case "scroll_app_bar":
1727 if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
1728 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1729 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1731 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1734 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1735 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1737 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1742 case "display_additional_app_bar_icons":
1744 if (sharedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
1745 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1746 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
1748 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
1751 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1752 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
1754 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
1760 // Get the new theme.
1761 String newAppTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
1763 // 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.
1764 if (newAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected.
1765 // Update the theme preference summary text.
1766 appThemePreference.setSummary(appThemeEntriesStringArray[1]);
1768 // Apply the new theme.
1769 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
1770 } else if (newAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected.
1771 // Update the theme preference summary text.
1772 appThemePreference.setSummary(appThemeEntriesStringArray[2]);
1774 // Apply the new theme.
1775 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
1776 } else { // The system default theme is selected.
1777 // Update the theme preference summary text.
1778 appThemePreference.setSummary(appThemeEntriesStringArray[0]);
1780 // Apply the new theme.
1781 if (Build.VERSION.SDK_INT >= 28) { // The system default theme is supported.
1782 // Follow the system default theme.
1783 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
1784 } else {// The system default theme is not supported.
1785 // Follow the battery saver mode.
1786 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
1790 // Update the current theme status.
1791 currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
1794 case "webview_theme":
1795 // Get the new WebView theme.
1796 String newWebViewTheme = sharedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
1798 // Define a new WebView theme entry number.
1799 int newWebViewThemeEntryNumber;
1801 // 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.
1802 if (newWebViewTheme.equals(webViewThemeEntriesStringArray[1])) { // The light theme is selected.
1803 // Store the new WebView theme entry number.
1804 newWebViewThemeEntryNumber = 1;
1805 } else if (newWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
1806 // Store the WebView theme entry number.
1807 newWebViewThemeEntryNumber = 2;
1808 } else { // The system default theme is selected.
1809 // Store the WebView theme entry number.
1810 newWebViewThemeEntryNumber = 0;
1814 switch (newWebViewThemeEntryNumber) {
1815 case 0: // The system default WebView theme is selected.
1816 // Set the icon according to the app theme.
1817 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1818 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1820 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1824 case 1: // The system default WebView theme is selected.
1825 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1826 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1828 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
1832 case 2: // The system default WebView theme is selected.
1833 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1834 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
1836 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1841 // Set the current theme as the summary text for the preference.
1842 webViewThemePreference.setSummary(webViewThemeEntriesStringArray[newWebViewThemeEntryNumber]);
1845 case "wide_viewport":
1847 if (sharedPreferences.getBoolean("wide_viewport", true)) {
1848 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1849 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
1851 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
1854 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1855 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
1857 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
1862 case "display_webpage_images":
1864 if (sharedPreferences.getBoolean("display_webpage_images", true)) {
1865 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1866 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
1868 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
1871 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1872 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
1874 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
1881 // Register the listener.
1882 savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);
1885 // 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.
1887 public void onPause() {
1889 savedPreferences.unregisterOnSharedPreferenceChangeListener(preferencesListener);
1893 public void onResume() {
1895 savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);