2 * Copyright © 2017 Soren Stoutner <soren@stoutner.com>.
4 * Huawei spinner code fix contributed 2017 Thomas Jensen <lianergoist@vongriffen.dk>. Copyright assigned to Soren Stoutner <soren@stoutner.com>.
6 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
8 * Privacy Browser is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * Privacy Browser is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>.
22 package com.stoutner.privacybrowser.fragments;
24 import android.annotation.SuppressLint;
25 import android.content.Context;
26 import android.database.Cursor;
27 import android.os.Build;
28 import android.os.Bundle;
29 // We have to use `android.support.v4.app.Fragment` until minimum API >= 23. Otherwise we cannot call `getContext()`.
30 import android.support.v4.app.Fragment;
31 import android.view.LayoutInflater;
32 import android.view.View;
33 import android.view.ViewGroup;
34 import android.webkit.WebView;
35 import android.widget.AdapterView;
36 import android.widget.ArrayAdapter;
37 import android.widget.CompoundButton;
38 import android.widget.EditText;
39 import android.widget.ImageView;
40 import android.widget.LinearLayout;
41 import android.widget.Spinner;
42 import android.widget.Switch;
43 import android.widget.TextView;
45 import com.stoutner.privacybrowser.R;
46 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
47 import com.stoutner.privacybrowser.helpers.DomainsDatabaseHelper;
49 public class DomainSettingsFragment extends Fragment {
50 // `DATABASE_ID` is used by activities calling this fragment.
51 public static final String DATABASE_ID = "database_id";
53 // `databaseId` is used in `onCreate()` and `onCreateView()`.
54 private int databaseId;
57 public void onCreate(Bundle savedInstanceState) {
58 super.onCreate(savedInstanceState);
60 // Store the database id in `databaseId`.
61 databaseId = getArguments().getInt(DATABASE_ID);
64 // We have to use the deprecated `getDrawable()` until the minimum API >= 21.
65 @SuppressWarnings("deprecation")
67 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
68 // Inflate `domain_settings`. `false` does not attach it to the root `container`.
69 View domainSettingsView = inflater.inflate(R.layout.domain_settings, container, false);
71 // Get a handle for the `Context`.
72 Context context = getContext();
74 // Get handles for the views in the fragment.
75 EditText domainNameEditText = (EditText) domainSettingsView.findViewById(R.id.domain_settings_name_edittext);
76 Switch javaScriptEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_javascript_switch);
77 final ImageView javaScriptImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_javascript_imageview);
78 Switch firstPartyCookiesEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_first_party_cookies_switch);
79 final ImageView firstPartyCookiesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_first_party_cookies_imageview);
80 LinearLayout thirdPartyCookiesLinearLayout = (LinearLayout) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_linearlayout);
81 final Switch thirdPartyCookiesEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_switch);
82 final ImageView thirdPartyCookiesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_imageview);
83 final Switch domStorageEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_dom_storage_switch);
84 final ImageView domStorageImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_dom_storage_imageview);
85 Switch formDataEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_form_data_switch);
86 final ImageView formDataImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_form_data_imageview);
87 Spinner userAgentSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_user_agent_spinner);
88 final TextView userAgentTextView = (TextView) domainSettingsView.findViewById(R.id.domain_settings_user_agent_textview);
89 final EditText customUserAgentEditText = (EditText) domainSettingsView.findViewById(R.id.domain_settings_custom_user_agent_edittext);
90 Spinner fontSizeSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_font_size_spinner);
91 final ImageView displayWebpageImagesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_imageview);
92 Spinner displayWebpageImagesSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_spinner);
94 // Initialize the database handler. `this` specifies the context. The two `nulls` do not specify the database name or a `CursorFactory`.
95 // The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
96 DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(getContext(), null, null, 0);
98 // Get the database `Cursor` for this ID and move it to the first row.
99 Cursor domainCursor = domainsDatabaseHelper.getCursorForId(databaseId);
100 domainCursor.moveToFirst();
102 // Save the `Cursor` entries as variables.
103 String domainNameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME));
104 int javaScriptEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT));
105 int firstPartyCookiesEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES));
106 int thirdPartyCookiesEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES));
107 int domStorageEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE));
108 int formDataEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA));
109 final String currentUserAgentString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT));
110 int fontSizeInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE));
111 int displayImagesInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES));
113 // Create `ArrayAdapters` for the `Spinners`and their `entry values`.
114 ArrayAdapter<CharSequence> userAgentArrayAdapter = ArrayAdapter.createFromResource(context, R.array.user_agent_entries, android.R.layout.simple_spinner_item);
115 final ArrayAdapter<CharSequence> userAgentEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.user_agent_entry_values, android.R.layout.simple_spinner_item);
116 ArrayAdapter<CharSequence> fontSizeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.default_font_size_entries, android.R.layout.simple_spinner_item);
117 ArrayAdapter<CharSequence> fontSizeEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.default_font_size_entry_values, android.R.layout.simple_spinner_item);
118 final ArrayAdapter<CharSequence> displayImagesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.display_website_images_array, android.R.layout.simple_spinner_item);
120 // Some phones running Huawei's customized Android 7.0 have layout problems displaying a spinner with the default `simple_spinner_dropdown_item`. The Huawei P9 Lite is known to be affected.
121 if (Build.BRAND.equals("HUAWEI") && (Build.VERSION.SDK_INT == 24)) { // The device is manufactured by Huawei and is running Android 7.0.
122 // Use a customized `simple_spinner_dropdown_item`. Huawei spinner code fix contributed 2017 Thomas Jensen <lianergoist@vongriffen.dk>. Copyright assigned to Soren Stoutner <soren@stoutner.com>.
123 userAgentArrayAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item_huawei_fix);
124 fontSizeArrayAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item_huawei_fix);
125 displayImagesArrayAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item_huawei_fix);
126 } else { // Use the standard `android.R.layout.simple_spinner_dropdown_item` on all other devices.
127 userAgentArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
128 fontSizeArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
129 displayImagesArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
132 // Set the `ArrayAdapters` for the `Spinners`.
133 userAgentSpinner.setAdapter(userAgentArrayAdapter);
134 fontSizeSpinner.setAdapter(fontSizeArrayAdapter);
135 displayWebpageImagesSpinner.setAdapter(displayImagesArrayAdapter);
137 // Set the domain name from the the database cursor.
138 domainNameEditText.setText(domainNameString);
140 // Set the JavaScript status.
141 if (javaScriptEnabledInt == 1) { // JavaScript is enabled.
142 javaScriptEnabledSwitch.setChecked(true);
143 javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.javascript_enabled));
144 } else { // JavaScript is disabled.
145 javaScriptEnabledSwitch.setChecked(false);
146 javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.privacy_mode));
149 // Set the first-party cookies status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
150 if (firstPartyCookiesEnabledInt == 1) { // First-party cookies are enabled.
151 firstPartyCookiesEnabledSwitch.setChecked(true);
152 firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_enabled));
153 } else { // First-party cookies are disabled.
154 firstPartyCookiesEnabledSwitch.setChecked(false);
156 // Set the icon according to the theme.
157 if (MainWebViewActivity.darkTheme) {
158 firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_dark));
160 firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
164 // Only display third-party cookies if SDK_INT >= 21.
165 if (Build.VERSION.SDK_INT >= 21) { // Third-party cookies can be configured for API >= 21.
166 // Only enable third-party-cookies if first-party cookies are enabled.
167 if (firstPartyCookiesEnabledInt == 1) { // First-party cookies are enabled.
168 // Set the third-party cookies status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
169 if (thirdPartyCookiesEnabledInt == 1) { // Both first-party and third-party cookies are enabled.
170 thirdPartyCookiesEnabledSwitch.setChecked(true);
171 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
172 } else { // First party cookies are enabled but third-party cookies are disabled.
173 thirdPartyCookiesEnabledSwitch.setChecked(false);
175 // Set the icon according to the theme.
176 if (MainWebViewActivity.darkTheme) {
177 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_dark));
179 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
182 } else { // First-party cookies are disabled.
183 // Set the status of third-party cookies.
184 if (thirdPartyCookiesEnabledInt == 1) {
185 thirdPartyCookiesEnabledSwitch.setChecked(true);
187 thirdPartyCookiesEnabledSwitch.setChecked(false);
190 // Disable the third-party cookies switch.
191 thirdPartyCookiesEnabledSwitch.setEnabled(false);
193 // Set the icon according to the theme.
194 if (MainWebViewActivity.darkTheme) {
195 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted_dark));
197 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted_light));
200 } else { // Third-party cookies cannot be configured for API <= 21.
201 // Hide the `LinearLayout` for third-party cookies.
202 thirdPartyCookiesLinearLayout.setVisibility(View.GONE);
205 // Only enable DOM storage if JavaScript is enabled.
206 if (javaScriptEnabledInt == 1) { // JavaScript is enabled.
207 // Set the DOM storage status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
208 if (domStorageEnabledInt == 1) { // Both JavaScript and DOM storage are enabled.
209 domStorageEnabledSwitch.setChecked(true);
210 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_enabled));
211 } else { // JavaScript is enabled but DOM storage is disabled.
212 // Set the DOM storage switch to off.
213 domStorageEnabledSwitch.setChecked(false);
215 // Set the icon according to the theme.
216 if (MainWebViewActivity.darkTheme) {
217 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_dark));
219 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_light));
222 } else { // JavaScript is disabled.
223 // Set the checked status of DOM storage.
224 if (domStorageEnabledInt == 1) { // DOM storage is enabled but JavaScript is disabled.
225 domStorageEnabledSwitch.setChecked(true);
226 } else { // Both JavaScript and DOM storage are disabled.
227 domStorageEnabledSwitch.setChecked(false);
230 // Disable `domStorageEnabledSwitch`.
231 domStorageEnabledSwitch.setEnabled(false);
233 // Set the icon according to the theme.
234 if (MainWebViewActivity.darkTheme) {
235 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted_dark));
237 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted_light));
241 // Set the form data status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
242 if (formDataEnabledInt == 1) { // Form data is enabled.
243 formDataEnabledSwitch.setChecked(true);
244 formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_enabled));
245 } else { // Form data is disabled.
246 // Set the form data switch to off.
247 formDataEnabledSwitch.setChecked(false);
249 // Set the icon according to the theme.
250 if (MainWebViewActivity.darkTheme) {
251 formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled_dark));
253 formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled_light));
257 // We need to inflated a `WebView` to get the default user agent.
258 // `@SuppressLint("InflateParams")` removes the warning about using `null` as the `ViewGroup`, which in this case makes sense because we don't want to display `bare_webview` on the screen. `false` does not attach the view to the root.
259 @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
260 WebView bareWebView = (WebView) bareWebViewLayout.findViewById(R.id.bare_webview);
261 final String webViewDefaultUserAgentString = bareWebView.getSettings().getUserAgentString();
263 // Get the position of the user agent in `userAgentEntryValuesArrayAdapter`.
264 int userAgentArrayPosition = userAgentEntryValuesArrayAdapter.getPosition(currentUserAgentString);
266 // Set the user agent.
267 if (userAgentArrayPosition == -1) { // We are using a custom `userAgentString`.
268 // Set `userAgentSpinner` to `Custom`.
269 userAgentSpinner.setSelection(userAgentEntryValuesArrayAdapter.getPosition("Custom user agent"));
271 // Hide `userAgentTextView`.
272 userAgentTextView.setVisibility(View.GONE);
274 // Show `customUserAgentEditText` and set `userAgentString` as the text.
275 customUserAgentEditText.setVisibility(View.VISIBLE);
276 customUserAgentEditText.setText(currentUserAgentString);
277 } else if (currentUserAgentString.equals("WebView default user agent")) { // We are using the `WebView` default user agent.
278 // Set the `userAgentSpinner` selection.
279 userAgentSpinner.setSelection(userAgentArrayPosition);
281 // Show `userAgentTextView` and set the text.
282 userAgentTextView.setVisibility(View.VISIBLE);
283 userAgentTextView.setText(webViewDefaultUserAgentString);
285 // Hide `customUserAgentEditText`.
286 customUserAgentEditText.setVisibility(View.GONE);
287 } else { // We are using a standard user agent.
288 // Set the `userAgentSpinner` selection.
289 userAgentSpinner.setSelection(userAgentArrayPosition);
291 // Show `userAgentTextView` and set the text.
292 userAgentTextView.setVisibility(View.VISIBLE);
293 userAgentTextView.setText(currentUserAgentString);
295 // Hide `customUserAgentEditText`.
296 customUserAgentEditText.setVisibility(View.GONE);
299 // Set the selected font size.
300 int fontSizeArrayPosition = fontSizeEntryValuesArrayAdapter.getPosition(String.valueOf(fontSizeInt));
301 fontSizeSpinner.setSelection(fontSizeArrayPosition);
303 // Set the selected display website images mode.
304 displayWebpageImagesSpinner.setSelection(displayImagesInt);
306 // Set the display website images icon.
307 switch (displayImagesInt) {
308 case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
309 if (MainWebViewActivity.displayWebpageImagesBoolean) {
310 // Set the icon according to the theme.
311 if (MainWebViewActivity.darkTheme) {
312 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_dark));
314 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
317 // Set the icon according to the theme.
318 if (MainWebViewActivity.darkTheme) {
319 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_dark));
321 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
326 case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_ENABLED:
327 // Set the icon according to the theme.
328 if (MainWebViewActivity.darkTheme) {
329 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_dark));
331 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
335 case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_DISABLED:
336 // Set the icon according to the theme.
337 if (MainWebViewActivity.darkTheme) {
338 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_dark));
340 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
346 // Set the `javaScriptEnabledSwitch` `OnCheckedChangeListener()`.
347 javaScriptEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
349 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
350 if (isChecked) { // JavaScript is enabled.
351 // Update the JavaScript icon.
352 javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.javascript_enabled));
354 // Enable the DOM storage `Switch`.
355 domStorageEnabledSwitch.setEnabled(true);
357 // Update the DOM storage icon.
358 if (domStorageEnabledSwitch.isChecked()) { // DOM storage is enabled.
359 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_enabled));
360 } else { // DOM storage is disabled.
361 // Set the icon according to the theme.
362 if (MainWebViewActivity.darkTheme) {
363 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_dark));
365 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_light));
368 } else { // JavaScript is disabled.
369 // Update the JavaScript icon.
370 javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.privacy_mode));
372 // Disable the DOM storage `Switch`.
373 domStorageEnabledSwitch.setEnabled(false);
375 // Set the DOM storage icon according to the theme.
376 if (MainWebViewActivity.darkTheme) {
377 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted_dark));
379 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted_light));
385 // Set the `firstPartyCookiesEnabledSwitch` `OnCheckedChangeListener()`.
386 firstPartyCookiesEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
388 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
389 if (isChecked) { // First-party cookies are enabled.
390 // Update the first-party cookies icon.
391 firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_enabled));
393 // Enable the third-party cookies `Switch`.
394 thirdPartyCookiesEnabledSwitch.setEnabled(true);
396 // Update the third-party cookies icon.
397 if (thirdPartyCookiesEnabledSwitch.isChecked()) { // Third-party cookies are enabled.
398 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
399 } else { // Third-party cookies are disabled.
400 // Set the third-party cookies icon according to the theme.
401 if (MainWebViewActivity.darkTheme) {
402 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_dark));
404 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
407 } else { // First-party cookies are disabled.
408 // Update the first-party cookies icon according to the theme.
409 if (MainWebViewActivity.darkTheme) {
410 firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_dark));
412 firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
415 // Disable the third-party cookies `Switch`.
416 thirdPartyCookiesEnabledSwitch.setEnabled(false);
418 // Set the third-party cookies icon according to the theme.
419 if (MainWebViewActivity.darkTheme) {
420 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted_dark));
422 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted_light));
428 // Set the `thirdPartyCookiesEnabledSwitch` `OnCheckedChangeListener()`.
429 thirdPartyCookiesEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
431 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
434 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
436 // Update the third-party cookies icon according to the theme.
437 if (MainWebViewActivity.darkTheme) {
438 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_dark));
440 thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled_light));
446 // Set the `domStorageEnabledSwitch` `OnCheckedChangeListener()`.
447 domStorageEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
449 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
452 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_enabled));
454 // Set the icon according to the theme.
455 if (MainWebViewActivity.darkTheme) {
456 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_dark));
458 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled_light));
464 // Set the `formDataEnabledSwitch` `OnCheckedChangeListener()`.
465 formDataEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
467 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
470 formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_enabled));
472 // Set the icon according to the theme.
473 if (MainWebViewActivity.darkTheme) {
474 formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled_dark));
476 formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled_light));
482 // Set the `userAgentSpinner` `onItemClickListener()`.
483 userAgentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
485 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
486 // Store the new user agent string.
487 String newUserAgentString = getResources().getStringArray(R.array.user_agent_entry_values)[position];
489 // Set the new user agent.
490 switch (newUserAgentString) {
491 case "Custom user agent":
492 // Hide `userAgentTextView`.
493 userAgentTextView.setVisibility(View.GONE);
495 // Show `customUserAgentEditText` and set `userAgentString` as the text.
496 customUserAgentEditText.setVisibility(View.VISIBLE);
497 customUserAgentEditText.setText(currentUserAgentString);
500 case "WebView default user agent":
501 // Show `userAgentTextView` and set the text.
502 userAgentTextView.setVisibility(View.VISIBLE);
503 userAgentTextView.setText(webViewDefaultUserAgentString);
505 // Hide `customUserAgentEditText`.
506 customUserAgentEditText.setVisibility(View.GONE);
510 // Show `userAgentTextView` and set the text.
511 userAgentTextView.setVisibility(View.VISIBLE);
512 userAgentTextView.setText(getResources().getStringArray(R.array.user_agent_entry_values)[position]);
514 // Hide `customUserAgentEditText`.
515 customUserAgentEditText.setVisibility(View.GONE);
521 public void onNothingSelected(AdapterView<?> parent) {
526 // Set the `displayImagesSwitch` `onItemClickListener()`.
527 displayWebpageImagesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
529 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
532 case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
533 if (MainWebViewActivity.displayWebpageImagesBoolean) {
534 // Set the icon according to the theme.
535 if (MainWebViewActivity.darkTheme) {
536 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_dark));
538 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
541 // Set the icon according to the theme.
542 if (MainWebViewActivity.darkTheme) {
543 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_dark));
545 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
550 case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_ENABLED:
551 // Set the icon according to the theme.
552 if (MainWebViewActivity.darkTheme) {
553 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_dark));
555 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled_light));
559 case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_DISABLED:
560 // Set the icon according to the theme.
561 if (MainWebViewActivity.darkTheme) {
562 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_dark));
564 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled_light));
571 public void onNothingSelected(AdapterView<?> parent) {
576 return domainSettingsView;