2 * Copyright © 2016-2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
6 * Privacy Browser Android 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 Android 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 Android. 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 // Declare the class variables.
49 private int currentThemeStatus;
50 private String defaultUserAgent;
51 private ArrayAdapter<CharSequence> userAgentNamesArray;
52 private String[] translatedUserAgentNamesArray;
53 private String[] userAgentDataArray;
54 private String[] appThemeEntriesStringArray;
55 private String[] appThemeEntryValuesStringArray;
56 private String[] webViewThemeEntriesStringArray;
57 private String[] webViewThemeEntryValuesStringArray;
58 private SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener;
60 // Declare the class views.
61 private Preference javaScriptPreference;
62 private Preference cookiesPreference;
63 private Preference domStoragePreference;
64 private Preference formDataPreference; // The form data preference can be removed once the minimum API >= 26.
65 private Preference userAgentPreference;
66 private Preference customUserAgentPreference;
67 private Preference incognitoModePreference;
68 private Preference allowScreenshotsPreference;
69 private Preference easyListPreference;
70 private Preference easyPrivacyPreference;
71 private Preference fanboyAnnoyanceListPreference;
72 private Preference fanboySocialBlockingListPreference;
73 private Preference ultraListPreference;
74 private Preference ultraPrivacyPreference;
75 private Preference blockAllThirdPartyRequestsPreference;
76 private Preference googleAnalyticsPreference;
77 private Preference facebookClickIdsPreference;
78 private Preference twitterAmpRedirectsPreference;
79 private Preference searchPreference;
80 private Preference searchCustomURLPreference;
81 private Preference proxyPreference;
82 private Preference proxyCustomUrlPreference;
83 private Preference fullScreenBrowsingModePreference;
84 private Preference hideAppBarPreference;
85 private Preference clearEverythingPreference;
86 private Preference clearCookiesPreference;
87 private Preference clearDomStoragePreference;
88 private Preference clearFormDataPreference; // The clear form data preference can be removed once the minimum API >= 26.
89 private Preference clearLogcatPreference;
90 private Preference clearCachePreference;
91 private Preference homepagePreference;
92 private Preference fontSizePreference;
93 private Preference openIntentsInNewTabPreference;
94 private Preference swipeToRefreshPreference;
95 private Preference downloadWithExternalAppPreference;
96 private Preference scrollAppBarPreference;
97 private Preference bottomAppBarPreference;
98 private Preference displayAdditionalAppBarIconsPreference;
99 private Preference appThemePreference;
100 private Preference webViewThemePreference;
101 private Preference wideViewportPreference;
102 private Preference displayWebpageImagesPreference;
105 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
106 // Load the preferences from the XML file.
107 setPreferencesFromResource(R.xml.preferences, rootKey);
109 // Get a handle for the activity.
110 Activity activity = getActivity();
112 // Remove the lint warning below that `getApplicationContext()` might produce a null pointer exception.
113 assert activity != null;
115 // Get a handle for the resources.
116 Resources resources = getResources();
118 // Get the current theme status.
119 currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
121 // Get a handle for the shared preferences.
122 SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
124 // Get handles for the preferences.
125 javaScriptPreference = findPreference("javascript");
126 cookiesPreference = findPreference(getString(R.string.cookies_key));
127 domStoragePreference = findPreference("dom_storage");
128 formDataPreference = findPreference("save_form_data"); // The form data preference can be removed once the minimum API >= 26.
129 userAgentPreference = findPreference("user_agent");
130 customUserAgentPreference = findPreference("custom_user_agent");
131 incognitoModePreference = findPreference("incognito_mode");
132 allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key));
133 easyListPreference = findPreference("easylist");
134 easyPrivacyPreference = findPreference("easyprivacy");
135 fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
136 fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
137 ultraListPreference = findPreference("ultralist");
138 ultraPrivacyPreference = findPreference("ultraprivacy");
139 blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
140 googleAnalyticsPreference = findPreference("google_analytics");
141 facebookClickIdsPreference = findPreference("facebook_click_ids");
142 twitterAmpRedirectsPreference = findPreference("twitter_amp_redirects");
143 searchPreference = findPreference("search");
144 searchCustomURLPreference = findPreference("search_custom_url");
145 proxyPreference = findPreference("proxy");
146 proxyCustomUrlPreference = findPreference(getString(R.string.proxy_custom_url_key));
147 fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
148 hideAppBarPreference = findPreference("hide_app_bar");
149 clearEverythingPreference = findPreference("clear_everything");
150 clearCookiesPreference = findPreference("clear_cookies");
151 clearDomStoragePreference = findPreference("clear_dom_storage");
152 clearFormDataPreference = findPreference("clear_form_data"); // The clear form data preference can be removed once the minimum API >= 26.
153 clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key));
154 clearCachePreference = findPreference("clear_cache");
155 homepagePreference = findPreference("homepage");
156 fontSizePreference = findPreference("font_size");
157 openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
158 swipeToRefreshPreference = findPreference("swipe_to_refresh");
159 downloadWithExternalAppPreference = findPreference(getString(R.string.download_with_external_app_key));
160 scrollAppBarPreference = findPreference(getString(R.string.scroll_app_bar_key));
161 bottomAppBarPreference = findPreference(getString(R.string.bottom_app_bar_key));
162 displayAdditionalAppBarIconsPreference = findPreference(getString(R.string.display_additional_app_bar_icons_key));
163 appThemePreference = findPreference("app_theme");
164 webViewThemePreference = findPreference("webview_theme");
165 wideViewportPreference = findPreference("wide_viewport");
166 displayWebpageImagesPreference = findPreference("display_webpage_images");
168 // Remove the lint warnings below that the preferences might be null.
169 assert javaScriptPreference != null;
170 assert cookiesPreference != null;
171 assert domStoragePreference != null;
172 assert formDataPreference != null;
173 assert userAgentPreference != null;
174 assert customUserAgentPreference != null;
175 assert incognitoModePreference != null;
176 assert allowScreenshotsPreference != null;
177 assert easyListPreference != null;
178 assert easyPrivacyPreference != null;
179 assert fanboyAnnoyanceListPreference != null;
180 assert fanboySocialBlockingListPreference != null;
181 assert ultraListPreference != null;
182 assert ultraPrivacyPreference != null;
183 assert blockAllThirdPartyRequestsPreference != null;
184 assert googleAnalyticsPreference != null;
185 assert facebookClickIdsPreference != null;
186 assert twitterAmpRedirectsPreference != null;
187 assert searchPreference != null;
188 assert searchCustomURLPreference != null;
189 assert proxyPreference != null;
190 assert proxyCustomUrlPreference != null;
191 assert fullScreenBrowsingModePreference != null;
192 assert hideAppBarPreference != null;
193 assert clearEverythingPreference != null;
194 assert clearCookiesPreference != null;
195 assert clearDomStoragePreference != null;
196 assert clearFormDataPreference != null;
197 assert clearLogcatPreference != null;
198 assert clearCachePreference != null;
199 assert homepagePreference != null;
200 assert fontSizePreference != null;
201 assert openIntentsInNewTabPreference != null;
202 assert swipeToRefreshPreference != null;
203 assert downloadWithExternalAppPreference != null;
204 assert scrollAppBarPreference != null;
205 assert bottomAppBarPreference != null;
206 assert displayAdditionalAppBarIconsPreference != null;
207 assert appThemePreference != null;
208 assert webViewThemePreference != null;
209 assert wideViewportPreference != null;
210 assert displayWebpageImagesPreference != null;
212 // Set the preference dependencies.
213 hideAppBarPreference.setDependency("full_screen_browsing_mode");
214 domStoragePreference.setDependency("javascript");
216 // Get strings from the preferences.
217 String userAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
218 String searchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
219 String proxyString = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value));
221 // Get booleans that are used in multiple places from the preferences.
222 boolean javaScriptEnabled = sharedPreferences.getBoolean("javascript", false);
223 boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
224 boolean fanboySocialBlockingEnabled = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
225 boolean fullScreenBrowsingMode = sharedPreferences.getBoolean("full_screen_browsing_mode", false);
226 boolean clearEverything = sharedPreferences.getBoolean("clear_everything", true);
228 // Remove the form data preferences if the API is >= 26 as they no longer do anything.
229 if (Build.VERSION.SDK_INT >= 26) {
230 // Get handles for the categories.
231 PreferenceCategory privacyCategory = findPreference("privacy");
232 PreferenceCategory clearAndExitCategory = findPreference("clear_and_exit");
234 // Remove the incorrect lint warnings below that the preference categories might be null.
235 assert privacyCategory != null;
236 assert clearAndExitCategory != null;
238 // Remove the form data preferences.
239 privacyCategory.removePreference(formDataPreference);
240 clearAndExitCategory.removePreference(clearFormDataPreference);
243 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled.
244 fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled);
247 // Inflate a WebView to get the default user agent.
248 LayoutInflater inflater = getActivity().getLayoutInflater();
250 // `@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.
251 @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
253 // Get a handle for a bare WebView.
254 WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
256 // Get the default user agent.
257 defaultUserAgent = bareWebView.getSettings().getUserAgentString();
259 // Get the user agent arrays.
260 userAgentNamesArray = ArrayAdapter.createFromResource(requireContext(), R.array.user_agent_names, R.layout.spinner_item);
261 translatedUserAgentNamesArray = resources.getStringArray(R.array.translated_user_agent_names);
262 userAgentDataArray = resources.getStringArray(R.array.user_agent_data);
264 // Get the array position of the user agent name.
265 int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
267 // Populate the user agent summary.
268 switch (userAgentArrayPosition) {
269 case MainWebViewActivity.UNRECOGNIZED_USER_AGENT: // The user agent name is not on the canonical list.
270 // 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.
271 userAgentPreference.setSummary(userAgentName);
274 case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
275 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
276 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + defaultUserAgent);
279 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
280 // Set the summary text.
281 userAgentPreference.setSummary(R.string.custom_user_agent);
285 // Get the user agent summary from the user agent data array.
286 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + userAgentDataArray[userAgentArrayPosition]);
289 // Set the summary text for the custom user agent preference.
290 customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
292 // Only enable the custom user agent preference if the user agent is set to `Custom`.
293 customUserAgentPreference.setEnabled(userAgentPreference.getSummary().equals(getString(R.string.custom_user_agent)));
296 // Set the search URL as the summary text for the search preference when the preference screen is loaded.
297 if (searchString.equals("Custom URL")) {
298 // Use R.string.custom_url, which will be translated, instead of the array value, which will not.
299 searchPreference.setSummary(R.string.custom_url);
301 // Set the array value as the summary text.
302 searchPreference.setSummary(searchString);
305 // Set the summary text for the search custom URL (the default is `""`).
306 searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
308 // Only enable the search custom URL preference if the search is set to `Custom URL`.
309 searchCustomURLPreference.setEnabled(searchString.equals("Custom URL"));
312 // Set the summary text for the proxy preference when the preference screen is loaded.
313 switch (proxyString) {
314 case ProxyHelper.NONE:
315 proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
318 case ProxyHelper.TOR:
319 proxyPreference.setSummary(getString(R.string.tor_enabled));
322 case ProxyHelper.I2P:
323 proxyPreference.setSummary(getString(R.string.i2p_enabled));
326 case ProxyHelper.CUSTOM:
327 proxyPreference.setSummary(getString(R.string.custom_proxy));
331 // Set the summary text for the custom proxy URL.
332 proxyCustomUrlPreference.setSummary(sharedPreferences.getString(getString(R.string.proxy_custom_url_key), getString(R.string.proxy_custom_url_default_value)));
334 // Only enable the custom proxy URL if a custom proxy is selected.
335 proxyCustomUrlPreference.setEnabled(proxyString.equals(ProxyHelper.CUSTOM));
338 // Set the status of the clear and exit preferences.
339 clearCookiesPreference.setEnabled(!clearEverything);
340 clearDomStoragePreference.setEnabled(!clearEverything);
341 clearFormDataPreference.setEnabled(!clearEverything); // The form data line can be removed once the minimum API is >= 26.
342 clearLogcatPreference.setEnabled(!clearEverything);
343 clearCachePreference.setEnabled(!clearEverything);
346 // Set the homepage URL as the summary text for the homepage preference.
347 homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
350 // Set the font size as the summary text for the preference.
351 fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
354 // Get the app theme string arrays.
355 appThemeEntriesStringArray = resources.getStringArray(R.array.app_theme_entries);
356 appThemeEntryValuesStringArray = resources.getStringArray(R.array.app_theme_entry_values);
358 // Get the current app theme.
359 String currentAppTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
361 // Define an app theme entry number.
362 int appThemeEntryNumber;
364 // 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.
365 if (currentAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected.
366 // Store the app theme entry number.
367 appThemeEntryNumber = 1;
368 } else if (currentAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected.
369 // Store the app theme entry number.
370 appThemeEntryNumber = 2;
371 } else { // The system default theme is selected.
372 // Store the app theme entry number.
373 appThemeEntryNumber = 0;
376 // Set the current theme as the summary text for the preference.
377 appThemePreference.setSummary(appThemeEntriesStringArray[appThemeEntryNumber]);
380 // Get the WebView theme string arrays.
381 webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries);
382 webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values);
384 // Get the current WebView theme.
385 String currentWebViewTheme = sharedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
387 // Define a WebView theme entry number.
388 int webViewThemeEntryNumber;
390 // 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.
391 if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[1])) { // The light theme is selected.
392 // Store the WebView theme entry number.
393 webViewThemeEntryNumber = 1;
394 } else if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
395 // Store the WebView theme entry number.
396 webViewThemeEntryNumber = 2;
397 } else { // The system default theme is selected.
398 // Store the WebView theme entry number.
399 webViewThemeEntryNumber = 0;
402 // Set the current theme as the summary text for the preference.
403 webViewThemePreference.setSummary(webViewThemeEntriesStringArray[webViewThemeEntryNumber]);
406 // Set the JavaScript icon.
407 if (javaScriptEnabled) {
408 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
410 javaScriptPreference.setIcon(R.drawable.privacy_mode);
413 // Set the cookies icon.
414 if (sharedPreferences.getBoolean(getString(R.string.cookies_key), false)) {
415 cookiesPreference.setIcon(R.drawable.cookies_enabled);
417 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
418 cookiesPreference.setIcon(R.drawable.cookies_disabled_day);
420 cookiesPreference.setIcon(R.drawable.cookies_disabled_night);
424 // Set the DOM storage icon.
425 if (javaScriptEnabled) { // The preference is enabled.
426 if (sharedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled.
427 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
428 } else { // DOM storage is disabled.
429 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
430 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
432 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
435 } else { // The preference is disabled. The icon should be ghosted.
436 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
437 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
439 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
443 // Set the save form data icon if API < 26. Save form data has no effect on API >= 26.
444 if (Build.VERSION.SDK_INT < 26) {
445 if (sharedPreferences.getBoolean("save_form_data", false)) {
446 formDataPreference.setIcon(R.drawable.form_data_enabled);
448 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
449 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
451 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
456 // Set the custom user agent icon.
457 if (customUserAgentPreference.isEnabled()) {
458 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
459 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
461 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
464 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
465 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
467 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
471 // Set the incognito mode icon.
472 if (sharedPreferences.getBoolean("incognito_mode", false)) {
473 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
474 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
476 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
479 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
480 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
482 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
486 // Set the allow screenshots icon.
487 if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) {
488 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
489 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
491 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
494 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
495 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
497 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
501 // Set the EasyList icon.
502 if (sharedPreferences.getBoolean("easylist", true)) {
503 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
504 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
506 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
509 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
510 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
512 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
516 // Set the EasyPrivacy icon.
517 if (sharedPreferences.getBoolean("easyprivacy", true)) {
518 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
519 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
521 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
524 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
525 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
527 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
531 // Set the Fanboy lists icons.
532 if (fanboyAnnoyanceListEnabled) {
533 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
534 // Set the Fanboy annoyance list icon.
535 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
537 // Set the Fanboy social blocking list icon.
538 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
540 // Set the Fanboy annoyance list icon.
541 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
543 // Set the Fanboy social blocking list icon.
544 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
547 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
548 // Set the Fanboy annoyance list icon.
549 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
551 // Set the Fanboy social blocking list icon.
552 if (fanboySocialBlockingEnabled) {
553 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
555 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
558 // Set the Fanboy annoyance list icon.
559 fanboyAnnoyanceListPreference.setIcon(R.drawable.block_ads_disabled_day);
561 // Set the Fanboy social blocking list icon.
562 if (fanboySocialBlockingEnabled) {
563 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
565 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
570 // Set the UltraList icon.
571 if (sharedPreferences.getBoolean("ultralist", true)){
572 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
573 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
575 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
578 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
579 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
581 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
585 // Set the UltraPrivacy icon.
586 if (sharedPreferences.getBoolean("ultraprivacy", true)) {
587 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
588 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
590 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
593 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
594 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
596 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
600 // Set the block all third-party requests icon.
601 if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
602 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
603 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
605 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
608 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
609 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
611 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
615 // Set the Google Analytics icon according to the theme.
616 if (sharedPreferences.getBoolean("google_analytics", true)) {
617 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
618 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
620 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
623 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
624 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
626 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
630 // Set the Facebook Click IDs icon according to the theme.
631 if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
632 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
633 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
635 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
638 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
639 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
641 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
645 // Set the Twitter AMP redirects icon according to the theme.
646 if (sharedPreferences.getBoolean("twitter_amp_redirects", true)) {
647 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
648 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
650 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
653 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
654 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
656 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
660 // Set the search custom URL icon.
661 if (searchCustomURLPreference.isEnabled()) {
662 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
663 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
665 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
668 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
669 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
671 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
675 // Set the Proxy icons according to the theme and status.
676 if (proxyString.equals(ProxyHelper.NONE)) { // Proxying is disabled.
677 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
678 // Set the main proxy icon to be disabled.
679 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
681 // Set the custom proxy URL icon to be ghosted.
682 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
683 } else { // Light theme.
684 // Set the main proxy icon to be disabled.
685 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
687 // Set the custom proxy URL icon to be ghosted.
688 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
690 } else { // Proxying is enabled.
691 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
692 // Set the main proxy icon to be enabled.
693 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
695 // Set the custom proxy URL icon according to its status.
696 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
697 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
698 } else { // Custom proxy is disabled.
699 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
701 } else { // Light theme.
702 // Set the main proxy icon to be enabled.
703 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
705 // Set the custom proxy URL icon according to its status.
706 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
707 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
708 } else { // Custom proxy is disabled.
709 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
714 // Set the full screen browsing mode icons.
715 if (fullScreenBrowsingMode) { // Full screen browsing mode is enabled.
716 // Set the `fullScreenBrowsingModePreference` icon according to the theme.
717 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
718 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
720 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
723 // Set the hide app bar icon.
724 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
725 // Set the icon according to the theme.
726 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
727 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
729 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
731 } else { // Hide app bar is disabled.
732 // Set the icon according to the theme.
733 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
734 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
736 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
739 } else { // Full screen browsing mode is disabled.
740 // Set the icons according to the theme.
741 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
742 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
743 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
745 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
746 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
750 // Set the clear everything preference icon.
751 if (clearEverything) {
752 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
753 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
755 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
758 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
761 // Set the clear cookies preference icon.
762 if (clearEverything || sharedPreferences.getBoolean("clear_cookies", true)) {
763 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
764 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
766 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
769 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
772 // Set the clear DOM storage preference icon.
773 if (clearEverything || sharedPreferences.getBoolean("clear_dom_storage", true)) {
774 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
775 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
777 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
780 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
783 // Set the clear form data preference icon if the API < 26. It has no effect on newer versions of Android.
784 if (Build.VERSION.SDK_INT < 26) {
785 if (clearEverything || sharedPreferences.getBoolean("clear_form_data", true)) {
786 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
787 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
789 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
792 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
796 // Set the clear logcat preference icon.
797 if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
798 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
799 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
801 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
804 clearLogcatPreference.setIcon(R.drawable.bug_warning);
807 // Set the clear cache preference icon.
808 if (clearEverything || sharedPreferences.getBoolean("clear_cache", true)) {
809 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
810 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
812 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
815 clearCachePreference.setIcon(R.drawable.cache_warning);
818 // Set the open intents in new tab preference icon.
819 if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
820 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
821 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
823 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
826 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
827 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
829 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
833 // Set the swipe to refresh preference icon.
834 if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
835 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
836 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
838 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
841 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
842 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
844 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
848 // Set the download with external app preference icon.
849 if (sharedPreferences.getBoolean(getString(R.string.download_with_external_app_key), false)) {
850 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
851 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_day);
853 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_night);
856 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
857 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_day);
859 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_night);
863 // Set the scroll app bar preference icon.
864 if (sharedPreferences.getBoolean(getString(R.string.scroll_app_bar_key), true)) {
865 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
866 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
868 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
871 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
872 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
874 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
878 // Set the bottom app bar preference icon.
879 if (sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)) {
880 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
881 bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_enabled_day);
883 bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_enabled_night);
886 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
887 bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_disabled_day);
889 bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_disabled_night);
893 // Set the display additional app bar icons preference icon.
894 if (sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false)) {
895 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
896 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
898 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
901 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
902 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
904 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
908 // Set the WebView theme preference icon.
909 switch (webViewThemeEntryNumber) {
910 case 0: // The system default WebView theme is selected.
911 // Set the icon according to the app theme.
912 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
913 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
915 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
919 case 1: // The light WebView theme is selected.
920 // Set the icon according to the app theme.
921 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
922 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
924 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
928 case 2: // The dark WebView theme is selected.
929 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
930 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
932 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
937 // Set the wide viewport preference icon.
938 if (sharedPreferences.getBoolean("wide_viewport", true)) {
939 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
940 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
942 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
945 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
946 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
948 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
952 // Set the display webpage images preference icon.
953 if (sharedPreferences.getBoolean("display_webpage_images", true)) {
954 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
955 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
957 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
960 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
961 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
963 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
968 // The listener should be unregistered when the app is paused.
970 public void onPause() {
971 // Run the default commands.
974 // Get a handle for the shared preferences.
975 SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
977 // Unregister the shared preference listener.
978 sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
981 // The listener should be re-registered when the app is resumed.
983 public void onResume() {
984 // Run the default commands.
987 // Get a new shared preference change listener.
988 sharedPreferenceChangeListener = getSharedPreferenceChangeListener(requireContext());
990 // Get a handle for the shared preferences.
991 SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
993 // Re-register the shared preference listener.
994 sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
997 // The context must be passed to the shared preference change listener or else any calls to the system `getString()` will crash if the app has been restarted.
998 // This can be removed at some future point, perhaps after the switch to PreferenceScreenCompat. It isn't an issue in Privacy Cell.
999 private SharedPreferences.OnSharedPreferenceChangeListener getSharedPreferenceChangeListener(Context context) {
1000 // Return the shared preference change listener.
1001 return (SharedPreferences sharedPreferences, String key) -> {
1004 // Update the icons and the DOM storage preference status.
1005 if (sharedPreferences.getBoolean("javascript", false)) { // The JavaScript preference is enabled.
1006 // Update the icon for the JavaScript preference.
1007 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
1009 // Update the status of the DOM storage preference.
1010 domStoragePreference.setEnabled(true);
1012 // Update the icon for the DOM storage preference.
1013 if (sharedPreferences.getBoolean("dom_storage", false)) {
1014 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1016 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1017 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1019 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1022 } else { // The JavaScript preference is disabled.
1023 // Update the icon for the JavaScript preference.
1024 javaScriptPreference.setIcon(R.drawable.privacy_mode);
1026 // Update the status of the DOM storage preference.
1027 domStoragePreference.setEnabled(false);
1029 // Set the icon for DOM storage preference to be ghosted.
1030 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1031 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
1033 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
1040 if (sharedPreferences.getBoolean(context.getString(R.string.cookies_key), false)) {
1041 cookiesPreference.setIcon(R.drawable.cookies_enabled);
1043 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1044 cookiesPreference.setIcon(R.drawable.cookies_disabled_day);
1046 cookiesPreference.setIcon(R.drawable.cookies_disabled_night);
1053 if (sharedPreferences.getBoolean("dom_storage", false)) {
1054 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1056 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1057 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1059 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1064 // Save form data can be removed once the minimum API >= 26.
1065 case "save_form_data":
1067 if (sharedPreferences.getBoolean("save_form_data", false)) {
1068 formDataPreference.setIcon(R.drawable.form_data_enabled);
1070 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1071 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
1073 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
1079 // Get the new user agent name.
1080 String newUserAgentName = sharedPreferences.getString("user_agent", context.getString(R.string.user_agent_default_value));
1082 // Get the array position for the new user agent name.
1083 int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName);
1085 // Get the translated new user agent name.
1086 String translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition];
1088 // Populate the user agent summary.
1089 switch (newUserAgentArrayPosition) {
1090 case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
1091 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
1092 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + defaultUserAgent);
1094 // Disable the custom user agent preference.
1095 customUserAgentPreference.setEnabled(false);
1097 // Set the custom user agent preference icon according to the theme.
1098 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1099 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1101 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1105 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
1106 // Set the summary text.
1107 userAgentPreference.setSummary(R.string.custom_user_agent);
1109 // Enable the custom user agent preference.
1110 customUserAgentPreference.setEnabled(true);
1112 // Set the custom user agent preference icon according to the theme.
1113 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1114 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
1116 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
1121 // Get the user agent summary from the user agent data array.
1122 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + userAgentDataArray[newUserAgentArrayPosition]);
1124 // Disable the custom user agent preference.
1125 customUserAgentPreference.setEnabled(false);
1127 // Set the custom user agent preference icon according to the theme.
1128 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1129 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1131 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1136 case "custom_user_agent":
1137 // Set the new custom user agent as the summary text for the preference.
1138 customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", context.getString(R.string.custom_user_agent_default_value)));
1141 case "incognito_mode":
1143 if (sharedPreferences.getBoolean("incognito_mode", false)) {
1144 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1145 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
1147 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
1150 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1151 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
1153 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
1158 case "allow_screenshots":
1160 if (sharedPreferences.getBoolean(context.getString(R.string.allow_screenshots_key), false)) {
1161 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1162 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
1164 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
1167 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1168 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
1170 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
1174 // Restart Privacy Browser.
1175 restartPrivacyBrowser();
1180 if (sharedPreferences.getBoolean("easylist", true)) {
1181 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1182 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
1184 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
1187 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1188 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
1190 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
1197 if (sharedPreferences.getBoolean("easyprivacy", true)) {
1198 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1199 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1201 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1204 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1205 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1207 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1212 case "fanboys_annoyance_list":
1213 boolean currentFanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
1214 boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
1216 // Update the Fanboy icons.
1217 if (currentFanboyAnnoyanceList) { // Fanboy's annoyance list is enabled.
1218 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1219 // Update the Fanboy's annoyance list icon.
1220 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
1222 // Update the Fanboy's social blocking list icon.
1223 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
1225 // Update the Fanboy's annoyance list icon.
1226 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
1228 // Update the Fanboy's social blocking list icon.
1229 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
1231 } else { // Fanboy's annoyance list is disabled.
1232 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1233 // Update the Fanboy's annoyance list icon.
1234 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
1236 // Update the Fanboy's social blocking list icon.
1237 if (currentFanboySocialBlockingList) {
1238 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1240 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1243 // Update the Fanboy's annoyance list icon.
1244 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_day);
1246 // Update the Fanboy's social blocking list icon.
1247 if (currentFanboySocialBlockingList) {
1248 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1250 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1255 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled.
1256 fanboySocialBlockingListPreference.setEnabled(!currentFanboyAnnoyanceList);
1259 case "fanboys_social_blocking_list":
1261 if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) {
1262 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1263 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1265 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1268 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1269 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1271 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1278 if (sharedPreferences.getBoolean("ultralist", true)) {
1279 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1280 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
1282 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
1285 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1286 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
1288 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
1293 case "ultraprivacy":
1295 if (sharedPreferences.getBoolean("ultraprivacy", true)) {
1296 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1297 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1299 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1302 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1303 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1305 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1310 case "block_all_third_party_requests":
1312 if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
1313 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1314 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
1316 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
1319 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1320 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
1322 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
1327 case "google_analytics":
1329 if (sharedPreferences.getBoolean("google_analytics", true)) {
1330 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1331 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
1333 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
1336 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1337 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
1339 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
1344 case "facebook_click_ids":
1346 if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
1347 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1348 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
1350 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
1353 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1354 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
1356 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
1361 case "twitter_amp_redirects":
1363 if (sharedPreferences.getBoolean("twitter_amp_redirects", true)) {
1364 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1365 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
1367 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
1370 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1371 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
1373 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
1379 // Store the new search string.
1380 String newSearchString = sharedPreferences.getString("search", context.getString(R.string.search_default_value));
1382 // Update the search and search custom URL preferences.
1383 if (newSearchString.equals("Custom URL")) { // `Custom URL` is selected.
1384 // Set the summary text to `R.string.custom_url`, which is translated.
1385 searchPreference.setSummary(R.string.custom_url);
1387 // Enable `searchCustomURLPreference`.
1388 searchCustomURLPreference.setEnabled(true);
1390 // Set the `searchCustomURLPreference` according to the theme.
1391 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1392 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
1394 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
1396 } else { // `Custom URL` is not selected.
1397 // Set the summary text to `newSearchString`.
1398 searchPreference.setSummary(newSearchString);
1400 // Disable `searchCustomURLPreference`.
1401 searchCustomURLPreference.setEnabled(false);
1403 // Set the `searchCustomURLPreference` according to the theme.
1404 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1405 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
1407 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
1412 case "search_custom_url":
1413 // Set the new search custom URL as the summary text for the preference.
1414 searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", context.getString(R.string.search_custom_url_default_value)));
1418 // Get current proxy string.
1419 String currentProxyString = sharedPreferences.getString("proxy", context.getString(R.string.proxy_default_value));
1421 // Update the summary text for the proxy preference.
1422 switch (currentProxyString) {
1423 case ProxyHelper.NONE:
1424 proxyPreference.setSummary(context.getString(R.string.no_proxy_enabled));
1427 case ProxyHelper.TOR:
1428 proxyPreference.setSummary(context.getString(R.string.tor_enabled));
1431 case ProxyHelper.I2P:
1432 proxyPreference.setSummary(context.getString(R.string.i2p_enabled));
1435 case ProxyHelper.CUSTOM:
1436 proxyPreference.setSummary(context.getString(R.string.custom_proxy));
1440 // Update the status of the custom URL preference.
1441 proxyCustomUrlPreference.setEnabled(currentProxyString.equals(ProxyHelper.CUSTOM));
1443 // Update the icons.
1444 if (currentProxyString.equals(ProxyHelper.NONE)) { // Proxying is disabled.
1445 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
1446 // Set the main proxy icon to be disabled
1447 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
1449 // Set the custom proxy URL icon to be ghosted.
1450 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1451 } else { // Light theme.
1452 // Set the main proxy icon to be disabled.
1453 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
1455 // Set the custom proxy URL icon to be ghosted.
1456 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1458 } else { // Proxying is enabled.
1459 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
1460 // Set the main proxy icon to be enabled.
1461 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
1463 /// Set the custom proxy URL icon according to its status.
1464 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
1465 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
1466 } else { // Custom proxy is disabled.
1467 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1469 } else { // Light theme.
1470 // Set the main proxy icon to be enabled.
1471 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
1473 // Set the custom proxy URL icon according to its status.
1474 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
1475 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
1476 } else { // Custom proxy is disabled.
1477 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1483 case "proxy_custom_url":
1484 // Set the summary text for the proxy custom URL.
1485 proxyCustomUrlPreference.setSummary(sharedPreferences.getString(context.getString(R.string.proxy_custom_url_key), context.getString(R.string.proxy_custom_url_default_value)));
1488 case "full_screen_browsing_mode":
1489 if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) { // Full screen browsing is enabled.
1490 // Set the full screen browsing mode preference icon according to the theme.
1491 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1492 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
1494 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
1497 // Set the hide app bar preference icon.
1498 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
1499 // Set the icon according to the theme.
1500 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1501 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1503 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1505 } else { // Hide app bar is disabled.
1506 // Set the icon according to the theme.
1507 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1508 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1510 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1513 } else { // Full screen browsing is disabled.
1514 // Update the icons according to the theme.
1515 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1516 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
1517 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
1519 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
1520 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
1525 case "hide_app_bar":
1527 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
1528 // Set the icon according to the theme.
1529 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1530 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1532 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1534 } else { // Hide app bar is disabled.
1535 // Set the icon according to the theme.
1536 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1537 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1539 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1544 case "clear_everything":
1545 // Store the new clear everything status
1546 boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true);
1548 // Update the status of the clear and exit preferences.
1549 clearCookiesPreference.setEnabled(!newClearEverythingBoolean);
1550 clearDomStoragePreference.setEnabled(!newClearEverythingBoolean);
1551 clearFormDataPreference.setEnabled(!newClearEverythingBoolean); // This line can be removed once the minimum API >= 26.
1552 clearLogcatPreference.setEnabled(!newClearEverythingBoolean);
1553 clearCachePreference.setEnabled(!newClearEverythingBoolean);
1555 // Update the clear everything preference icon.
1556 if (newClearEverythingBoolean) {
1557 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1558 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
1560 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
1563 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
1566 // Update the clear cookies preference icon.
1567 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) {
1568 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1569 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1571 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1574 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1577 // Update the clear dom storage preference icon.
1578 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) {
1579 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1580 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1582 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1585 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1588 // Update the clear form data preference icon if the API < 26.
1589 if (Build.VERSION.SDK_INT < 26) {
1590 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) {
1591 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1592 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1594 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1597 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1601 // Update the clear logcat preference icon.
1602 if (newClearEverythingBoolean || sharedPreferences.getBoolean(context.getString(R.string.clear_logcat_key), true)) {
1603 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1604 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1606 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1609 clearLogcatPreference.setIcon(R.drawable.cache_warning);
1612 // Update the clear cache preference icon.
1613 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) {
1614 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1615 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1617 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1620 clearCachePreference.setIcon(R.drawable.cache_warning);
1624 case "clear_cookies":
1626 if (sharedPreferences.getBoolean("clear_cookies", true)) {
1627 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1628 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1630 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1633 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1637 case "clear_dom_storage":
1639 if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
1640 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1641 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1643 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1646 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1650 // This section can be removed once the minimum API >= 26.
1651 case "clear_form_data":
1653 if (sharedPreferences.getBoolean("clear_form_data", true)) {
1654 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1655 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1657 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1660 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1664 case "clear_logcat":
1666 if (sharedPreferences.getBoolean(context.getString(R.string.clear_logcat_key), true)) {
1667 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1668 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1670 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1673 clearLogcatPreference.setIcon(R.drawable.bug_warning);
1679 if (sharedPreferences.getBoolean("clear_cache", true)) {
1680 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1681 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1683 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1686 clearCachePreference.setIcon(R.drawable.cache_warning);
1691 // Set the new homepage URL as the summary text for the Homepage preference.
1692 homepagePreference.setSummary(sharedPreferences.getString("homepage", context.getString(R.string.homepage_default_value)));
1696 // Update the font size summary text.
1697 fontSizePreference.setSummary(sharedPreferences.getString("font_size", context.getString(R.string.font_size_default_value)) + "%");
1700 case "open_intents_in_new_tab":
1702 if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
1703 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1704 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
1706 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
1709 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1710 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
1712 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
1717 case "swipe_to_refresh":
1719 if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
1720 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1721 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
1723 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
1726 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1727 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
1729 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
1734 case "download_with_external_app":
1736 if (sharedPreferences.getBoolean(context.getString(R.string.download_with_external_app_key), false)) {
1737 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1738 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_day);
1740 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_night);
1743 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1744 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_day);
1746 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_night);
1751 case "scroll_app_bar":
1753 if (sharedPreferences.getBoolean(context.getString(R.string.scroll_app_bar_key), true)) {
1754 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1755 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1757 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1760 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1761 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1763 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1768 case "bottom_app_bar":
1770 if (sharedPreferences.getBoolean(context.getString(R.string.bottom_app_bar_key), false)) {
1771 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1772 bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_enabled_day);
1774 bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_enabled_night);
1777 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1778 bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_disabled_day);
1780 bottomAppBarPreference.setIcon(R.drawable.bottom_app_bar_disabled_night);
1784 // Restart Privacy Browser.
1785 restartPrivacyBrowser();
1788 case "display_additional_app_bar_icons":
1790 if (sharedPreferences.getBoolean(context.getString(R.string.display_additional_app_bar_icons_key), false)) {
1791 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1792 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
1794 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
1797 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1798 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
1800 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
1806 // Get the new theme.
1807 String newAppTheme = sharedPreferences.getString("app_theme", context.getString(R.string.app_theme_default_value));
1809 // 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.
1810 if (newAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected.
1811 // Update the theme preference summary text.
1812 appThemePreference.setSummary(appThemeEntriesStringArray[1]);
1814 // Apply the new theme.
1815 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
1816 } else if (newAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected.
1817 // Update the theme preference summary text.
1818 appThemePreference.setSummary(appThemeEntriesStringArray[2]);
1820 // Apply the new theme.
1821 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
1822 } else { // The system default theme is selected.
1823 // Update the theme preference summary text.
1824 appThemePreference.setSummary(appThemeEntriesStringArray[0]);
1826 // Apply the new theme.
1827 if (Build.VERSION.SDK_INT >= 28) { // The system default theme is supported.
1828 // Follow the system default theme.
1829 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
1830 } else {// The system default theme is not supported.
1831 // Follow the battery saver mode.
1832 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
1836 // Update the current theme status.
1837 currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
1840 case "webview_theme":
1841 // Get the new WebView theme.
1842 String newWebViewTheme = sharedPreferences.getString("webview_theme", context.getString(R.string.webview_theme_default_value));
1844 // Define a new WebView theme entry number.
1845 int newWebViewThemeEntryNumber;
1847 // 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.
1848 if (newWebViewTheme.equals(webViewThemeEntriesStringArray[1])) { // The light theme is selected.
1849 // Store the new WebView theme entry number.
1850 newWebViewThemeEntryNumber = 1;
1851 } else if (newWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
1852 // Store the WebView theme entry number.
1853 newWebViewThemeEntryNumber = 2;
1854 } else { // The system default theme is selected.
1855 // Store the WebView theme entry number.
1856 newWebViewThemeEntryNumber = 0;
1860 switch (newWebViewThemeEntryNumber) {
1861 case 0: // The system default WebView theme is selected.
1862 // Set the icon according to the app theme.
1863 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1864 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1866 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1870 case 1: // The system default WebView theme is selected.
1871 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1872 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1874 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
1878 case 2: // The system default WebView theme is selected.
1879 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1880 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
1882 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1887 // Set the current theme as the summary text for the preference.
1888 webViewThemePreference.setSummary(webViewThemeEntriesStringArray[newWebViewThemeEntryNumber]);
1891 case "wide_viewport":
1893 if (sharedPreferences.getBoolean("wide_viewport", true)) {
1894 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1895 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
1897 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
1900 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1901 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
1903 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
1908 case "display_webpage_images":
1910 if (sharedPreferences.getBoolean("display_webpage_images", true)) {
1911 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1912 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
1914 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
1917 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1918 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
1920 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
1928 private void restartPrivacyBrowser() {
1929 // Create an intent to restart Privacy Browser.
1930 Intent restartIntent = requireActivity().getParentActivityIntent();
1932 // Assert that the intent is not null to remove the lint error below.
1933 assert restartIntent != null;
1935 // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack. It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
1936 restartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
1938 // Create a handler to restart the activity.
1939 Handler restartHandler = new Handler(Looper.getMainLooper());
1941 // Create a runnable to restart the activity.
1942 Runnable restartRunnable = () -> {
1943 // Restart the activity.
1944 startActivity(restartIntent);
1946 // Kill this instance of Privacy Browser. Otherwise, the app exhibits sporadic behavior after the restart.
1950 // Restart the activity after 400 milliseconds, so that the app has enough time to save the change to the preference.
1951 restartHandler.postDelayed(restartRunnable, 400);