2 * Copyright © 2016-2021 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
6 * Privacy Browser is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacybrowser.fragments;
22 import android.annotation.SuppressLint;
23 import android.app.Activity;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.content.SharedPreferences;
27 import android.content.res.Configuration;
28 import android.content.res.Resources;
29 import android.os.Build;
30 import android.os.Bundle;
31 import android.os.Handler;
32 import android.os.Looper;
33 import android.view.LayoutInflater;
34 import android.view.View;
35 import android.webkit.WebView;
36 import android.widget.ArrayAdapter;
38 import androidx.appcompat.app.AppCompatDelegate;
39 import androidx.preference.Preference;
40 import androidx.preference.PreferenceCategory;
41 import androidx.preference.PreferenceFragmentCompat;
43 import com.stoutner.privacybrowser.R;
44 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
45 import com.stoutner.privacybrowser.helpers.ProxyHelper;
47 public class SettingsFragment extends PreferenceFragmentCompat {
48 // 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 displayAdditionalAppBarIconsPreference;
98 private Preference appThemePreference;
99 private Preference webViewThemePreference;
100 private Preference wideViewportPreference;
101 private Preference displayWebpageImagesPreference;
104 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
105 // Load the preferences from the XML file.
106 setPreferencesFromResource(R.xml.preferences, rootKey);
108 // Get a handle for the activity.
109 Activity activity = getActivity();
111 // Remove the lint warning below that `getApplicationContext()` might produce a null pointer exception.
112 assert activity != null;
114 // Get a handle for the resources.
115 Resources resources = getResources();
117 // Get the current theme status.
118 currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
120 // // Get a handle for the shared preferences.
121 SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
123 // Get handles for the preferences.
124 javaScriptPreference = findPreference("javascript");
125 cookiesPreference = findPreference(getString(R.string.cookies_key));
126 domStoragePreference = findPreference("dom_storage");
127 formDataPreference = findPreference("save_form_data"); // The form data preference can be removed once the minimum API >= 26.
128 userAgentPreference = findPreference("user_agent");
129 customUserAgentPreference = findPreference("custom_user_agent");
130 incognitoModePreference = findPreference("incognito_mode");
131 allowScreenshotsPreference = findPreference(getString(R.string.allow_screenshots_key));
132 easyListPreference = findPreference("easylist");
133 easyPrivacyPreference = findPreference("easyprivacy");
134 fanboyAnnoyanceListPreference = findPreference("fanboys_annoyance_list");
135 fanboySocialBlockingListPreference = findPreference("fanboys_social_blocking_list");
136 ultraListPreference = findPreference("ultralist");
137 ultraPrivacyPreference = findPreference("ultraprivacy");
138 blockAllThirdPartyRequestsPreference = findPreference("block_all_third_party_requests");
139 googleAnalyticsPreference = findPreference("google_analytics");
140 facebookClickIdsPreference = findPreference("facebook_click_ids");
141 twitterAmpRedirectsPreference = findPreference("twitter_amp_redirects");
142 searchPreference = findPreference("search");
143 searchCustomURLPreference = findPreference("search_custom_url");
144 proxyPreference = findPreference("proxy");
145 proxyCustomUrlPreference = findPreference("proxy_custom_url");
146 fullScreenBrowsingModePreference = findPreference("full_screen_browsing_mode");
147 hideAppBarPreference = findPreference("hide_app_bar");
148 clearEverythingPreference = findPreference("clear_everything");
149 clearCookiesPreference = findPreference("clear_cookies");
150 clearDomStoragePreference = findPreference("clear_dom_storage");
151 clearFormDataPreference = findPreference("clear_form_data"); // The clear form data preference can be removed once the minimum API >= 26.
152 clearLogcatPreference = findPreference(getString(R.string.clear_logcat_key));
153 clearCachePreference = findPreference("clear_cache");
154 homepagePreference = findPreference("homepage");
155 fontSizePreference = findPreference("font_size");
156 openIntentsInNewTabPreference = findPreference("open_intents_in_new_tab");
157 swipeToRefreshPreference = findPreference("swipe_to_refresh");
158 downloadWithExternalAppPreference = findPreference(getString(R.string.download_with_external_app_key));
159 scrollAppBarPreference = findPreference("scroll_app_bar");
160 displayAdditionalAppBarIconsPreference = findPreference(getString(R.string.display_additional_app_bar_icons_key));
161 appThemePreference = findPreference("app_theme");
162 webViewThemePreference = findPreference("webview_theme");
163 wideViewportPreference = findPreference("wide_viewport");
164 displayWebpageImagesPreference = findPreference("display_webpage_images");
166 // Remove the lint warnings below that the preferences might be null.
167 assert javaScriptPreference != null;
168 assert cookiesPreference != null;
169 assert domStoragePreference != null;
170 assert formDataPreference != null;
171 assert userAgentPreference != null;
172 assert customUserAgentPreference != null;
173 assert incognitoModePreference != null;
174 assert allowScreenshotsPreference != null;
175 assert easyListPreference != null;
176 assert easyPrivacyPreference != null;
177 assert fanboyAnnoyanceListPreference != null;
178 assert fanboySocialBlockingListPreference != null;
179 assert ultraListPreference != null;
180 assert ultraPrivacyPreference != null;
181 assert blockAllThirdPartyRequestsPreference != null;
182 assert googleAnalyticsPreference != null;
183 assert facebookClickIdsPreference != null;
184 assert twitterAmpRedirectsPreference != null;
185 assert searchPreference != null;
186 assert searchCustomURLPreference != null;
187 assert proxyPreference != null;
188 assert proxyCustomUrlPreference != null;
189 assert fullScreenBrowsingModePreference != null;
190 assert hideAppBarPreference != null;
191 assert clearEverythingPreference != null;
192 assert clearCookiesPreference != null;
193 assert clearDomStoragePreference != null;
194 assert clearFormDataPreference != null;
195 assert clearLogcatPreference != null;
196 assert clearCachePreference != null;
197 assert homepagePreference != null;
198 assert fontSizePreference != null;
199 assert openIntentsInNewTabPreference != null;
200 assert swipeToRefreshPreference != null;
201 assert downloadWithExternalAppPreference != null;
202 assert scrollAppBarPreference != null;
203 assert displayAdditionalAppBarIconsPreference != null;
204 assert appThemePreference != null;
205 assert webViewThemePreference != null;
206 assert wideViewportPreference != null;
207 assert displayWebpageImagesPreference != null;
209 // Set the preference dependencies.
210 hideAppBarPreference.setDependency("full_screen_browsing_mode");
211 domStoragePreference.setDependency("javascript");
213 // Get strings from the preferences.
214 String userAgentName = sharedPreferences.getString("user_agent", getString(R.string.user_agent_default_value));
215 String searchString = sharedPreferences.getString("search", getString(R.string.search_default_value));
216 String proxyString = sharedPreferences.getString("proxy", getString(R.string.proxy_default_value));
218 // Get booleans that are used in multiple places from the preferences.
219 boolean javaScriptEnabled = sharedPreferences.getBoolean("javascript", false);
220 boolean fanboyAnnoyanceListEnabled = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
221 boolean fanboySocialBlockingEnabled = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
222 boolean fullScreenBrowsingMode = sharedPreferences.getBoolean("full_screen_browsing_mode", false);
223 boolean clearEverything = sharedPreferences.getBoolean("clear_everything", true);
225 // Remove the form data preferences if the API is >= 26 as they no longer do anything.
226 if (Build.VERSION.SDK_INT >= 26) {
227 // Get handles for the categories.
228 PreferenceCategory privacyCategory = findPreference("privacy");
229 PreferenceCategory clearAndExitCategory = findPreference("clear_and_exit");
231 // Remove the incorrect lint warnings below that the preference categories might be null.
232 assert privacyCategory != null;
233 assert clearAndExitCategory != null;
235 // Remove the form data preferences.
236 privacyCategory.removePreference(formDataPreference);
237 clearAndExitCategory.removePreference(clearFormDataPreference);
240 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list is disabled.
241 fanboySocialBlockingListPreference.setEnabled(!fanboyAnnoyanceListEnabled);
244 // Inflate a WebView to get the default user agent.
245 LayoutInflater inflater = getActivity().getLayoutInflater();
247 // `@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.
248 @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
250 // Get a handle for a bare WebView.
251 WebView bareWebView = bareWebViewLayout.findViewById(R.id.bare_webview);
253 // Get the default user agent.
254 defaultUserAgent = bareWebView.getSettings().getUserAgentString();
256 // Get the user agent arrays.
257 userAgentNamesArray = ArrayAdapter.createFromResource(requireContext(), R.array.user_agent_names, R.layout.spinner_item);
258 translatedUserAgentNamesArray = resources.getStringArray(R.array.translated_user_agent_names);
259 userAgentDataArray = resources.getStringArray(R.array.user_agent_data);
261 // Get the array position of the user agent name.
262 int userAgentArrayPosition = userAgentNamesArray.getPosition(userAgentName);
264 // Populate the user agent summary.
265 switch (userAgentArrayPosition) {
266 case MainWebViewActivity.UNRECOGNIZED_USER_AGENT: // The user agent name is not on the canonical list.
267 // 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.
268 userAgentPreference.setSummary(userAgentName);
271 case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
272 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
273 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + defaultUserAgent);
276 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
277 // Set the summary text.
278 userAgentPreference.setSummary(R.string.custom_user_agent);
282 // Get the user agent summary from the user agent data array.
283 userAgentPreference.setSummary(translatedUserAgentNamesArray[userAgentArrayPosition] + ":\n" + userAgentDataArray[userAgentArrayPosition]);
286 // Set the summary text for the custom user agent preference.
287 customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", getString(R.string.custom_user_agent_default_value)));
289 // Only enable the custom user agent preference if the user agent is set to `Custom`.
290 customUserAgentPreference.setEnabled(userAgentPreference.getSummary().equals(getString(R.string.custom_user_agent)));
293 // Set the search URL as the summary text for the search preference when the preference screen is loaded.
294 if (searchString.equals("Custom URL")) {
295 // Use R.string.custom_url, which will be translated, instead of the array value, which will not.
296 searchPreference.setSummary(R.string.custom_url);
298 // Set the array value as the summary text.
299 searchPreference.setSummary(searchString);
302 // Set the summary text for the search custom URL (the default is `""`).
303 searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", getString(R.string.search_custom_url_default_value)));
305 // Only enable the search custom URL preference if the search is set to `Custom URL`.
306 searchCustomURLPreference.setEnabled(searchString.equals("Custom URL"));
309 // Set the summary text for the proxy preference when the preference screen is loaded.
310 switch (proxyString) {
311 case ProxyHelper.NONE:
312 proxyPreference.setSummary(getString(R.string.no_proxy_enabled));
315 case ProxyHelper.TOR:
316 if (Build.VERSION.SDK_INT == 19) { // Proxying through SOCKS doesn't work on Android KitKat.
317 proxyPreference.setSummary(getString(R.string.tor_enabled_kitkat));
319 proxyPreference.setSummary(getString(R.string.tor_enabled));
323 case ProxyHelper.I2P:
324 proxyPreference.setSummary(getString(R.string.i2p_enabled));
327 case ProxyHelper.CUSTOM:
328 proxyPreference.setSummary(getString(R.string.custom_proxy));
332 // Set the summary text for the custom proxy URL.
333 proxyCustomUrlPreference.setSummary(sharedPreferences.getString("proxy_custom_url", getString(R.string.proxy_custom_url_default_value)));
335 // Only enable the custom proxy URL if a custom proxy is selected.
336 proxyCustomUrlPreference.setEnabled(proxyString.equals("Custom"));
339 // Set the status of the clear and exit preferences.
340 clearCookiesPreference.setEnabled(!clearEverything);
341 clearDomStoragePreference.setEnabled(!clearEverything);
342 clearFormDataPreference.setEnabled(!clearEverything); // The form data line can be removed once the minimum API is >= 26.
343 clearLogcatPreference.setEnabled(!clearEverything);
344 clearCachePreference.setEnabled(!clearEverything);
347 // Set the homepage URL as the summary text for the homepage preference.
348 homepagePreference.setSummary(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
351 // Set the font size as the summary text for the preference.
352 fontSizePreference.setSummary(sharedPreferences.getString("font_size", getString(R.string.font_size_default_value)) + "%");
355 // Get the app theme string arrays.
356 appThemeEntriesStringArray = resources.getStringArray(R.array.app_theme_entries);
357 appThemeEntryValuesStringArray = resources.getStringArray(R.array.app_theme_entry_values);
359 // Get the current app theme.
360 String currentAppTheme = sharedPreferences.getString("app_theme", getString(R.string.app_theme_default_value));
362 // Define an app theme entry number.
363 int appThemeEntryNumber;
365 // 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.
366 if (currentAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected.
367 // Store the app theme entry number.
368 appThemeEntryNumber = 1;
369 } else if (currentAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected.
370 // Store the app theme entry number.
371 appThemeEntryNumber = 2;
372 } else { // The system default theme is selected.
373 // Store the app theme entry number.
374 appThemeEntryNumber = 0;
377 // Set the current theme as the summary text for the preference.
378 appThemePreference.setSummary(appThemeEntriesStringArray[appThemeEntryNumber]);
381 // Get the WebView theme string arrays.
382 webViewThemeEntriesStringArray = resources.getStringArray(R.array.webview_theme_entries);
383 webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values);
385 // Get the current WebView theme.
386 String currentWebViewTheme = sharedPreferences.getString("webview_theme", getString(R.string.webview_theme_default_value));
388 // Define a WebView theme entry number.
389 int webViewThemeEntryNumber;
391 // 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.
392 if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[1])) { // The light theme is selected.
393 // Store the WebView theme entry number.
394 webViewThemeEntryNumber = 1;
395 } else if (currentWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
396 // Store the WebView theme entry number.
397 webViewThemeEntryNumber = 2;
398 } else { // The system default theme is selected.
399 // Store the WebView theme entry number.
400 webViewThemeEntryNumber = 0;
403 // Set the visibility of the WebView theme preference.
404 if (Build.VERSION.SDK_INT < 21) { // The device is running API 19.
405 // Get a handle for the general category.
406 PreferenceCategory generalCategory = findPreference("general");
408 // Remove the incorrect lint warning below that the general preference category might be null.
409 assert generalCategory != null;
411 // Remove the WebView theme preference.
412 generalCategory.removePreference(webViewThemePreference);
413 } else { // The device is running API >= 21
414 // Set the current theme as the summary text for the preference.
415 webViewThemePreference.setSummary(webViewThemeEntriesStringArray[webViewThemeEntryNumber]);
419 // Set the JavaScript icon.
420 if (javaScriptEnabled) {
421 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
423 javaScriptPreference.setIcon(R.drawable.privacy_mode);
426 // Set the cookies icon.
427 if (sharedPreferences.getBoolean(getString(R.string.cookies_key), false)) {
428 cookiesPreference.setIcon(R.drawable.cookies_enabled);
430 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
431 cookiesPreference.setIcon(R.drawable.cookies_disabled_day);
433 cookiesPreference.setIcon(R.drawable.cookies_disabled_night);
437 // Set the DOM storage icon.
438 if (javaScriptEnabled) { // The preference is enabled.
439 if (sharedPreferences.getBoolean("dom_storage", false)) { // DOM storage is enabled.
440 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
441 } else { // DOM storage is disabled.
442 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
443 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
445 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
448 } else { // The preference is disabled. The icon should be ghosted.
449 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
450 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
452 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
456 // Set the save form data icon if API < 26. Save form data has no effect on API >= 26.
457 if (Build.VERSION.SDK_INT < 26) {
458 if (sharedPreferences.getBoolean("save_form_data", false)) {
459 formDataPreference.setIcon(R.drawable.form_data_enabled);
461 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
462 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
464 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
469 // Set the custom user agent icon.
470 if (customUserAgentPreference.isEnabled()) {
471 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
472 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
474 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
477 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
478 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
480 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
484 // Set the incognito mode icon.
485 if (sharedPreferences.getBoolean("incognito_mode", false)) {
486 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
487 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
489 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
492 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
493 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
495 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
499 // Set the allow screenshots icon.
500 if (sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)) {
501 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
502 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
504 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
507 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
508 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
510 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
514 // Set the EasyList icon.
515 if (sharedPreferences.getBoolean("easylist", true)) {
516 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
517 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
519 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
522 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
523 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
525 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
529 // Set the EasyPrivacy icon.
530 if (sharedPreferences.getBoolean("easyprivacy", true)) {
531 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
532 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
534 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
537 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
538 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
540 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
544 // Set the Fanboy lists icons.
545 if (fanboyAnnoyanceListEnabled) {
546 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
547 // Set the Fanboy annoyance list icon.
548 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
550 // Set the Fanboy social blocking list icon.
551 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
553 // Set the Fanboy annoyance list icon.
554 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
556 // Set the Fanboy social blocking list icon.
557 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
560 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
561 // Set the Fanboy annoyance list icon.
562 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
564 // Set the Fanboy social blocking list icon.
565 if (fanboySocialBlockingEnabled) {
566 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
568 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
571 // Set the Fanboy annoyance list icon.
572 fanboyAnnoyanceListPreference.setIcon(R.drawable.block_ads_disabled_day);
574 // Set the Fanboy social blocking list icon.
575 if (fanboySocialBlockingEnabled) {
576 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
578 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
583 // Set the UltraList icon.
584 if (sharedPreferences.getBoolean("ultralist", true)){
585 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
586 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
588 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
591 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
592 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
594 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
598 // Set the UltraPrivacy icon.
599 if (sharedPreferences.getBoolean("ultraprivacy", true)) {
600 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
601 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
603 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
606 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
607 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
609 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
613 // Set the block all third-party requests icon.
614 if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
615 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
616 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
618 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
621 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
622 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
624 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
628 // Set the Google Analytics icon according to the theme.
629 if (sharedPreferences.getBoolean("google_analytics", true)) {
630 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
631 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
633 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
636 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
637 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
639 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
643 // Set the Facebook Click IDs icon according to the theme.
644 if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
645 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
646 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
648 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
651 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
652 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
654 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
658 // Set the Twitter AMP redirects icon according to the theme.
659 if (sharedPreferences.getBoolean("twitter_amp_redirects", true)) {
660 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
661 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
663 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
666 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
667 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
669 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
673 // Set the search custom URL icon.
674 if (searchCustomURLPreference.isEnabled()) {
675 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
676 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
678 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
681 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
682 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
684 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
688 // Set the Proxy icons according to the theme and status.
689 if (proxyString.equals("None")) { // Proxying is disabled.
690 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
691 // Set the main proxy icon to be disabled.
692 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
694 // Set the custom proxy URL icon to be ghosted.
695 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
696 } else { // Light theme.
697 // Set the main proxy icon to be disabled.
698 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
700 // Set the custom proxy URL icon to be ghosted.
701 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
703 } else { // Proxying is enabled.
704 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
705 // Set the main proxy icon to be enabled.
706 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
708 // Set the custom proxy URL icon according to its status.
709 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
710 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
711 } else { // Custom proxy is disabled.
712 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
714 } else { // Light theme.
715 // Set the main proxy icon to be enabled.
716 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
718 // Set the custom proxy URL icon according to its status.
719 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
720 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
721 } else { // Custom proxy is disabled.
722 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
727 // Set the full screen browsing mode icons.
728 if (fullScreenBrowsingMode) { // Full screen browsing mode is enabled.
729 // Set the `fullScreenBrowsingModePreference` icon according to the theme.
730 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
731 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
733 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
736 // Set the hide app bar icon.
737 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
738 // Set the icon according to the theme.
739 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
740 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
742 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
744 } else { // Hide app bar is disabled.
745 // Set the icon according to the theme.
746 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
747 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
749 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
752 } else { // Full screen browsing mode is disabled.
753 // Set the icons according to the theme.
754 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
755 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
756 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
758 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
759 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
763 // Set the clear everything preference icon.
764 if (clearEverything) {
765 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
766 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
768 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
771 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
774 // Set the clear cookies preference icon.
775 if (clearEverything || sharedPreferences.getBoolean("clear_cookies", true)) {
776 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
777 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
779 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
782 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
785 // Set the clear DOM storage preference icon.
786 if (clearEverything || sharedPreferences.getBoolean("clear_dom_storage", true)) {
787 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
788 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
790 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
793 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
796 // Set the clear form data preference icon if the API < 26. It has no effect on newer versions of Android.
797 if (Build.VERSION.SDK_INT < 26) {
798 if (clearEverything || sharedPreferences.getBoolean("clear_form_data", true)) {
799 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
800 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
802 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
805 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
809 // Set the clear logcat preference icon.
810 if (clearEverything || sharedPreferences.getBoolean(getString(R.string.clear_logcat_key), true)) {
811 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
812 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
814 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
817 clearLogcatPreference.setIcon(R.drawable.bug_warning);
820 // Set the clear cache preference icon.
821 if (clearEverything || sharedPreferences.getBoolean("clear_cache", true)) {
822 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
823 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
825 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
828 clearCachePreference.setIcon(R.drawable.cache_warning);
831 // Set the open intents in new tab preference icon.
832 if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
833 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
834 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
836 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
839 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
840 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
842 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
846 // Set the swipe to refresh preference icon.
847 if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
848 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
849 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
851 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
854 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
855 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
857 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
861 // Set the download with external app preference icon.
862 if (sharedPreferences.getBoolean(getString(R.string.download_with_external_app_key), false)) {
863 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
864 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_day);
866 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_night);
869 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
870 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_day);
872 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_night);
876 // Set the scroll app bar preference icon.
877 if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
878 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
879 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
881 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
884 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
885 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
887 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
891 // Set the display additional app bar icons preference icon.
892 if (sharedPreferences.getBoolean(getString(R.string.display_additional_app_bar_icons_key), false)) {
893 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
894 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
896 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
899 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
900 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
902 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
906 // Set the WebView theme preference icon.
907 switch (webViewThemeEntryNumber) {
908 case 0: // The system default WebView theme is selected.
909 // Set the icon according to the app theme.
910 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
911 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
913 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
917 case 1: // The light WebView theme is selected.
918 // Set the icon according to the app theme.
919 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
920 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
922 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
926 case 2: // The dark WebView theme is selected.
927 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
928 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
930 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
935 // Set the wide viewport preference icon.
936 if (sharedPreferences.getBoolean("wide_viewport", true)) {
937 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
938 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
940 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
943 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
944 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
946 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
950 // Set the display webpage images preference icon.
951 if (sharedPreferences.getBoolean("display_webpage_images", true)) {
952 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
953 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
955 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
958 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
959 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
961 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);
965 // Get the shared preferences change listener.
966 sharedPreferenceChangeListener = getSharedPreferencesChangeListener(requireContext());
968 // Register the listener.
969 sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
972 // The listener should be unregistered when the app is paused.
974 public void onPause() {
975 // Run the default commands.
978 // Get a handle for the shared preferences.
979 SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
981 // Unregister the shared preferences listener.
982 sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
985 // The listener should be re-registered when the app is resumed.
987 public void onResume() {
988 // Run the default commands.
991 // Get a new shared preferences change listener.
992 sharedPreferenceChangeListener = getSharedPreferencesChangeListener(requireContext());
994 // Get a handle for the shared preferences.
995 SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
997 // Re-register the shared preferences listener.
998 sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
1001 // 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.
1002 private SharedPreferences.OnSharedPreferenceChangeListener getSharedPreferencesChangeListener(Context context) {
1003 // Return the shared preference change listener.
1004 return (SharedPreferences sharedPreferences, String key) -> {
1007 // Update the icons and the DOM storage preference status.
1008 if (sharedPreferences.getBoolean("javascript", false)) { // The JavaScript preference is enabled.
1009 // Update the icon for the JavaScript preference.
1010 javaScriptPreference.setIcon(R.drawable.javascript_enabled);
1012 // Update the status of the DOM storage preference.
1013 domStoragePreference.setEnabled(true);
1015 // Update the icon for the DOM storage preference.
1016 if (sharedPreferences.getBoolean("dom_storage", false)) {
1017 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1019 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1020 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1022 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1025 } else { // The JavaScript preference is disabled.
1026 // Update the icon for the JavaScript preference.
1027 javaScriptPreference.setIcon(R.drawable.privacy_mode);
1029 // Update the status of the DOM storage preference.
1030 domStoragePreference.setEnabled(false);
1032 // Set the icon for DOM storage preference to be ghosted.
1033 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1034 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_day);
1036 domStoragePreference.setIcon(R.drawable.dom_storage_ghosted_night);
1043 if (sharedPreferences.getBoolean(context.getString(R.string.cookies_key), false)) {
1044 cookiesPreference.setIcon(R.drawable.cookies_enabled);
1046 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1047 cookiesPreference.setIcon(R.drawable.cookies_disabled_day);
1049 cookiesPreference.setIcon(R.drawable.cookies_disabled_night);
1056 if (sharedPreferences.getBoolean("dom_storage", false)) {
1057 domStoragePreference.setIcon(R.drawable.dom_storage_enabled);
1059 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1060 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_day);
1062 domStoragePreference.setIcon(R.drawable.dom_storage_disabled_night);
1067 // Save form data can be removed once the minimum API >= 26.
1068 case "save_form_data":
1070 if (sharedPreferences.getBoolean("save_form_data", false)) {
1071 formDataPreference.setIcon(R.drawable.form_data_enabled);
1073 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1074 formDataPreference.setIcon(R.drawable.form_data_disabled_day);
1076 formDataPreference.setIcon(R.drawable.form_data_disabled_night);
1082 // Get the new user agent name.
1083 String newUserAgentName = sharedPreferences.getString("user_agent", context.getString(R.string.user_agent_default_value));
1085 // Get the array position for the new user agent name.
1086 int newUserAgentArrayPosition = userAgentNamesArray.getPosition(newUserAgentName);
1088 // Get the translated new user agent name.
1089 String translatedNewUserAgentName = translatedUserAgentNamesArray[newUserAgentArrayPosition];
1091 // Populate the user agent summary.
1092 switch (newUserAgentArrayPosition) {
1093 case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
1094 // Get the user agent text from the webview (which changes based on the version of Android and WebView installed).
1095 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + defaultUserAgent);
1097 // Disable the custom user agent preference.
1098 customUserAgentPreference.setEnabled(false);
1100 // Set the custom user agent preference icon according to the theme.
1101 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1102 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1104 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1108 case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
1109 // Set the summary text.
1110 userAgentPreference.setSummary(R.string.custom_user_agent);
1112 // Enable the custom user agent preference.
1113 customUserAgentPreference.setEnabled(true);
1115 // Set the custom user agent preference icon according to the theme.
1116 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1117 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_night);
1119 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_enabled_day);
1124 // Get the user agent summary from the user agent data array.
1125 userAgentPreference.setSummary(translatedNewUserAgentName + ":\n" + userAgentDataArray[newUserAgentArrayPosition]);
1127 // Disable the custom user agent preference.
1128 customUserAgentPreference.setEnabled(false);
1130 // Set the custom user agent preference icon according to the theme.
1131 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1132 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_night);
1134 customUserAgentPreference.setIcon(R.drawable.custom_user_agent_ghosted_day);
1139 case "custom_user_agent":
1140 // Set the new custom user agent as the summary text for the preference.
1141 customUserAgentPreference.setSummary(sharedPreferences.getString("custom_user_agent", context.getString(R.string.custom_user_agent_default_value)));
1144 case "incognito_mode":
1146 if (sharedPreferences.getBoolean("incognito_mode", false)) {
1147 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1148 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_night);
1150 incognitoModePreference.setIcon(R.drawable.incognito_mode_enabled_day);
1153 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1154 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_night);
1156 incognitoModePreference.setIcon(R.drawable.incognito_mode_disabled_day);
1161 case "allow_screenshots":
1163 if (sharedPreferences.getBoolean(context.getString(R.string.allow_screenshots_key), false)) {
1164 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1165 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_day);
1167 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_enabled_night);
1170 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1171 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_day);
1173 allowScreenshotsPreference.setIcon(R.drawable.allow_screenshots_disabled_night);
1177 // Create an intent to restart Privacy Browser.
1178 Intent allowScreenshotsRestartIntent = requireActivity().getParentActivityIntent();
1180 // Assert that the intent is not null to remove the lint error below.
1181 assert allowScreenshotsRestartIntent != null;
1183 // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack. It requires `Intent.FLAG_ACTIVITY_NEW_TASK`.
1184 allowScreenshotsRestartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
1186 // Create a handler to restart the activity.
1187 Handler allowScreenshotsRestartHandler = new Handler(Looper.getMainLooper());
1189 // Create a runnable to restart the activity.
1190 Runnable allowScreenshotsRestartRunnable = () -> {
1191 // Restart the activity.
1192 startActivity(allowScreenshotsRestartIntent);
1194 // Kill this instance of Privacy Browser. Otherwise, the app exhibits sporadic behavior after the restart.
1198 // Restart the activity after 150 milliseconds, so that the app has enough time to save the change to the preference.
1199 allowScreenshotsRestartHandler.postDelayed(allowScreenshotsRestartRunnable, 150);
1204 if (sharedPreferences.getBoolean("easylist", true)) {
1205 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1206 easyListPreference.setIcon(R.drawable.block_ads_enabled_night);
1208 easyListPreference.setIcon(R.drawable.block_ads_enabled_day);
1211 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1212 easyListPreference.setIcon(R.drawable.block_ads_disabled_night);
1214 easyListPreference.setIcon(R.drawable.block_ads_disabled_day);
1221 if (sharedPreferences.getBoolean("easyprivacy", true)) {
1222 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1223 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1225 easyPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1228 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1229 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1231 easyPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1236 case "fanboys_annoyance_list":
1237 boolean currentFanboyAnnoyanceList = sharedPreferences.getBoolean("fanboys_annoyance_list", true);
1238 boolean currentFanboySocialBlockingList = sharedPreferences.getBoolean("fanboys_social_blocking_list", true);
1240 // Update the Fanboy icons.
1241 if (currentFanboyAnnoyanceList) { // Fanboy's annoyance list is enabled.
1242 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1243 // Update the Fanboy's annoyance list icon.
1244 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_night);
1246 // Update the Fanboy's social blocking list icon.
1247 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_night);
1249 // Update the Fanboy's annoyance list icon.
1250 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_enabled_day);
1252 // Update the Fanboy's social blocking list icon.
1253 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_ghosted_day);
1255 } else { // Fanboy's annoyance list is disabled.
1256 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1257 // Update the Fanboy's annoyance list icon.
1258 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_night);
1260 // Update the Fanboy's social blocking list icon.
1261 if (currentFanboySocialBlockingList) {
1262 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1264 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1267 // Update the Fanboy's annoyance list icon.
1268 fanboyAnnoyanceListPreference.setIcon(R.drawable.social_media_disabled_day);
1270 // Update the Fanboy's social blocking list icon.
1271 if (currentFanboySocialBlockingList) {
1272 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1274 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1279 // Only enable Fanboy's social blocking list preference if Fanboy's annoyance list preference is disabled.
1280 fanboySocialBlockingListPreference.setEnabled(!currentFanboyAnnoyanceList);
1283 case "fanboys_social_blocking_list":
1285 if (sharedPreferences.getBoolean("fanboys_social_blocking_list", true)) {
1286 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1287 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_night);
1289 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_enabled_day);
1292 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1293 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_night);
1295 fanboySocialBlockingListPreference.setIcon(R.drawable.social_media_disabled_day);
1302 if (sharedPreferences.getBoolean("ultralist", true)) {
1303 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1304 ultraListPreference.setIcon(R.drawable.block_ads_enabled_night);
1306 ultraListPreference.setIcon(R.drawable.block_ads_enabled_day);
1309 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1310 ultraListPreference.setIcon(R.drawable.block_ads_disabled_night);
1312 ultraListPreference.setIcon(R.drawable.block_ads_disabled_day);
1317 case "ultraprivacy":
1319 if (sharedPreferences.getBoolean("ultraprivacy", true)) {
1320 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1321 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_night);
1323 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_enabled_day);
1326 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1327 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_night);
1329 ultraPrivacyPreference.setIcon(R.drawable.block_tracking_disabled_day);
1334 case "block_all_third_party_requests":
1336 if (sharedPreferences.getBoolean("block_all_third_party_requests", false)) {
1337 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1338 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_night);
1340 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_enabled_day);
1343 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1344 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_night);
1346 blockAllThirdPartyRequestsPreference.setIcon(R.drawable.block_all_third_party_requests_disabled_day);
1351 case "google_analytics":
1353 if (sharedPreferences.getBoolean("google_analytics", true)) {
1354 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1355 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_night);
1357 googleAnalyticsPreference.setIcon(R.drawable.modify_url_enabled_day);
1360 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1361 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_night);
1363 googleAnalyticsPreference.setIcon(R.drawable.modify_url_disabled_day);
1368 case "facebook_click_ids":
1370 if (sharedPreferences.getBoolean("facebook_click_ids", true)) {
1371 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1372 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_night);
1374 facebookClickIdsPreference.setIcon(R.drawable.modify_url_enabled_day);
1377 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1378 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_night);
1380 facebookClickIdsPreference.setIcon(R.drawable.modify_url_disabled_day);
1385 case "twitter_amp_redirects":
1387 if (sharedPreferences.getBoolean("twitter_amp_redirects", true)) {
1388 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1389 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_night);
1391 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_enabled_day);
1394 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1395 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_night);
1397 twitterAmpRedirectsPreference.setIcon(R.drawable.modify_url_disabled_day);
1403 // Store the new search string.
1404 String newSearchString = sharedPreferences.getString("search", context.getString(R.string.search_default_value));
1406 // Update the search and search custom URL preferences.
1407 if (newSearchString.equals("Custom URL")) { // `Custom URL` is selected.
1408 // Set the summary text to `R.string.custom_url`, which is translated.
1409 searchPreference.setSummary(R.string.custom_url);
1411 // Enable `searchCustomURLPreference`.
1412 searchCustomURLPreference.setEnabled(true);
1414 // Set the `searchCustomURLPreference` according to the theme.
1415 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1416 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_night);
1418 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_enabled_day);
1420 } else { // `Custom URL` is not selected.
1421 // Set the summary text to `newSearchString`.
1422 searchPreference.setSummary(newSearchString);
1424 // Disable `searchCustomURLPreference`.
1425 searchCustomURLPreference.setEnabled(false);
1427 // Set the `searchCustomURLPreference` according to the theme.
1428 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1429 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_night);
1431 searchCustomURLPreference.setIcon(R.drawable.search_custom_url_ghosted_day);
1436 case "search_custom_url":
1437 // Set the new search custom URL as the summary text for the preference.
1438 searchCustomURLPreference.setSummary(sharedPreferences.getString("search_custom_url", context.getString(R.string.search_custom_url_default_value)));
1442 // Get current proxy string.
1443 String currentProxyString = sharedPreferences.getString("proxy", context.getString(R.string.proxy_default_value));
1445 // Update the summary text for the proxy preference.
1446 switch (currentProxyString) {
1447 case ProxyHelper.NONE:
1448 proxyPreference.setSummary(context.getString(R.string.no_proxy_enabled));
1451 case ProxyHelper.TOR:
1452 if (Build.VERSION.SDK_INT == 19) { // Proxying through SOCKS doesn't work on Android KitKat.
1453 proxyPreference.setSummary(context.getString(R.string.tor_enabled_kitkat));
1455 proxyPreference.setSummary(context.getString(R.string.tor_enabled));
1459 case ProxyHelper.I2P:
1460 proxyPreference.setSummary(context.getString(R.string.i2p_enabled));
1463 case ProxyHelper.CUSTOM:
1464 proxyPreference.setSummary(context.getString(R.string.custom_proxy));
1468 // Update the status of the custom URL preference.
1469 proxyCustomUrlPreference.setEnabled(currentProxyString.equals("Custom"));
1471 // Update the icons.
1472 if (currentProxyString.equals("None")) { // Proxying is disabled.
1473 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
1474 // Set the main proxy icon to be disabled
1475 proxyPreference.setIcon(R.drawable.proxy_disabled_night);
1477 // Set the custom proxy URL icon to be ghosted.
1478 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1479 } else { // Light theme.
1480 // Set the main proxy icon to be disabled.
1481 proxyPreference.setIcon(R.drawable.proxy_disabled_day);
1483 // Set the custom proxy URL icon to be ghosted.
1484 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1486 } else { // Proxying is enabled.
1487 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) { // Dark theme.
1488 // Set the main proxy icon to be enabled.
1489 proxyPreference.setIcon(R.drawable.proxy_enabled_night);
1491 /// Set the custom proxy URL icon according to its status.
1492 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
1493 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_night);
1494 } else { // Custom proxy is disabled.
1495 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_night);
1497 } else { // Light theme.
1498 // Set the main proxy icon to be enabled.
1499 proxyPreference.setIcon(R.drawable.proxy_enabled_day);
1501 // Set the custom proxy URL icon according to its status.
1502 if (proxyCustomUrlPreference.isEnabled()) { // Custom proxy is enabled.
1503 proxyCustomUrlPreference.setIcon(R.drawable.proxy_enabled_day);
1504 } else { // Custom proxy is disabled.
1505 proxyCustomUrlPreference.setIcon(R.drawable.proxy_ghosted_day);
1511 case "proxy_custom_url":
1512 // Set the summary text for the proxy custom URL.
1513 proxyCustomUrlPreference.setSummary(sharedPreferences.getString("proxy_custom_url", context.getString(R.string.proxy_custom_url_default_value)));
1516 case "full_screen_browsing_mode":
1517 if (sharedPreferences.getBoolean("full_screen_browsing_mode", false)) { // Full screen browsing is enabled.
1518 // Set the full screen browsing mode preference icon according to the theme.
1519 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1520 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_night);
1522 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_enabled_day);
1525 // Set the hide app bar preference icon.
1526 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
1527 // Set the icon according to the theme.
1528 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1529 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1531 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1533 } else { // Hide app bar is disabled.
1534 // Set the icon according to the theme.
1535 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1536 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1538 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1541 } else { // Full screen browsing is disabled.
1542 // Update the icons according to the theme.
1543 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1544 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_night);
1545 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_night);
1547 fullScreenBrowsingModePreference.setIcon(R.drawable.full_screen_disabled_day);
1548 hideAppBarPreference.setIcon(R.drawable.app_bar_ghosted_day);
1553 case "hide_app_bar":
1555 if (sharedPreferences.getBoolean("hide_app_bar", true)) { // Hide app bar is enabled.
1556 // Set the icon according to the theme.
1557 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1558 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1560 hideAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1562 } else { // Hide app bar is disabled.
1563 // Set the icon according to the theme.
1564 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1565 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1567 hideAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1572 case "clear_everything":
1573 // Store the new clear everything status
1574 boolean newClearEverythingBoolean = sharedPreferences.getBoolean("clear_everything", true);
1576 // Update the status of the clear and exit preferences.
1577 clearCookiesPreference.setEnabled(!newClearEverythingBoolean);
1578 clearDomStoragePreference.setEnabled(!newClearEverythingBoolean);
1579 clearFormDataPreference.setEnabled(!newClearEverythingBoolean); // This line can be removed once the minimum API >= 26.
1580 clearLogcatPreference.setEnabled(!newClearEverythingBoolean);
1581 clearCachePreference.setEnabled(!newClearEverythingBoolean);
1583 // Update the clear everything preference icon.
1584 if (newClearEverythingBoolean) {
1585 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1586 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_day);
1588 clearEverythingPreference.setIcon(R.drawable.clear_everything_enabled_night);
1591 clearEverythingPreference.setIcon(R.drawable.clear_everything_disabled);
1594 // Update the clear cookies preference icon.
1595 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cookies", true)) {
1596 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1597 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1599 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1602 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1605 // Update the clear dom storage preference icon.
1606 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_dom_storage", true)) {
1607 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1608 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1610 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1613 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1616 // Update the clear form data preference icon if the API < 26.
1617 if (Build.VERSION.SDK_INT < 26) {
1618 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_form_data", true)) {
1619 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1620 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1622 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1625 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1629 // Update the clear logcat preference icon.
1630 if (newClearEverythingBoolean || sharedPreferences.getBoolean(context.getString(R.string.clear_logcat_key), true)) {
1631 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1632 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1634 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1637 clearLogcatPreference.setIcon(R.drawable.cache_warning);
1640 // Update the clear cache preference icon.
1641 if (newClearEverythingBoolean || sharedPreferences.getBoolean("clear_cache", true)) {
1642 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1643 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1645 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1648 clearCachePreference.setIcon(R.drawable.cache_warning);
1652 case "clear_cookies":
1654 if (sharedPreferences.getBoolean("clear_cookies", true)) {
1655 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1656 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_day);
1658 clearCookiesPreference.setIcon(R.drawable.cookies_cleared_night);
1661 clearCookiesPreference.setIcon(R.drawable.cookies_warning);
1665 case "clear_dom_storage":
1667 if (sharedPreferences.getBoolean("clear_dom_storage", true)) {
1668 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1669 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_day);
1671 clearDomStoragePreference.setIcon(R.drawable.dom_storage_cleared_night);
1674 clearDomStoragePreference.setIcon(R.drawable.dom_storage_warning);
1678 // This section can be removed once the minimum API >= 26.
1679 case "clear_form_data":
1681 if (sharedPreferences.getBoolean("clear_form_data", true)) {
1682 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1683 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_day);
1685 clearFormDataPreference.setIcon(R.drawable.form_data_cleared_night);
1688 clearFormDataPreference.setIcon(R.drawable.form_data_warning);
1692 case "clear_logcat":
1694 if (sharedPreferences.getBoolean(context.getString(R.string.clear_logcat_key), true)) {
1695 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1696 clearLogcatPreference.setIcon(R.drawable.bug_cleared_day);
1698 clearLogcatPreference.setIcon(R.drawable.bug_cleared_night);
1701 clearLogcatPreference.setIcon(R.drawable.bug_warning);
1707 if (sharedPreferences.getBoolean("clear_cache", true)) {
1708 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1709 clearCachePreference.setIcon(R.drawable.cache_cleared_day);
1711 clearCachePreference.setIcon(R.drawable.cache_cleared_night);
1714 clearCachePreference.setIcon(R.drawable.cache_warning);
1719 // Set the new homepage URL as the summary text for the Homepage preference.
1720 homepagePreference.setSummary(sharedPreferences.getString("homepage", context.getString(R.string.homepage_default_value)));
1724 // Update the font size summary text.
1725 fontSizePreference.setSummary(sharedPreferences.getString("font_size", context.getString(R.string.font_size_default_value)) + "%");
1728 case "open_intents_in_new_tab":
1730 if (sharedPreferences.getBoolean("open_intents_in_new_tab", true)) {
1731 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1732 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_day);
1734 openIntentsInNewTabPreference.setIcon(R.drawable.tab_enabled_night);
1737 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1738 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_day);
1740 openIntentsInNewTabPreference.setIcon(R.drawable.tab_disabled_night);
1745 case "swipe_to_refresh":
1747 if (sharedPreferences.getBoolean("swipe_to_refresh", true)) {
1748 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1749 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_day);
1751 swipeToRefreshPreference.setIcon(R.drawable.refresh_enabled_night);
1754 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1755 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_day);
1757 swipeToRefreshPreference.setIcon(R.drawable.refresh_disabled_night);
1762 case "download_with_external_app":
1764 if (sharedPreferences.getBoolean(context.getString(R.string.download_with_external_app_key), false)) {
1765 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1766 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_day);
1768 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_enabled_night);
1771 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1772 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_day);
1774 downloadWithExternalAppPreference.setIcon(R.drawable.download_with_external_app_disabled_night);
1779 case "scroll_app_bar":
1781 if (sharedPreferences.getBoolean("scroll_app_bar", true)) {
1782 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1783 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_day);
1785 scrollAppBarPreference.setIcon(R.drawable.app_bar_enabled_night);
1788 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1789 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_day);
1791 scrollAppBarPreference.setIcon(R.drawable.app_bar_disabled_night);
1796 case "display_additional_app_bar_icons":
1798 if (sharedPreferences.getBoolean(context.getString(R.string.display_additional_app_bar_icons_key), false)) {
1799 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1800 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_day);
1802 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_enabled_night);
1805 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1806 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_day);
1808 displayAdditionalAppBarIconsPreference.setIcon(R.drawable.more_disabled_night);
1814 // Get the new theme.
1815 String newAppTheme = sharedPreferences.getString("app_theme", context.getString(R.string.app_theme_default_value));
1817 // 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.
1818 if (newAppTheme.equals(appThemeEntryValuesStringArray[1])) { // The light theme is selected.
1819 // Update the theme preference summary text.
1820 appThemePreference.setSummary(appThemeEntriesStringArray[1]);
1822 // Apply the new theme.
1823 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
1824 } else if (newAppTheme.equals(appThemeEntryValuesStringArray[2])) { // The dark theme is selected.
1825 // Update the theme preference summary text.
1826 appThemePreference.setSummary(appThemeEntriesStringArray[2]);
1828 // Apply the new theme.
1829 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
1830 } else { // The system default theme is selected.
1831 // Update the theme preference summary text.
1832 appThemePreference.setSummary(appThemeEntriesStringArray[0]);
1834 // Apply the new theme.
1835 if (Build.VERSION.SDK_INT >= 28) { // The system default theme is supported.
1836 // Follow the system default theme.
1837 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
1838 } else {// The system default theme is not supported.
1839 // Follow the battery saver mode.
1840 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY);
1844 // Update the current theme status.
1845 currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
1848 case "webview_theme":
1849 // Get the new WebView theme.
1850 String newWebViewTheme = sharedPreferences.getString("webview_theme", context.getString(R.string.webview_theme_default_value));
1852 // Define a new WebView theme entry number.
1853 int newWebViewThemeEntryNumber;
1855 // 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.
1856 if (newWebViewTheme.equals(webViewThemeEntriesStringArray[1])) { // The light theme is selected.
1857 // Store the new WebView theme entry number.
1858 newWebViewThemeEntryNumber = 1;
1859 } else if (newWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
1860 // Store the WebView theme entry number.
1861 newWebViewThemeEntryNumber = 2;
1862 } else { // The system default theme is selected.
1863 // Store the WebView theme entry number.
1864 newWebViewThemeEntryNumber = 0;
1868 switch (newWebViewThemeEntryNumber) {
1869 case 0: // The system default WebView theme is selected.
1870 // Set the icon according to the app theme.
1871 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1872 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1874 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1878 case 1: // The system default WebView theme is selected.
1879 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1880 webViewThemePreference.setIcon(R.drawable.webview_light_theme_day);
1882 webViewThemePreference.setIcon(R.drawable.webview_light_theme_night);
1886 case 2: // The system default WebView theme is selected.
1887 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
1888 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_day);
1890 webViewThemePreference.setIcon(R.drawable.webview_dark_theme_night);
1895 // Set the current theme as the summary text for the preference.
1896 webViewThemePreference.setSummary(webViewThemeEntriesStringArray[newWebViewThemeEntryNumber]);
1899 case "wide_viewport":
1901 if (sharedPreferences.getBoolean("wide_viewport", true)) {
1902 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1903 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_night);
1905 wideViewportPreference.setIcon(R.drawable.wide_viewport_enabled_day);
1908 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1909 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_night);
1911 wideViewportPreference.setIcon(R.drawable.wide_viewport_disabled_day);
1916 case "display_webpage_images":
1918 if (sharedPreferences.getBoolean("display_webpage_images", true)) {
1919 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1920 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_night);
1922 displayWebpageImagesPreference.setIcon(R.drawable.images_enabled_day);
1925 if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
1926 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_night);
1928 displayWebpageImagesPreference.setIcon(R.drawable.images_disabled_day);