2 * Copyright © 2016-2020 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
6 * Privacy Browser is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacybrowser.fragments;
22 import android.annotation.SuppressLint;
23 import android.app.Activity;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.content.SharedPreferences;
27 import android.content.res.Configuration;
28 import android.content.res.Resources;
29 import android.os.Build;
30 import android.os.Bundle;
31 import android.os.Handler;
32 import android.view.LayoutInflater;
33 import android.view.View;
34 import android.webkit.WebView;
35 import android.widget.ArrayAdapter;
37 import androidx.appcompat.app.AppCompatDelegate;
38 import androidx.preference.Preference;
39 import androidx.preference.PreferenceCategory;
40 import androidx.preference.PreferenceFragmentCompat;
42 import com.stoutner.privacybrowser.R;
43 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
44 import com.stoutner.privacybrowser.helpers.DownloadLocationHelper;
45 import com.stoutner.privacybrowser.helpers.ProxyHelper;
47 public class SettingsFragment extends PreferenceFragmentCompat {
48 // Define the class variables.
49 private SharedPreferences.OnSharedPreferenceChangeListener preferencesListener;
50 private SharedPreferences savedPreferences;
51 private int currentThemeStatus;
54 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
55 // Load the preferences from the XML file.
56 setPreferencesFromResource(R.xml.preferences, rootKey);
58 // Get a handle for the activity.
59 Activity activity = getActivity();
61 // Remove the lint warning below that `getApplicationContext()` might produce a null pointer exception.
62 assert activity != null;
64 // Get a handle for the context and the resources.
65 Context context = activity.getApplicationContext();
66 Resources resources = getResources();
68 // Get the current theme status.
69 currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
71 // Initialize savedPreferences.
72 savedPreferences = getPreferenceScreen().getSharedPreferences();
74 // Get handles for the preferences.
75 Preference javaScriptPreference = findPreference("javascript");
76 Preference firstPartyCookiesPreference = findPreference("first_party_cookies");
77 Preference thirdPartyCookiesPreference = findPreference("third_party_cookies");
78 Preference domStoragePreference = findPreference("dom_storage");
79 Preference formDataPreference = findPreference("save_form_data"); // The form data preference can be removed once the minimum API >= 26.
80 Preference userAgentPreference = findPreference("user_agent");
81 Preference customUserAgentPreference = findPreference("custom_user_agent");
82 Preference incognitoModePreference = findPreference("incognito_mode");
83 Preference doNotTrackPreference = findPreference("do_not_track");
84 Preference allowScreenshotsPreference = findPreference("allow_screenshots");
85 Preference easyListPreference = findPreference("easylist");
86 Preference easyPrivacyPreference = findPreference("easyprivacy");
87 Preference fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
88 Preference fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
89 Preference ultraListPreference = findPreference("ultralist");
90 Preference ultraPrivacyPreference = findPreference("ultraprivacy");
91 Preference blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
92 Preference googleAnalyticsPreference = findPreference("google_analytics");
93 Preference facebookClickIdsPreference = findPreference("facebook_click_ids");
94 Preference twitterAmpRedirectsPreference = findPreference("twitter_amp_redirects");
95 Preference searchPreference = findPreference("search");
96 Preference searchCustomURLPreference = findPreference("search_custom_url");
97 Preference proxyPreference = findPreference("proxy");
98 Preference proxyCustomUrlPreference = findPreference("proxy_custom_url");
99 Preference fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
100 Preference hideAppBarPreference = findPreference("hide_app_bar");
101 Preference clearEverythingPreference = findPreference("clear_everything");
102 Preference clearCookiesPreference = findPreference("clear_cookies");
103 Preference clearDomStoragePreference = findPreference("clear_dom_storage");
104 Preference clearFormDataPreference = findPreference("clear_form_data"); // The clear form data preference can be removed once the minimum API >= 26.
105 Preference clearCachePreference = findPreference("clear_cache");
106 Preference homepagePreference = findPreference("homepage");
107 Preference downloadLocationPreference = findPreference("download_location");
108 Preference downloadCustomLocationPreference = findPreference("download_custom_location");
109 Preference fontSizePreference = findPreference("font_size");
110 Preference openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
111 Preference swipeToRefreshPreference = findPreference("swipe_to_refresh");
112 Preference scrollAppBarPreference = findPreference("scroll_app_bar");
113 Preference displayAdditionalAppBarIconsPreference = findPreference("display_additional_app_bar_icons");
114 Preference appThemePreference = findPreference("app_theme");
115 Preference nightModePreference = findPreference("night_mode");
116 Preference wideViewportPreference = findPreference("wide_viewport");
117 Preference displayWebpageImagesPreference = findPreference("display_webpage_images");
119 // Remove the lint warnings below that the preferences might be null.
120 assert javaScriptPreference != null;
121 assert firstPartyCookiesPreference != null;
122 assert thirdPartyCookiesPreference != null;
123 assert domStoragePreference != null;
124 assert formDataPreference != null;
125 assert userAgentPreference != null;
126 assert customUserAgentPreference != null;
127 assert incognitoModePreference != null;
128 assert doNotTrackPreference != null;
129 assert allowScreenshotsPreference != null;
130 assert easyListPreference != null;
131 assert easyPrivacyPreference != null;
132 assert fanboyAnnoyanceListPreference != null;
133 assert fanboySocialBlockingListPreference != null;
134 assert ultraListPreference != null;
135 assert ultraPrivacyPreference != null;
136 assert blockAllThirdPartyRequestsPreference != null;
137 assert googleAnalyticsPreference != null;
138 assert facebookClickIdsPreference != null;
139 assert twitterAmpRedirectsPreference != null;
140 assert searchPreference != null;
141 assert searchCustomURLPreference != null;
142 assert proxyPreference != null;
143 assert proxyCustomUrlPreference != null;
144 assert fullScreenBrowsingModePreference != null;
145 assert hideAppBarPreference != null;
146 assert clearEverythingPreference != null;
147 assert clearCookiesPreference != null;
148 assert clearDomStoragePreference != null;
149 assert clearFormDataPreference != null;
150 assert clearCachePreference != null;
151 assert homepagePreference != null;
152 assert downloadLocationPreference != null;
153 assert downloadCustomLocationPreference != null;
154 assert fontSizePreference != null;
155 assert openIntentsInNewTabPreference != null;
156 assert swipeToRefreshPreference != null;
157 assert scrollAppBarPreference != null;
158 assert displayAdditionalAppBarIconsPreference != null;
159 assert appThemePreference != null;
160 assert nightModePreference != null;
161 assert wideViewportPreference != null;
162 assert displayWebpageImagesPreference != null;
164 // Set the hide app bar preference dependency.
165 hideAppBarPreference.setDependency("full_screen_browsing_mode");
167 // Get strings from the preferences.
168 String userAgentName = savedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
169 String searchString = savedPreferences.getString("search", getString(R.string.search_default_value));
170 String proxyString = savedPreferences.getString("proxy", getString(R.string.proxy_default_value));
171 String downloadLocationString = savedPreferences.getString("download_location", getString(R.string.download_location_default_value));
173 // Get booleans that are used in multiple places from the preferences.
174 boolean javaScriptEnabled = savedPreferences.getBoolean("javascript", false);
175 boolean firstPartyCookiesEnabled = savedPreferences.getBoolean("first_party_cookies", false);
176 boolean thirdPartyCookiesEnabled = savedPreferences.getBoolean("third_party_cookies", false);
177 boolean fanboyAnnoyanceListEnabled = savedPreferences.getBoolean("fanboys_annoyance_list", true);
178 boolean fanboySocialBlockingEnabled = savedPreferences.getBoolean("fanboys_social_blocking_list", true);
179 boolean fullScreenBrowsingMode = savedPreferences.getBoolean("full_screen_browsing_mode", false);
180 boolean clearEverything = savedPreferences.getBoolean("clear_everything", true);
181 boolean nightMode = savedPreferences.getBoolean("night_mode", false);
183 // Only enable the third-party cookies preference if first-party cookies are enabled and API >= 21.
184 thirdPartyCookiesPreference.setEnabled(firstPartyCookiesEnabled && (Build.VERSION.SDK_INT >= 21));
186 // Only enable the DOM storage preference if either JavaScript or Night Mode is enabled.
187 domStoragePreference.setEnabled(javaScriptEnabled || nightMode);
189 // Remove the form data preferences if the API is >= 26 as they no longer do anything.
190 if (Build.VERSION.SDK_INT >= 26) {
191 // Get the categories.
192 PreferenceCategory privacyCategory = findPreference("privacy");
193 PreferenceCategory clearAndExitCategory = findPreference("clear_and_exit");
195 // Remove the lint warnings below that the preference categories might be null.
196 assert privacyCategory != null;
197 assert clearAndExitCategory != null;
199 // Remove the form data preferences.
200 privacyCategory.removePreference(formDataPreference);
201 clearAndExitCategory.removePreference(clearFormDataPreference);
204 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled.
205 fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled);
208 // Inflate a WebView to get the default user agent.
209 LayoutInflater inflater = getActivity().getLayoutInflater();
211 // `@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.
212 @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
214 // Get a handle for a bare WebView.
215 WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
217 // Get the user agent arrays.
218 ArrayAdapter<CharSequence> userAgentNamesArray = ArrayAdapter.createFromResource(context, R.array.user_agent_names, R.layout.spinner_item);
219 String[] translatedUserAgentNamesArray = resources.getStringArray(R.array.translated_user_agent_names);
220 String[] userAgentDataArray = resources.getStringArray(R.array.user_agent_data);
222 // Get the array position of the user agent name.
223 int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
225 // Populate the user agent summary.
226 switch (userAgentArrayPosition) {
227 case MainWebViewActivity.UNRECOGNIZED_USER_AGENT: // The user agent name is not on the canonical list.
228 // 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.
229 userAgentPreference.setSummary(userAgentName);
232 case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
233 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
234 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + bareWebView.getSettings().getUserAgentString());
237 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
238 // Set the summary text.
239 userAgentPreference.setSummary(R.string.custom_user_agent);
243 // Get the user agent summary from the user agent data array.
244 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + userAgentDataArray[userAgentArrayPosition]);
247 // Set the summary text for the custom user agent preference.
248 customUserAgentPreference.setSummary(savedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
250 // Only enable the custom user agent preference if the user agent is set to `Custom`.
251 customUserAgentPreference.setEnabled(userAgentPreference.getSummary().equals(getString(R.string.custom_user_agent)));
254 // Set the search URL as the summary text for the search preference when the preference screen is loaded.
255 if (searchString.equals("Custom URL")) {
256 // Use R.string.custom_url, which will be translated, instead of the array value, which will not.
257 searchPreference.setSummary(R.string.custom_url);
259 // Set the array value as the summary text.
260 searchPreference.setSummary(searchString);
263 // Set the summary text for the search custom URL (the default is `""`).
264 searchCustomURLPreference.setSummary(savedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
266 // Only enable the search custom URL preference if the search is set to `Custom URL`.
267 searchCustomURLPreference.setEnabled(searchString.equals("Custom URL"));
270 // Set the summary text for the proxy preference when the preference screen is loaded.
271 switch (proxyString) {
272 case ProxyHelper.NONE:
273 proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
276 case ProxyHelper.TOR:
277 if (Build.VERSION.SDK_INT == 19) { // Proxying through SOCKS doesn't work on Android KitKat.
278 proxyPreference.setSummary(getString(R.string.tor_enabled_kitkat));
280 proxyPreference.setSummary(getString(R.string.tor_enabled));
284 case ProxyHelper.I2P:
285 proxyPreference.setSummary(getString(R.string.i2p_enabled));
288 case ProxyHelper.CUSTOM:
289 proxyPreference.setSummary(getString(R.string.custom_proxy));
293 // Set the summary text for the custom proxy URL.
294 proxyCustomUrlPreference.setSummary(savedPreferences.getString("proxy_custom_url", getString(R.string.proxy_custom_url_default_value)));
296 // Only enable the custom proxy URL if a custom proxy is selected.
297 proxyCustomUrlPreference.setEnabled(proxyString.equals("Custom"));
300 // Set the status of the Clear and Exit preferences.
301 clearCookiesPreference.setEnabled(!clearEverything);
302 clearDomStoragePreference.setEnabled(!clearEverything);
303 clearFormDataPreference.setEnabled(!clearEverything); // The form data line can be removed once the minimum API is >= 26.
304 clearCachePreference.setEnabled(!clearEverything);
307 // Set the homepage URL as the summary text for the homepage preference.
308 homepagePreference.setSummary(savedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
311 // Get the download location string arrays.
312 String[] downloadLocationEntriesStringArray = resources.getStringArray(R.array.download_location_entries);
313 String[] downloadLocationEntryValuesStringArray = resources.getStringArray(R.array.download_location_entry_values);
315 // Instantiate the download location helper.
316 DownloadLocationHelper downloadLocationHelper = new DownloadLocationHelper();
318 // Check to see if a download custom location is selected.
319 if (downloadLocationString.equals(downloadLocationEntryValuesStringArray[3])) { // A download custom location is selected.
320 // Set the download location summary text to be `Custom`.
321 downloadLocationPreference.setSummary(downloadLocationEntriesStringArray[3]);
322 } else { // A custom download location is not selected.
323 // Set the download location summary text to be the download location.
324 downloadLocationPreference.setSummary(downloadLocationHelper.getDownloadLocation(context));
326 // Disable the download custom location preference.
327 downloadCustomLocationPreference.setEnabled(false);
330 // Set the summary text for the download custom location (the default is `"`).
331 downloadCustomLocationPreference.setSummary(savedPreferences.getString("download_custom_location", getString(R.string.download_custom_location_default_value)));
334 // Set the font size as the summary text for the preference.
335 fontSizePreference.setSummary(savedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
338 // Get the theme string arrays.
339 String[] appThemeEntriesStringArray = resources.getStringArray(R.array.app_theme_entries);
340 String[] appThemeEntryValuesStringArray = resources.getStringArray(R.array.app_theme_entry_values);
342 // Get the current theme.
343 String currentAppTheme = savedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
345 // Define a theme entry number.
346 int appThemeEntryNumber;
348 // Get the theme entry number that matches the current theme. A switch statement cannot be used because the theme entry values string array is not a compile time constant.
349 if (currentAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected.
350 appThemeEntryNumber = 1;
351 } else if (currentAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected.
352 appThemeEntryNumber = 2;
353 } else { // The system default theme is selected.
354 appThemeEntryNumber = 0;
357 // Set the current theme as the summary text for the preference.
358 appThemePreference.setSummary(appThemeEntriesStringArray[appThemeEntryNumber]);
361 // Disable the JavaScript preference if Night Mode is enabled. JavaScript will be enabled for all web pages.
362 javaScriptPreference.setEnabled(!nightMode);
364 // Set the JavaScript icon.
365 if (javaScriptEnabled || nightMode) {
366 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
368 javaScriptPreference.setIcon(R.drawable.privacy_mode);
371 // Set the first-party cookies icon.
372 if (firstPartyCookiesEnabled) {
373 firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
375 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
376 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
378 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
382 // Set the third party cookies icon.
383 if (firstPartyCookiesEnabled && Build.VERSION.SDK_INT >= 21) {
384 if (thirdPartyCookiesEnabled) {
385 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
387 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
388 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
390 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
394 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
395 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
397 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
401 // Set the DOM storage icon.
402 if (javaScriptEnabled || nightMode) { // The preference is enabled.
403 if (savedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled.
404 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
405 } else { // DOM storage is disabled.
406 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
407 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
409 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
412 } else { // The preference is disabled. The icon should be ghosted.
413 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
414 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
416 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
420 // Set the save form data icon if API < 26. Save form data has no effect on API >= 26.
421 if (Build.VERSION.SDK_INT < 26) {
422 if (savedPreferences.getBoolean("save_form_data", false)) {
423 formDataPreference.setIcon(R.drawable.form_data_enabled);
425 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
426 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
428 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
433 // Set the custom user agent icon.
434 if (customUserAgentPreference.isEnabled()) {
435 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
436 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
438 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
441 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
442 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
444 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
448 // Set the incognito mode icon.
449 if (savedPreferences.getBoolean("incognito_mode", false)) {
450 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
451 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
453 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
456 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
457 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
459 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
463 // Set the Do Not Track icon.
464 if (savedPreferences.getBoolean("do_not_track", false)) {
465 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
466 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_night);
468 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_day);
471 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
472 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_night);
474 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_day);
478 // Set the allow screenshots icon.
479 if (savedPreferences.getBoolean("allow_screenshots", false)) {
480 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
481 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
483 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
486 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
487 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
489 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
493 // Set the EasyList icon.
494 if (savedPreferences.getBoolean("easylist", true)) {
495 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
496 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
498 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
501 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
502 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
504 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
508 // Set the EasyPrivacy icon.
509 if (savedPreferences.getBoolean("easyprivacy", true)) {
510 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
511 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
513 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
516 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
517 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
519 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
523 // Set the Fanboy lists icons.
524 if (fanboyAnnoyanceListEnabled) {
525 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
526 // Set the Fanboy annoyance list icon.
527 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
529 // Set the Fanboy social blocking list icon.
530 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
532 // Set the Fanboy annoyance list icon.
533 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
535 // Set the Fanboy social blocking list icon.
536 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
539 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
540 // Set the Fanboy annoyance list icon.
541 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
543 // Set the Fanboy social blocking list icon.
544 if (fanboySocialBlockingEnabled) {
545 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
547 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
550 // Set the Fanboy annoyance list icon.
551 fanboyAnnoyanceListPreference.setIcon(R.drawable.block_ads_disabled_day);
553 // Set the Fanboy social blocking list icon.
554 if (fanboySocialBlockingEnabled) {
555 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
557 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
562 // Set the UltraList icon.
563 if (savedPreferences.getBoolean("ultralist", true)){
564 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
565 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
567 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
570 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
571 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
573 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
577 // Set the UltraPrivacy icon.
578 if (savedPreferences.getBoolean("ultraprivacy", true)) {
579 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
580 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
582 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
585 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
586 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
588 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
592 // Set the block all third-party requests icon.
593 if (savedPreferences.getBoolean("block_all_third_party_requests", false)) {
594 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
595 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
597 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
600 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
601 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
603 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
607 // Set the Google Analytics icon according to the theme.
608 if (savedPreferences.getBoolean("google_analytics", true)) {
609 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
610 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
612 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
615 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
616 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
618 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
622 // Set the Facebook Click IDs icon according to the theme.
623 if (savedPreferences.getBoolean("facebook_click_ids", true)) {
624 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
625 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
627 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
630 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
631 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
633 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
637 // Set the Twitter AMP redirects icon according to the theme.
638 if (savedPreferences.getBoolean("twitter_amp_redirects", true)) {
639 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
640 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
642 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
645 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
646 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
648 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
652 // Set the search custom URL icon.
653 if (searchCustomURLPreference.isEnabled()) {
654 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
655 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
657 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
660 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
661 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
663 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
667 // Set the Proxy icons according to the theme and status.
668 if (proxyString.equals("None")) { // Proxying is disabled.
669 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
670 // Set the main proxy icon to be disabled.
671 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
673 // Set the custom proxy URL icon to be ghosted.
674 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
675 } else { // Light theme.
676 // Set the main proxy icon to be disabled.
677 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
679 // Set the custom proxy URL icon to be ghosted.
680 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
682 } else { // Proxying is enabled.
683 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
684 // Set the main proxy icon to be enabled.
685 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
687 // Set the custom proxy URL icon according to its status.
688 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
689 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
690 } else { // Custom proxy is disabled.
691 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
693 } else { // Light theme.
694 // Set the main proxy icon to be enabled.
695 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
697 // Set the custom proxy URL icon according to its status.
698 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
699 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
700 } else { // Custom proxy is disabled.
701 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
706 // Set the full screen browsing mode icons.
707 if (fullScreenBrowsingMode) { // Full screen browsing mode is enabled.
708 // Set the `fullScreenBrowsingModePreference` icon according to the theme.
709 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
710 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
712 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
715 // Set the hide app bar icon.
716 if (savedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
717 // Set the icon according to the theme.
718 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
719 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
721 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
723 } else { // Hide app bar is disabled.
724 // Set the icon according to the theme.
725 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
726 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
728 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
731 } else { // Full screen browsing mode is disabled.
732 // Set the icons according to the theme.
733 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
734 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
735 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
737 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
738 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
742 // Set the clear everything preference icon.
743 if (clearEverything) {
744 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
745 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
747 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
750 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
753 // Set the clear cookies preference icon.
754 if (clearEverything || savedPreferences.getBoolean("clear_cookies", true)) {
755 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
756 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
758 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
761 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
764 // Set the clear DOM storage preference icon.
765 if (clearEverything || savedPreferences.getBoolean("clear_dom_storage", true)) {
766 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
767 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
769 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
772 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
775 // Set the clear form data preference icon if the API < 26. It has no effect on newer versions of Android.
776 if (Build.VERSION.SDK_INT < 26) {
777 if (clearEverything || savedPreferences.getBoolean("clear_form_data", true)) {
778 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
779 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
781 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
784 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
788 // Set the clear cache preference icon.
789 if (clearEverything || savedPreferences.getBoolean("clear_cache", true)) {
790 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
791 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
793 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
796 clearCachePreference.setIcon(R.drawable.cache_warning);
799 // Set the download custom location icon.
800 if (downloadCustomLocationPreference.isEnabled()) {
801 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
802 downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_night);
804 downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_day);
807 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
808 downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_night);
810 downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_day);
814 // Set the open intents in new tab preference icon.
815 if (savedPreferences.getBoolean("open_intents_in_new_tab", true)) {
816 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
817 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
819 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
822 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
823 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
825 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
829 // Set the swipe to refresh preference icon.
830 if (savedPreferences.getBoolean("swipe_to_refresh", true)) {
831 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
832 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
834 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
837 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
838 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
840 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
844 // Set the scroll app bar preference icon.
845 if (savedPreferences.getBoolean("scroll_app_bar", true)) {
846 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
847 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
849 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
852 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
853 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
855 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
859 // Set the display additional app bar icons preference icon.
860 if (savedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
861 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
862 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
864 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
867 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
868 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
870 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
874 // Set the night mode preference icon.
876 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
877 nightModePreference.setIcon(R.drawable.night_mode_enabled_night);
879 nightModePreference.setIcon(R.drawable.night_mode_enabled_day);
882 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
883 nightModePreference.setIcon(R.drawable.night_mode_disabled_night);
885 nightModePreference.setIcon(R.drawable.night_mode_disabled_day);
889 // Set the wide viewport preference icon.
890 if (savedPreferences.getBoolean("wide_viewport", true)) {
891 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
892 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
894 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
897 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
898 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
900 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
904 // Set the display webpage images preference icon.
905 if (savedPreferences.getBoolean("display_webpage_images", true)) {
906 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
907 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
909 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
912 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
913 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
915 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
920 // Listen for preference changes.
921 preferencesListener = (SharedPreferences sharedPreferences, String key) -> {
924 // Update the icons and the DOM storage preference status.
925 if (sharedPreferences.getBoolean("javascript", false)) { // The JavaScript preference is enabled.
926 // Update the icon for the JavaScript preference.
927 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
929 // Update the status of the DOM storage preference.
930 domStoragePreference.setEnabled(true);
932 // Update the icon for the DOM storage preference.
933 if (sharedPreferences.getBoolean("dom_storage", false)) {
934 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
936 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
937 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
939 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
942 } else { // The JavaScript preference is disabled.
943 // Update the icon for the JavaScript preference.
944 javaScriptPreference.setIcon(R.drawable.privacy_mode);
946 // Update the status of the DOM storage preference.
947 domStoragePreference.setEnabled(false);
949 // Set the icon for DOM storage preference to be ghosted.
950 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
951 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
953 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
958 case "first_party_cookies":
959 // Update the icons for `first_party_cookies` and `third_party_cookies`.
960 if (sharedPreferences.getBoolean("first_party_cookies", false)) {
961 // Set the icon for `first_party_cookies`.
962 firstPartyCookiesPreference.setIcon(R.drawable.cookies_enabled);
964 // Update the icon for `third_party_cookies`.
965 if (Build.VERSION.SDK_INT >= 21) {
966 if (sharedPreferences.getBoolean("third_party_cookies", false)) {
967 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
969 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
970 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
972 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
976 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
977 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
979 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
982 } else { // `first_party_cookies` is `false`.
983 // Update the icon for `first_party_cookies`.
984 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
985 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
987 firstPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
990 // Set the icon for `third_party_cookies` to be ghosted.
991 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
992 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_night);
994 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_ghosted_day);
998 // Enable `third_party_cookies` if `first_party_cookies` is `true` and API >= 21.
999 thirdPartyCookiesPreference.setEnabled(sharedPreferences.getBoolean("first_party_cookies", false) && (Build.VERSION.SDK_INT >= 21));
1002 case "third_party_cookies":
1004 if (sharedPreferences.getBoolean("third_party_cookies", false)) {
1005 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_warning);
1007 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1008 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_night);
1010 thirdPartyCookiesPreference.setIcon(R.drawable.cookies_disabled_day);
1017 if (sharedPreferences.getBoolean("dom_storage", false)) {
1018 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1020 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1021 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1023 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1028 // Save form data can be removed once the minimum API >= 26.
1029 case "save_form_data":
1031 if (sharedPreferences.getBoolean("save_form_data", false)) {
1032 formDataPreference.setIcon(R.drawable.form_data_enabled);
1034 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1035 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
1037 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
1043 // Get the new user agent name.
1044 String newUserAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
1046 // Get the array position for the new user agent name.
1047 int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName);
1049 // Get the translated new user agent name.
1050 String translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition];
1052 // Populate the user agent summary.
1053 switch (newUserAgentArrayPosition) {
1054 case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
1055 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
1056 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + bareWebView.getSettings().getUserAgentString());
1058 // Disable the custom user agent preference.
1059 customUserAgentPreference.setEnabled(false);
1061 // Set the custom user agent preference icon according to the theme.
1062 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1063 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1065 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1069 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
1070 // Set the summary text.
1071 userAgentPreference.setSummary(R.string.custom_user_agent);
1073 // Enable the custom user agent preference.
1074 customUserAgentPreference.setEnabled(true);
1076 // Set the custom user agent preference icon according to the theme.
1077 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1078 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
1080 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
1085 // Get the user agent summary from the user agent data array.
1086 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + userAgentDataArray[newUserAgentArrayPosition]);
1088 // Disable the custom user agent preference.
1089 customUserAgentPreference.setEnabled(false);
1091 // Set the custom user agent preference icon according to the theme.
1092 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1093 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1095 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1100 case "custom_user_agent":
1101 // Set the new custom user agent as the summary text for the preference.
1102 customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
1105 case "incognito_mode":
1107 if (sharedPreferences.getBoolean("incognito_mode", false)) {
1108 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1109 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
1111 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
1114 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1115 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
1117 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
1122 case "do_not_track":
1124 if (sharedPreferences.getBoolean("do_not_track", false)) {
1125 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1126 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_night);
1128 doNotTrackPreference.setIcon(R.drawable.block_tracking_enabled_day);
1131 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1132 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_night);
1134 doNotTrackPreference.setIcon(R.drawable.block_tracking_disabled_day);
1140 case "allow_screenshots":
1142 if (sharedPreferences.getBoolean("allow_screenshots", false)) {
1143 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1144 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
1146 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
1149 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1150 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
1152 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
1156 // Create an intent to restart Privacy Browser.
1157 Intent allowScreenshotsRestartIntent = getActivity().getParentActivityIntent();
1159 // Assert that the intent is not null to remove the lint error below.
1160 assert allowScreenshotsRestartIntent != null;
1162 // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack. It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
1163 allowScreenshotsRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
1165 // Create a handler to restart the activity.
1166 Handler allowScreenshotsRestartHandler = new Handler();
1168 // Create a runnable to restart the activity.
1169 Runnable allowScreenshotsRestartRunnable = () -> {
1170 // Restart the activity.
1171 startActivity(allowScreenshotsRestartIntent);
1173 // Kill this instance of Privacy Browser. Otherwise, the app exhibits sporadic behavior after the restart.
1177 // Restart the activity after 150 milliseconds, so that the app has enough time to save the change to the preference.
1178 allowScreenshotsRestartHandler.postDelayed(allowScreenshotsRestartRunnable, 150);
1183 if (sharedPreferences.getBoolean("easylist", true)) {
1184 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1185 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
1187 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
1190 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1191 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
1193 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
1200 if (sharedPreferences.getBoolean("easyprivacy", true)) {
1201 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1202 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1204 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1207 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1208 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1210 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1215 case "fanboys_annoyance_list":
1216 boolean currentFanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
1217 boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
1219 // Update the Fanboy icons.
1220 if (currentFanboyAnnoyanceList) { // Fanboy's annoyance list is enabled.
1221 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1222 // Update the Fanboy's annoyance list icon.
1223 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
1225 // Update the Fanboy's social blocking list icon.
1226 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
1228 // Update the Fanboy's annoyance list icon.
1229 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
1231 // Update the Fanboy's social blocking list icon.
1232 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
1234 } else { // Fanboy's annoyance list is disabled.
1235 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1236 // Update the Fanboy's annoyance list icon.
1237 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
1239 // Update the Fanboy's social blocking list icon.
1240 if (currentFanboySocialBlockingList) {
1241 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1243 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1246 // Update the Fanboy's annoyance list icon.
1247 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_day);
1249 // Update the Fanboy's social blocking list icon.
1250 if (currentFanboySocialBlockingList) {
1251 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1253 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1258 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled.
1259 fanboySocialBlockingListPreference.setEnabled(!currentFanboyAnnoyanceList);
1262 case "fanboys_social_blocking_list":
1264 if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) {
1265 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1266 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1268 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1271 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1272 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1274 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1281 if (sharedPreferences.getBoolean("ultralist", true)) {
1282 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1283 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
1285 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
1288 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1289 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
1291 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
1296 case "ultraprivacy":
1298 if (sharedPreferences.getBoolean("ultraprivacy", true)) {
1299 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1300 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1302 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1305 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1306 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1308 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1313 case "block_all_third_party_requests":
1315 if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
1316 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1317 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
1319 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
1322 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1323 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
1325 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
1330 case "google_analytics":
1332 if (sharedPreferences.getBoolean("google_analytics", true)) {
1333 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1334 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
1336 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
1339 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1340 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
1342 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
1347 case "facebook_click_ids":
1349 if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
1350 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1351 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
1353 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
1356 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1357 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
1359 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
1364 case "twitter_amp_redirects":
1366 if (sharedPreferences.getBoolean("twitter_amp_redirects", true)) {
1367 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1368 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
1370 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
1373 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1374 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
1376 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
1382 // Store the new search string.
1383 String newSearchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
1385 // Update the search and search custom URL preferences.
1386 if (newSearchString.equals("Custom URL")) { // `Custom URL` is selected.
1387 // Set the summary text to `R.string.custom_url`, which is translated.
1388 searchPreference.setSummary(R.string.custom_url);
1390 // Enable `searchCustomURLPreference`.
1391 searchCustomURLPreference.setEnabled(true);
1393 // Set the `searchCustomURLPreference` according to the theme.
1394 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1395 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
1397 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
1399 } else { // `Custom URL` is not selected.
1400 // Set the summary text to `newSearchString`.
1401 searchPreference.setSummary(newSearchString);
1403 // Disable `searchCustomURLPreference`.
1404 searchCustomURLPreference.setEnabled(false);
1406 // Set the `searchCustomURLPreference` according to the theme.
1407 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1408 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
1410 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
1415 case "search_custom_url":
1416 // Set the new search custom URL as the summary text for the preference.
1417 searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
1421 // Get current proxy string.
1422 String currentProxyString = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value));
1424 // Update the summary text for the proxy preference.
1425 switch (currentProxyString) {
1426 case ProxyHelper.NONE:
1427 proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
1430 case ProxyHelper.TOR:
1431 if (Build.VERSION.SDK_INT == 19) { // Proxying through SOCKS doesn't work on Android KitKat.
1432 proxyPreference.setSummary(getString(R.string.tor_enabled_kitkat));
1434 proxyPreference.setSummary(getString(R.string.tor_enabled));
1438 case ProxyHelper.I2P:
1439 proxyPreference.setSummary(getString(R.string.i2p_enabled));
1442 case ProxyHelper.CUSTOM:
1443 proxyPreference.setSummary(getString(R.string.custom_proxy));
1447 // Update the status of the custom URL preference.
1448 proxyCustomUrlPreference.setEnabled(currentProxyString.equals("Custom"));
1450 // Update the icons.
1451 if (currentProxyString.equals("None")) { // Proxying is disabled.
1452 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
1453 // Set the main proxy icon to be disabled
1454 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
1456 // Set the custom proxy URL icon to be ghosted.
1457 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1458 } else { // Light theme.
1459 // Set the main proxy icon to be disabled.
1460 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
1462 // Set the custom proxy URL icon to be ghosted.
1463 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1465 } else { // Proxying is enabled.
1466 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
1467 // Set the main proxy icon to be enabled.
1468 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
1470 /// Set the custom proxy URL icon according to its status.
1471 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
1472 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
1473 } else { // Custom proxy is disabled.
1474 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1476 } else { // Light theme.
1477 // Set the main proxy icon to be enabled.
1478 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
1480 // Set the custom proxy URL icon according to its status.
1481 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
1482 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
1483 } else { // Custom proxy is disabled.
1484 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1490 case "proxy_custom_url":
1491 // Set the summary text for the proxy custom URL.
1492 proxyCustomUrlPreference.setSummary(sharedPreferences.getString("proxy_custom_url", getString(R.string.proxy_custom_url_default_value)));
1495 case "full_screen_browsing_mode":
1496 if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) { // Full screen browsing is enabled.
1497 // Set the full screen browsing mode preference icon according to the theme.
1498 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1499 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
1501 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
1504 // Set the hide app bar preference icon.
1505 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
1506 // Set the icon according to the theme.
1507 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1508 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1510 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1512 } else { // Hide app bar is disabled.
1513 // Set the icon according to the theme.
1514 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1515 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1517 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1520 } else { // Full screen browsing is disabled.
1521 // Update the icons according to the theme.
1522 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1523 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
1524 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
1526 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
1527 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
1532 case "hide_app_bar":
1534 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
1535 // Set the icon according to the theme.
1536 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1537 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1539 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1541 } else { // Hide app bar is disabled.
1542 // Set the icon according to the theme.
1543 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1544 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1546 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1551 case "clear_everything":
1552 // Store the new `clear_everything` status
1553 boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true);
1555 // Update the status of the `Clear and Exit` preferences.
1556 clearCookiesPreference.setEnabled(!newClearEverythingBoolean);
1557 clearDomStoragePreference.setEnabled(!newClearEverythingBoolean);
1558 clearFormDataPreference.setEnabled(!newClearEverythingBoolean); // This line can be removed once the minimum API >= 26.
1559 clearCachePreference.setEnabled(!newClearEverythingBoolean);
1561 // Update the `clearEverythingPreference` icon.
1562 if (newClearEverythingBoolean) {
1563 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1564 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
1566 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
1569 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
1572 // Update the `clearCookiesPreference` icon.
1573 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) {
1574 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1575 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1577 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1580 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1583 // Update the `clearDomStoragePreference` icon.
1584 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) {
1585 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1586 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1588 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1591 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1594 // Update the clear form data preference icon if the API < 26.
1595 if (Build.VERSION.SDK_INT < 26) {
1596 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) {
1597 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1598 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1600 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1603 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1607 // Update the `clearCachePreference` icon.
1608 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) {
1609 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1610 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1612 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1615 clearCachePreference.setIcon(R.drawable.cache_warning);
1619 case "clear_cookies":
1621 if (sharedPreferences.getBoolean("clear_cookies", true)) {
1622 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1623 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1625 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1628 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1632 case "clear_dom_storage":
1634 if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
1635 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1636 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1638 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1641 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1645 // This section can be removed once the minimum API >= 26.
1646 case "clear_form_data":
1648 if (sharedPreferences.getBoolean("clear_form_data", true)) {
1649 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1650 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1652 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1655 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1661 if (sharedPreferences.getBoolean("clear_cache", true)) {
1662 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1663 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1665 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1668 clearCachePreference.setIcon(R.drawable.cache_warning);
1673 // Set the new homepage URL as the summary text for the Homepage preference.
1674 homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
1677 case "download_location":
1678 // Get the new download location.
1679 String newDownloadLocationString = sharedPreferences.getString("download_location", getString(R.string.download_location_default_value));
1681 // Check to see if a download custom location is selected.
1682 if (newDownloadLocationString.equals(downloadLocationEntryValuesStringArray[3])) { // A download custom location is selected.
1683 // Set the download location summary text to be `Custom`.
1684 downloadLocationPreference.setSummary(downloadLocationEntriesStringArray[3]);
1686 // Enable the download custom location preference.
1687 downloadCustomLocationPreference.setEnabled(true);
1688 } else { // A download custom location is not selected.
1689 // Set the download location summary text to be the download location.
1690 downloadLocationPreference.setSummary(downloadLocationHelper.getDownloadLocation(context));
1692 // Disable the download custom location.
1693 downloadCustomLocationPreference.setEnabled(newDownloadLocationString.equals(downloadLocationEntryValuesStringArray[3]));
1696 // Update the download custom location icon.
1697 if (downloadCustomLocationPreference.isEnabled()) {
1698 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1699 downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_night);
1701 downloadCustomLocationPreference.setIcon(R.drawable.downloads_enabled_day);
1704 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1705 downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_night);
1707 downloadCustomLocationPreference.setIcon(R.drawable.downloads_ghosted_day);
1712 case "download_custom_location":
1713 // Set the new download custom location as the summary text for the preference.
1714 downloadCustomLocationPreference.setSummary(sharedPreferences.getString("download_custom_location", getString(R.string.download_custom_location_default_value)));
1718 // Update the font size summary text.
1719 fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
1722 case "open_intents_in_new_tab":
1724 if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
1725 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1726 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
1728 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
1731 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1732 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
1734 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
1739 case "swipe_to_refresh":
1741 if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
1742 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1743 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
1745 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
1748 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1749 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
1751 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
1756 case "scroll_app_bar":
1758 if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
1759 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1760 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1762 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1765 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1766 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1768 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1773 case "display_additional_app_bar_icons":
1775 if (sharedPreferences.getBoolean("display_additional_app_bar_icons", false)) {
1776 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1777 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
1779 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
1782 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1783 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
1785 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
1791 // Get the new theme.
1792 String newAppTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
1794 // 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.
1795 if (newAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected.
1796 // Update the theme preference summary text.
1797 appThemePreference.setSummary(appThemeEntriesStringArray[1]);
1799 // Apply the new theme.
1800 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
1801 } else if (newAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected.
1802 // Update the theme preference summary text.
1803 appThemePreference.setSummary(appThemeEntriesStringArray[2]);
1805 // Apply the new theme.
1806 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
1807 } else { // The system default theme is selected.
1808 // Update the theme preference summary text.
1809 appThemePreference.setSummary(appThemeEntriesStringArray[0]);
1811 // Apply the new theme.
1812 if (Build.VERSION.SDK_INT >= 28) { // The system default theme is supported.
1813 // Follow the system default theme.
1814 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
1815 } else {// The system default theme is not supported.
1816 // Follow the battery saver mode.
1817 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
1821 // Update the current theme status.
1822 currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
1826 // Store the current night mode status.
1827 boolean currentNightModeBoolean = sharedPreferences.getBoolean("night_mode", false);
1828 boolean currentJavaScriptBoolean = sharedPreferences.getBoolean("javascript", false);
1831 if (currentNightModeBoolean) {
1832 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1833 nightModePreference.setIcon(R.drawable.night_mode_enabled_night);
1835 nightModePreference.setIcon(R.drawable.night_mode_enabled_day);
1838 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1839 nightModePreference.setIcon(R.drawable.night_mode_disabled_night);
1841 nightModePreference.setIcon(R.drawable.night_mode_disabled_day);
1845 // Update the status of `javaScriptPreference` and `domStoragePreference`.
1846 javaScriptPreference.setEnabled(!currentNightModeBoolean);
1847 domStoragePreference.setEnabled(currentNightModeBoolean || currentJavaScriptBoolean);
1849 // Update the `javaScriptPreference` icon.
1850 if (currentNightModeBoolean || currentJavaScriptBoolean) {
1851 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
1853 javaScriptPreference.setIcon(R.drawable.privacy_mode);
1856 // Update the DOM storage preference icon.
1857 if (currentNightModeBoolean || currentJavaScriptBoolean) { // The preference is enabled.
1858 if (sharedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled.
1859 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1860 } else { // DOM storage is disabled.
1861 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1862 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1864 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1867 } else { // The preference is disabled. The icon should be ghosted.
1868 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1869 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
1871 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
1876 case "wide_viewport":
1878 if (sharedPreferences.getBoolean("wide_viewport", true)) {
1879 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1880 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
1882 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
1885 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1886 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
1888 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
1893 case "display_webpage_images":
1895 if (sharedPreferences.getBoolean("display_webpage_images", true)) {
1896 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1897 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
1899 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
1902 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1903 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
1905 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
1912 // Register the listener.
1913 savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);
1916 // 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.
1918 public void onPause() {
1920 savedPreferences.unregisterOnSharedPreferenceChangeListener(preferencesListener);
1924 public void onResume() {
1926 savedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);