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 cookiesPreference = findPreference(getString(R.string.cookies_key));
77 Preference domStoragePreference = findPreference("dom_storage");
78 Preference formDataPreference = findPreference("save_form_data"); // The form data preference can be removed once the minimum API >= 26.
79 Preference userAgentPreference = findPreference("user_agent");
80 Preference customUserAgentPreference = findPreference("custom_user_agent");
81 Preference incognitoModePreference = findPreference("incognito_mode");
82 Preference allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key));
83 Preference easyListPreference = findPreference("easylist");
84 Preference easyPrivacyPreference = findPreference("easyprivacy");
85 Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
86 Preference fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
87 Preference ultraListPreference = findPreference("ultralist");
88 Preference ultraPrivacyPreference = findPreference("ultraprivacy");
89 Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
90 Preference googleAnalyticsPreference = findPreference("google_analytics");
91 Preference facebookClickIdsPreference = findPreference("facebook_click_ids");
92 Preference twitterAmpRedirectsPreference = findPreference("twitter_amp_redirects");
93 Preference searchPreference = findPreference("search");
94 Preference searchCustomURLPreference = findPreference("search_custom_url");
95 Preference proxyPreference = findPreference("proxy");
96 Preference proxyCustomUrlPreference = findPreference("proxy_custom_url");
97 Preference fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
98 Preference hideAppBarPreference = findPreference("hide_app_bar");
99 Preference clearEverythingPreference = findPreference("clear_everything");
100 Preference clearCookiesPreference = findPreference("clear_cookies");
101 Preference clearDomStoragePreference = findPreference("clear_dom_storage");
102 Preference clearFormDataPreference = findPreference("clear_form_data"); // The clear form data preference can be removed once the minimum API >= 26.
103 Preference clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key));
104 Preference clearCachePreference = findPreference("clear_cache");
105 Preference homepagePreference = findPreference("homepage");
106 Preference fontSizePreference = findPreference("font_size");
107 Preference openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
108 Preference swipeToRefreshPreference = findPreference("swipe_to_refresh");
109 Preference scrollAppBarPreference = findPreference("scroll_app_bar");
110 Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons");
111 Preference appThemePreference = findPreference("app_theme");
112 Preference webViewThemePreference = findPreference("webview_theme");
113 Preference wideViewportPreference = findPreference("wide_viewport");
114 Preference displayWebpageImagesPreference = findPreference("display_webpage_images");
116 // Remove the lint warnings below that the preferences might be null.
117 assert javaScriptPreference != null;
118 assert cookiesPreference != null;
119 assert domStoragePreference != null;
120 assert formDataPreference != null;
121 assert userAgentPreference != null;
122 assert customUserAgentPreference != null;
123 assert incognitoModePreference != null;
124 assert allowScreenshotsPreference != null;
125 assert easyListPreference != null;
126 assert easyPrivacyPreference != null;
127 assert fanboyAnnoyanceListPreference != null;
128 assert fanboySocialBlockingListPreference != null;
129 assert ultraListPreference != null;
130 assert ultraPrivacyPreference != null;
131 assert blockAllThirdPartyRequestsPreference != null;
132 assert googleAnalyticsPreference != null;
133 assert facebookClickIdsPreference != null;
134 assert twitterAmpRedirectsPreference != null;
135 assert searchPreference != null;
136 assert searchCustomURLPreference != null;
137 assert proxyPreference != null;
138 assert proxyCustomUrlPreference != null;
139 assert fullScreenBrowsingModePreference != null;
140 assert hideAppBarPreference != null;
141 assert clearEverythingPreference != null;
142 assert clearCookiesPreference != null;
143 assert clearDomStoragePreference != null;
144 assert clearFormDataPreference != null;
145 assert clearLogcatPreference != null;
146 assert clearCachePreference != null;
147 assert homepagePreference != null;
148 assert fontSizePreference != null;
149 assert openIntentsInNewTabPreference != null;
150 assert swipeToRefreshPreference != null;
151 assert scrollAppBarPreference != null;
152 assert displayAdditionalAppBarIconsPreference != null;
153 assert appThemePreference != null;
154 assert webViewThemePreference != null;
155 assert wideViewportPreference != null;
156 assert displayWebpageImagesPreference != null;
158 // Set the preference dependencies.
159 hideAppBarPreference.setDependency("full_screen_browsing_mode");
160 domStoragePreference.setDependency("javascript");
162 // Get strings from the preferences.
163 String userAgentName = savedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
164 String searchString = savedPreferences.getString("search", getString(R.string.search_default_value));
165 String proxyString = savedPreferences.getString("proxy", getString(R.string.proxy_default_value));
167 // Get booleans that are used in multiple places from the preferences.
168 boolean javaScriptEnabled = savedPreferences.getBoolean("javascript", false);
169 boolean fanboyAnnoyanceListEnabled = savedPreferences.getBoolean("fanboys_annoyance_list", true);
170 boolean fanboySocialBlockingEnabled = savedPreferences.getBoolean("fanboys_social_blocking_list", true);
171 boolean fullScreenBrowsingMode = savedPreferences.getBoolean("full_screen_browsing_mode", false);
172 boolean clearEverything = savedPreferences.getBoolean("clear_everything", true);
174 // Remove the form data preferences if the API is >= 26 as they no longer do anything.
175 if (Build.VERSION.SDK_INT >= 26) {
176 // Get handles for the categories.
177 PreferenceCategory privacyCategory = findPreference("privacy");
178 PreferenceCategory clearAndExitCategory = findPreference("clear_and_exit");
180 // Remove the incorrect lint warnings below that the preference categories might be null.
181 assert privacyCategory != null;
182 assert clearAndExitCategory != null;
184 // Remove the form data preferences.
185 privacyCategory.removePreference(formDataPreference);
186 clearAndExitCategory.removePreference(clearFormDataPreference);
189 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled.
190 fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled);
193 // Inflate a WebView to get the default user agent.
194 LayoutInflater inflater = getActivity().getLayoutInflater();
196 // `@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.
197 @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
199 // Get a handle for a bare WebView.
200 WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
202 // Get the user agent arrays.
203 ArrayAdapter<CharSequence> userAgentNamesArray = ArrayAdapter.createFromResource(context, R.array.user_agent_names, R.layout.spinner_item);
204 String[] translatedUserAgentNamesArray = resources.getStringArray(R.array.translated_user_agent_names);
205 String[] userAgentDataArray = resources.getStringArray(R.array.user_agent_data);
207 // Get the array position of the user agent name.
208 int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
210 // Populate the user agent summary.
211 switch (userAgentArrayPosition) {
212 case MainWebViewActivity.UNRECOGNIZED_USER_AGENT: // The user agent name is not on the canonical list.
213 // 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.
214 userAgentPreference.setSummary(userAgentName);
217 case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
218 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
219 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + bareWebView.getSettings().getUserAgentString());
222 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
223 // Set the summary text.
224 userAgentPreference.setSummary(R.string.custom_user_agent);
228 // Get the user agent summary from the user agent data array.
229 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + userAgentDataArray[userAgentArrayPosition]);
232 // Set the summary text for the custom user agent preference.
233 customUserAgentPreference.setSummary(savedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
235 // Only enable the custom user agent preference if the user agent is set to `Custom`.
236 customUserAgentPreference.setEnabled(userAgentPreference.getSummary().equals(getString(R.string.custom_user_agent)));
239 // Set the search URL as the summary text for the search preference when the preference screen is loaded.
240 if (searchString.equals("Custom URL")) {
241 // Use R.string.custom_url, which will be translated, instead of the array value, which will not.
242 searchPreference.setSummary(R.string.custom_url);
244 // Set the array value as the summary text.
245 searchPreference.setSummary(searchString);
248 // Set the summary text for the search custom URL (the default is `""`).
249 searchCustomURLPreference.setSummary(savedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
251 // Only enable the search custom URL preference if the search is set to `Custom URL`.
252 searchCustomURLPreference.setEnabled(searchString.equals("Custom URL"));
255 // Set the summary text for the proxy preference when the preference screen is loaded.
256 switch (proxyString) {
257 case ProxyHelper.NONE:
258 proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
261 case ProxyHelper.TOR:
262 if (Build.VERSION.SDK_INT == 19) { // Proxying through SOCKS doesn't work on Android KitKat.
263 proxyPreference.setSummary(getString(R.string.tor_enabled_kitkat));
265 proxyPreference.setSummary(getString(R.string.tor_enabled));
269 case ProxyHelper.I2P:
270 proxyPreference.setSummary(getString(R.string.i2p_enabled));
273 case ProxyHelper.CUSTOM:
274 proxyPreference.setSummary(getString(R.string.custom_proxy));
278 // Set the summary text for the custom proxy URL.
279 proxyCustomUrlPreference.setSummary(savedPreferences.getString("proxy_custom_url", getString(R.string.proxy_custom_url_default_value)));
281 // Only enable the custom proxy URL if a custom proxy is selected.
282 proxyCustomUrlPreference.setEnabled(proxyString.equals("Custom"));
285 // Set the status of the clear and exit preferences.
286 clearCookiesPreference.setEnabled(!clearEverything);
287 clearDomStoragePreference.setEnabled(!clearEverything);
288 clearFormDataPreference.setEnabled(!clearEverything); // The form data line can be removed once the minimum API is >= 26.
289 clearLogcatPreference.setEnabled(!clearEverything);
290 clearCachePreference.setEnabled(!clearEverything);
293 // Set the homepage URL as the summary text for the homepage preference.
294 homepagePreference.setSummary(savedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
297 // Set the font size as the summary text for the preference.
298 fontSizePreference.setSummary(savedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
301 // Get the app theme string arrays.
302 String[] appThemeEntriesStringArray = resources.getStringArray(R.array.app_theme_entries);
303 String[] appThemeEntryValuesStringArray = resources.getStringArray(R.array.app_theme_entry_values);
305 // Get the current app theme.
306 String currentAppTheme = savedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
308 // Define an app theme entry number.
309 int appThemeEntryNumber;
311 // 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.
312 if (currentAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected.
313 // Store the app theme entry number.
314 appThemeEntryNumber = 1;
315 } else if (currentAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected.
316 // Store the app theme entry number.
317 appThemeEntryNumber = 2;
318 } else { // The system default theme is selected.
319 // Store the app theme entry number.
320 appThemeEntryNumber = 0;
323 // Set the current theme as the summary text for the preference.
324 appThemePreference.setSummary(appThemeEntriesStringArray[appThemeEntryNumber]);
327 // Get the WebView theme string arrays.
328 String[] webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries);
329 String[] webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values);
331 // Get the current WebView theme.
332 String currentWebViewTheme = savedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
334 // Define a WebView theme entry number.
335 int webViewThemeEntryNumber;
337 // 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.
338 if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[1])) { // The light theme is selected.
339 // Store the WebView theme entry number.
340 webViewThemeEntryNumber = 1;
341 } else if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
342 // Store the WebView theme entry number.
343 webViewThemeEntryNumber = 2;
344 } else { // The system default theme is selected.
345 // Store the WebView theme entry number.
346 webViewThemeEntryNumber = 0;
349 // Set the visibility of the WebView theme preference.
350 if (Build.VERSION.SDK_INT < 21) { // The device is running API 19.
351 // Get a handle for the general category.
352 PreferenceCategory generalCategory = findPreference("general");
354 // Remove the incorrect lint warning below that the general preference category might be null.
355 assert generalCategory != null;
357 // Remove the WebView theme preference.
358 generalCategory.removePreference(webViewThemePreference);
359 } else { // The device is running API >= 21
360 // Set the current theme as the summary text for the preference.
361 webViewThemePreference.setSummary(webViewThemeEntriesStringArray[webViewThemeEntryNumber]);
365 // Set the JavaScript icon.
366 if (javaScriptEnabled) {
367 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
369 javaScriptPreference.setIcon(R.drawable.privacy_mode);
372 // Set the cookies icon.
373 if (savedPreferences.getBoolean(getString(R.string.cookies_key), false)) {
374 cookiesPreference.setIcon(R.drawable.cookies_enabled);
376 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
377 cookiesPreference.setIcon(R.drawable.cookies_disabled_day);
379 cookiesPreference.setIcon(R.drawable.cookies_disabled_night);
383 // Set the DOM storage icon.
384 if (javaScriptEnabled) { // The preference is enabled.
385 if (savedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled.
386 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
387 } else { // DOM storage is disabled.
388 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
389 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
391 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
394 } else { // The preference is disabled. The icon should be ghosted.
395 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
396 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
398 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
402 // Set the save form data icon if API < 26. Save form data has no effect on API >= 26.
403 if (Build.VERSION.SDK_INT < 26) {
404 if (savedPreferences.getBoolean("save_form_data", false)) {
405 formDataPreference.setIcon(R.drawable.form_data_enabled);
407 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
408 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
410 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
415 // Set the custom user agent icon.
416 if (customUserAgentPreference.isEnabled()) {
417 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
418 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
420 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
423 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
424 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
426 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
430 // Set the incognito mode icon.
431 if (savedPreferences.getBoolean("incognito_mode", false)) {
432 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
433 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
435 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
438 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
439 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
441 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
445 // Set the allow screenshots icon.
446 if (savedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) {
447 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
448 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
450 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
453 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
454 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
456 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
460 // Set the EasyList icon.
461 if (savedPreferences.getBoolean("easylist", true)) {
462 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
463 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
465 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
468 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
469 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
471 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
475 // Set the EasyPrivacy icon.
476 if (savedPreferences.getBoolean("easyprivacy", true)) {
477 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
478 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
480 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
483 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
484 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
486 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
490 // Set the Fanboy lists icons.
491 if (fanboyAnnoyanceListEnabled) {
492 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
493 // Set the Fanboy annoyance list icon.
494 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
496 // Set the Fanboy social blocking list icon.
497 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
499 // Set the Fanboy annoyance list icon.
500 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
502 // Set the Fanboy social blocking list icon.
503 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
506 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
507 // Set the Fanboy annoyance list icon.
508 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
510 // Set the Fanboy social blocking list icon.
511 if (fanboySocialBlockingEnabled) {
512 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
514 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
517 // Set the Fanboy annoyance list icon.
518 fanboyAnnoyanceListPreference.setIcon(R.drawable.block_ads_disabled_day);
520 // Set the Fanboy social blocking list icon.
521 if (fanboySocialBlockingEnabled) {
522 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
524 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
529 // Set the UltraList icon.
530 if (savedPreferences.getBoolean("ultralist", true)){
531 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
532 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
534 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
537 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
538 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
540 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
544 // Set the UltraPrivacy icon.
545 if (savedPreferences.getBoolean("ultraprivacy", true)) {
546 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
547 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
549 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
552 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
553 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
555 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
559 // Set the block all third-party requests icon.
560 if (savedPreferences.getBoolean("block_all_third_party_requests", false)) {
561 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
562 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
564 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
567 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
568 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
570 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
574 // Set the Google Analytics icon according to the theme.
575 if (savedPreferences.getBoolean("google_analytics", true)) {
576 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
577 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
579 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
582 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
583 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
585 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
589 // Set the Facebook Click IDs icon according to the theme.
590 if (savedPreferences.getBoolean("facebook_click_ids", true)) {
591 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
592 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
594 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
597 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
598 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
600 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
604 // Set the Twitter AMP redirects icon according to the theme.
605 if (savedPreferences.getBoolean("twitter_amp_redirects", true)) {
606 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
607 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
609 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
612 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
613 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
615 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
619 // Set the search custom URL icon.
620 if (searchCustomURLPreference.isEnabled()) {
621 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
622 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
624 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
627 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
628 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
630 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
634 // Set the Proxy icons according to the theme and status.
635 if (proxyString.equals("None")) { // Proxying is disabled.
636 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
637 // Set the main proxy icon to be disabled.
638 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
640 // Set the custom proxy URL icon to be ghosted.
641 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
642 } else { // Light theme.
643 // Set the main proxy icon to be disabled.
644 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
646 // Set the custom proxy URL icon to be ghosted.
647 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
649 } else { // Proxying is enabled.
650 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
651 // Set the main proxy icon to be enabled.
652 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
654 // Set the custom proxy URL icon according to its status.
655 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
656 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
657 } else { // Custom proxy is disabled.
658 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
660 } else { // Light theme.
661 // Set the main proxy icon to be enabled.
662 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
664 // Set the custom proxy URL icon according to its status.
665 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
666 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
667 } else { // Custom proxy is disabled.
668 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
673 // Set the full screen browsing mode icons.
674 if (fullScreenBrowsingMode) { // Full screen browsing mode is enabled.
675 // Set the `fullScreenBrowsingModePreference` icon according to the theme.
676 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
677 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
679 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
682 // Set the hide app bar icon.
683 if (savedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
684 // Set the icon according to the theme.
685 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
686 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
688 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
690 } else { // Hide app bar is disabled.
691 // Set the icon according to the theme.
692 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
693 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
695 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
698 } else { // Full screen browsing mode is disabled.
699 // Set the icons according to the theme.
700 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
701 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
702 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
704 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
705 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
709 // Set the clear everything preference icon.
710 if (clearEverything) {
711 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
712 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
714 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
717 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
720 // Set the clear cookies preference icon.
721 if (clearEverything || savedPreferences.getBoolean("clear_cookies", true)) {
722 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
723 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
725 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
728 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
731 // Set the clear DOM storage preference icon.
732 if (clearEverything || savedPreferences.getBoolean("clear_dom_storage", true)) {
733 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
734 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
736 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
739 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
742 // Set the clear form data preference icon if the API < 26. It has no effect on newer versions of Android.
743 if (Build.VERSION.SDK_INT < 26) {
744 if (clearEverything || savedPreferences.getBoolean("clear_form_data", true)) {
745 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
746 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
748 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
751 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
755 // Set the clear logcat preference icon.
756 if (clearEverything || savedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
757 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
758 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
760 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
763 clearLogcatPreference.setIcon(R.drawable.bug_warning);
766 // Set the clear cache preference icon.
767 if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) {
768 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
769 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
771 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
774 clearCachePreference.setIcon(R.drawable.cache_warning);
777 // Set the open intents in new tab preference icon.
778 if (savedPreferences.getBoolean("open_intents_in_new_tab", true)) {
779 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
780 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
782 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
785 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
786 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
788 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
792 // Set the swipe to refresh preference icon.
793 if (savedPreferences.getBoolean("swipe_to_refresh", true)) {
794 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
795 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
797 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
800 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
801 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
803 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
807 // Set the scroll app bar preference icon.
808 if (savedPreferences.getBoolean("scroll_app_bar", true)) {
809 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
810 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
812 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
815 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
816 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
818 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
822 // Set the display additional app bar icons preference icon.
823 if (savedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
824 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
825 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
827 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
830 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
831 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
833 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
837 // Set the WebView theme preference icon.
838 switch (webViewThemeEntryNumber) {
839 case 0: // The system default WebView theme is selected.
840 // Set the icon according to the app theme.
841 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
842 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
844 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
848 case 1: // The light WebView theme is selected.
849 // Set the icon according to the app theme.
850 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
851 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
853 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
857 case 2: // The dark WebView theme is selected.
858 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
859 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
861 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
866 // Set the wide viewport preference icon.
867 if (savedPreferences.getBoolean("wide_viewport", true)) {
868 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
869 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
871 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
874 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
875 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
877 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
881 // Set the display webpage images preference icon.
882 if (savedPreferences.getBoolean("display_webpage_images", true)) {
883 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
884 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
886 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
889 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
890 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
892 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
897 // Listen for preference changes.
898 preferencesListener = (SharedPreferences sharedPreferences, String key) -> {
901 // Update the icons and the DOM storage preference status.
902 if (sharedPreferences.getBoolean("javascript", false)) { // The JavaScript preference is enabled.
903 // Update the icon for the JavaScript preference.
904 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
906 // Update the status of the DOM storage preference.
907 domStoragePreference.setEnabled(true);
909 // Update the icon for the DOM storage preference.
910 if (sharedPreferences.getBoolean("dom_storage", false)) {
911 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
913 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
914 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
916 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
919 } else { // The JavaScript preference is disabled.
920 // Update the icon for the JavaScript preference.
921 javaScriptPreference.setIcon(R.drawable.privacy_mode);
923 // Update the status of the DOM storage preference.
924 domStoragePreference.setEnabled(false);
926 // Set the icon for DOM storage preference to be ghosted.
927 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
928 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
930 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
937 if (sharedPreferences.getBoolean(getString(R.string.cookies_key), false)) {
938 cookiesPreference.setIcon(R.drawable.cookies_enabled);
940 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
941 cookiesPreference.setIcon(R.drawable.cookies_disabled_day);
943 cookiesPreference.setIcon(R.drawable.cookies_disabled_night);
950 if (sharedPreferences.getBoolean("dom_storage", false)) {
951 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
953 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
954 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
956 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
961 // Save form data can be removed once the minimum API >= 26.
962 case "save_form_data":
964 if (sharedPreferences.getBoolean("save_form_data", false)) {
965 formDataPreference.setIcon(R.drawable.form_data_enabled);
967 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
968 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
970 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
976 // Get the new user agent name.
977 String newUserAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
979 // Get the array position for the new user agent name.
980 int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName);
982 // Get the translated new user agent name.
983 String translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition];
985 // Populate the user agent summary.
986 switch (newUserAgentArrayPosition) {
987 case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
988 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
989 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + bareWebView.getSettings().getUserAgentString());
991 // Disable the custom user agent preference.
992 customUserAgentPreference.setEnabled(false);
994 // Set the custom user agent preference icon according to the theme.
995 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
996 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
998 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1002 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
1003 // Set the summary text.
1004 userAgentPreference.setSummary(R.string.custom_user_agent);
1006 // Enable the custom user agent preference.
1007 customUserAgentPreference.setEnabled(true);
1009 // Set the custom user agent preference icon according to the theme.
1010 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1011 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
1013 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
1018 // Get the user agent summary from the user agent data array.
1019 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + userAgentDataArray[newUserAgentArrayPosition]);
1021 // Disable the custom user agent preference.
1022 customUserAgentPreference.setEnabled(false);
1024 // Set the custom user agent preference icon according to the theme.
1025 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1026 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1028 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1033 case "custom_user_agent":
1034 // Set the new custom user agent as the summary text for the preference.
1035 customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
1038 case "incognito_mode":
1040 if (sharedPreferences.getBoolean("incognito_mode", false)) {
1041 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1042 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
1044 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
1047 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1048 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
1050 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
1055 case "allow_screenshots":
1057 if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) {
1058 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1059 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
1061 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
1064 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1065 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
1067 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
1071 // Create an intent to restart Privacy Browser.
1072 Intent allowScreenshotsRestartIntent = getActivity().getParentActivityIntent();
1074 // Assert that the intent is not null to remove the lint error below.
1075 assert allowScreenshotsRestartIntent != null;
1077 // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack. It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
1078 allowScreenshotsRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
1080 // Create a handler to restart the activity.
1081 Handler allowScreenshotsRestartHandler = new Handler(Looper.getMainLooper());
1083 // Create a runnable to restart the activity.
1084 Runnable allowScreenshotsRestartRunnable = () -> {
1085 // Restart the activity.
1086 startActivity(allowScreenshotsRestartIntent);
1088 // Kill this instance of Privacy Browser. Otherwise, the app exhibits sporadic behavior after the restart.
1092 // Restart the activity after 150 milliseconds, so that the app has enough time to save the change to the preference.
1093 allowScreenshotsRestartHandler.postDelayed(allowScreenshotsRestartRunnable, 150);
1098 if (sharedPreferences.getBoolean("easylist", true)) {
1099 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1100 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
1102 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
1105 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1106 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
1108 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
1115 if (sharedPreferences.getBoolean("easyprivacy", true)) {
1116 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1117 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1119 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1122 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1123 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1125 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1130 case "fanboys_annoyance_list":
1131 boolean currentFanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
1132 boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
1134 // Update the Fanboy icons.
1135 if (currentFanboyAnnoyanceList) { // Fanboy's annoyance list is enabled.
1136 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1137 // Update the Fanboy's annoyance list icon.
1138 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
1140 // Update the Fanboy's social blocking list icon.
1141 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
1143 // Update the Fanboy's annoyance list icon.
1144 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
1146 // Update the Fanboy's social blocking list icon.
1147 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
1149 } else { // Fanboy's annoyance list is disabled.
1150 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1151 // Update the Fanboy's annoyance list icon.
1152 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
1154 // Update the Fanboy's social blocking list icon.
1155 if (currentFanboySocialBlockingList) {
1156 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1158 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1161 // Update the Fanboy's annoyance list icon.
1162 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_day);
1164 // Update the Fanboy's social blocking list icon.
1165 if (currentFanboySocialBlockingList) {
1166 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1168 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1173 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled.
1174 fanboySocialBlockingListPreference.setEnabled(!currentFanboyAnnoyanceList);
1177 case "fanboys_social_blocking_list":
1179 if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) {
1180 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1181 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1183 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1186 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1187 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1189 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1196 if (sharedPreferences.getBoolean("ultralist", true)) {
1197 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1198 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
1200 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
1203 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1204 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
1206 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
1211 case "ultraprivacy":
1213 if (sharedPreferences.getBoolean("ultraprivacy", true)) {
1214 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1215 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1217 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1220 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1221 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1223 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1228 case "block_all_third_party_requests":
1230 if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
1231 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1232 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
1234 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
1237 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1238 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
1240 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
1245 case "google_analytics":
1247 if (sharedPreferences.getBoolean("google_analytics", true)) {
1248 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1249 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
1251 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
1254 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1255 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
1257 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
1262 case "facebook_click_ids":
1264 if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
1265 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1266 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
1268 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
1271 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1272 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
1274 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
1279 case "twitter_amp_redirects":
1281 if (sharedPreferences.getBoolean("twitter_amp_redirects", true)) {
1282 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1283 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
1285 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
1288 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1289 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
1291 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
1297 // Store the new search string.
1298 String newSearchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
1300 // Update the search and search custom URL preferences.
1301 if (newSearchString.equals("Custom URL")) { // `Custom URL` is selected.
1302 // Set the summary text to `R.string.custom_url`, which is translated.
1303 searchPreference.setSummary(R.string.custom_url);
1305 // Enable `searchCustomURLPreference`.
1306 searchCustomURLPreference.setEnabled(true);
1308 // Set the `searchCustomURLPreference` according to the theme.
1309 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1310 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
1312 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
1314 } else { // `Custom URL` is not selected.
1315 // Set the summary text to `newSearchString`.
1316 searchPreference.setSummary(newSearchString);
1318 // Disable `searchCustomURLPreference`.
1319 searchCustomURLPreference.setEnabled(false);
1321 // Set the `searchCustomURLPreference` according to the theme.
1322 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1323 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
1325 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
1330 case "search_custom_url":
1331 // Set the new search custom URL as the summary text for the preference.
1332 searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
1336 // Get current proxy string.
1337 String currentProxyString = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value));
1339 // Update the summary text for the proxy preference.
1340 switch (currentProxyString) {
1341 case ProxyHelper.NONE:
1342 proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
1345 case ProxyHelper.TOR:
1346 if (Build.VERSION.SDK_INT == 19) { // Proxying through SOCKS doesn't work on Android KitKat.
1347 proxyPreference.setSummary(getString(R.string.tor_enabled_kitkat));
1349 proxyPreference.setSummary(getString(R.string.tor_enabled));
1353 case ProxyHelper.I2P:
1354 proxyPreference.setSummary(getString(R.string.i2p_enabled));
1357 case ProxyHelper.CUSTOM:
1358 proxyPreference.setSummary(getString(R.string.custom_proxy));
1362 // Update the status of the custom URL preference.
1363 proxyCustomUrlPreference.setEnabled(currentProxyString.equals("Custom"));
1365 // Update the icons.
1366 if (currentProxyString.equals("None")) { // Proxying is disabled.
1367 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
1368 // Set the main proxy icon to be disabled
1369 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
1371 // Set the custom proxy URL icon to be ghosted.
1372 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1373 } else { // Light theme.
1374 // Set the main proxy icon to be disabled.
1375 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
1377 // Set the custom proxy URL icon to be ghosted.
1378 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1380 } else { // Proxying is enabled.
1381 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
1382 // Set the main proxy icon to be enabled.
1383 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
1385 /// Set the custom proxy URL icon according to its status.
1386 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
1387 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
1388 } else { // Custom proxy is disabled.
1389 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1391 } else { // Light theme.
1392 // Set the main proxy icon to be enabled.
1393 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
1395 // Set the custom proxy URL icon according to its status.
1396 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
1397 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
1398 } else { // Custom proxy is disabled.
1399 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1405 case "proxy_custom_url":
1406 // Set the summary text for the proxy custom URL.
1407 proxyCustomUrlPreference.setSummary(sharedPreferences.getString("proxy_custom_url", getString(R.string.proxy_custom_url_default_value)));
1410 case "full_screen_browsing_mode":
1411 if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) { // Full screen browsing is enabled.
1412 // Set the full screen browsing mode preference icon according to the theme.
1413 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1414 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
1416 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
1419 // Set the hide app bar preference icon.
1420 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
1421 // Set the icon according to the theme.
1422 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1423 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1425 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1427 } else { // Hide app bar is disabled.
1428 // Set the icon according to the theme.
1429 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1430 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1432 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1435 } else { // Full screen browsing is disabled.
1436 // Update the icons according to the theme.
1437 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1438 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
1439 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
1441 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
1442 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
1447 case "hide_app_bar":
1449 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
1450 // Set the icon according to the theme.
1451 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1452 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1454 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1456 } else { // Hide app bar is disabled.
1457 // Set the icon according to the theme.
1458 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1459 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1461 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1466 case "clear_everything":
1467 // Store the new clear everything status
1468 boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true);
1470 // Update the status of the clear and exit preferences.
1471 clearCookiesPreference.setEnabled(!newClearEverythingBoolean);
1472 clearDomStoragePreference.setEnabled(!newClearEverythingBoolean);
1473 clearFormDataPreference.setEnabled(!newClearEverythingBoolean); // This line can be removed once the minimum API >= 26.
1474 clearLogcatPreference.setEnabled(!newClearEverythingBoolean);
1475 clearCachePreference.setEnabled(!newClearEverythingBoolean);
1477 // Update the clear everything preference icon.
1478 if (newClearEverythingBoolean) {
1479 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1480 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
1482 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
1485 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
1488 // Update the clear cookies preference icon.
1489 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) {
1490 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1491 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1493 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1496 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1499 // Update the clear dom storage preference icon.
1500 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) {
1501 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1502 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1504 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1507 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1510 // Update the clear form data preference icon if the API < 26.
1511 if (Build.VERSION.SDK_INT < 26) {
1512 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) {
1513 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1514 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1516 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1519 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1523 // Update the clear logcat preference icon.
1524 if (newClearEverythingBoolean || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
1525 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1526 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1528 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1531 clearLogcatPreference.setIcon(R.drawable.cache_warning);
1534 // Update the clear cache preference icon.
1535 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) {
1536 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1537 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1539 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1542 clearCachePreference.setIcon(R.drawable.cache_warning);
1546 case "clear_cookies":
1548 if (sharedPreferences.getBoolean("clear_cookies", true)) {
1549 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1550 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1552 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1555 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1559 case "clear_dom_storage":
1561 if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
1562 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1563 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1565 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1568 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1572 // This section can be removed once the minimum API >= 26.
1573 case "clear_form_data":
1575 if (sharedPreferences.getBoolean("clear_form_data", true)) {
1576 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1577 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1579 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1582 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1586 case "clear_logcat":
1588 if (sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
1589 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1590 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1592 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1595 clearLogcatPreference.setIcon(R.drawable.bug_warning);
1601 if (sharedPreferences.getBoolean("clear_cache", true)) {
1602 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1603 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1605 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1608 clearCachePreference.setIcon(R.drawable.cache_warning);
1613 // Set the new homepage URL as the summary text for the Homepage preference.
1614 homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
1618 // Update the font size summary text.
1619 fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
1622 case "open_intents_in_new_tab":
1624 if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
1625 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1626 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
1628 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
1631 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1632 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
1634 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
1639 case "swipe_to_refresh":
1641 if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
1642 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1643 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
1645 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
1648 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1649 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
1651 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
1656 case "scroll_app_bar":
1658 if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
1659 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1660 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1662 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1665 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1666 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1668 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1673 case "display_additional_app_bar_icons":
1675 if (sharedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
1676 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1677 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
1679 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
1682 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1683 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
1685 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
1691 // Get the new theme.
1692 String newAppTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
1694 // 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.
1695 if (newAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected.
1696 // Update the theme preference summary text.
1697 appThemePreference.setSummary(appThemeEntriesStringArray[1]);
1699 // Apply the new theme.
1700 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
1701 } else if (newAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected.
1702 // Update the theme preference summary text.
1703 appThemePreference.setSummary(appThemeEntriesStringArray[2]);
1705 // Apply the new theme.
1706 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
1707 } else { // The system default theme is selected.
1708 // Update the theme preference summary text.
1709 appThemePreference.setSummary(appThemeEntriesStringArray[0]);
1711 // Apply the new theme.
1712 if (Build.VERSION.SDK_INT >= 28) { // The system default theme is supported.
1713 // Follow the system default theme.
1714 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
1715 } else {// The system default theme is not supported.
1716 // Follow the battery saver mode.
1717 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
1721 // Update the current theme status.
1722 currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
1725 case "webview_theme":
1726 // Get the new WebView theme.
1727 String newWebViewTheme = sharedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
1729 // Define a new WebView theme entry number.
1730 int newWebViewThemeEntryNumber;
1732 // 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.
1733 if (newWebViewTheme.equals(webViewThemeEntriesStringArray[1])) { // The light theme is selected.
1734 // Store the new WebView theme entry number.
1735 newWebViewThemeEntryNumber = 1;
1736 } else if (newWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
1737 // Store the WebView theme entry number.
1738 newWebViewThemeEntryNumber = 2;
1739 } else { // The system default theme is selected.
1740 // Store the WebView theme entry number.
1741 newWebViewThemeEntryNumber = 0;
1745 switch (newWebViewThemeEntryNumber) {
1746 case 0: // The system default WebView theme is selected.
1747 // Set the icon according to the app theme.
1748 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1749 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1751 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1755 case 1: // The system default WebView theme is selected.
1756 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1757 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1759 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
1763 case 2: // The system default WebView theme is selected.
1764 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1765 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
1767 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1772 // Set the current theme as the summary text for the preference.
1773 webViewThemePreference.setSummary(webViewThemeEntriesStringArray[newWebViewThemeEntryNumber]);
1776 case "wide_viewport":
1778 if (sharedPreferences.getBoolean("wide_viewport", true)) {
1779 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1780 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
1782 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
1785 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1786 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
1788 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
1793 case "display_webpage_images":
1795 if (sharedPreferences.getBoolean("display_webpage_images", true)) {
1796 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1797 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
1799 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
1802 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1803 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
1805 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
1812 // Register the listener.
1813 savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);
1816 // 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.
1818 public void onPause() {
1820 savedPreferences.unregisterOnSharedPreferenceChangeListener(preferencesListener);
1824 public void onResume() {
1826 savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);