4416d3019da0a3ccc3b6d863ab5fddfd5581e863
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / DomainSettingsFragment.java
1 /*
2  * Copyright © 2017 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 package com.stoutner.privacybrowser.fragments;
21
22 import android.annotation.SuppressLint;
23 import android.content.Context;
24 import android.database.Cursor;
25 import android.os.Build;
26 import android.os.Bundle;
27 // We have to use `android.support.v4.app.Fragment` until minimum API >= 23.  Otherwise we cannot call `getContext()`.
28 import android.support.v4.app.Fragment;
29 import android.view.LayoutInflater;
30 import android.view.View;
31 import android.view.ViewGroup;
32 import android.webkit.WebView;
33 import android.widget.AdapterView;
34 import android.widget.ArrayAdapter;
35 import android.widget.CompoundButton;
36 import android.widget.EditText;
37 import android.widget.ImageView;
38 import android.widget.LinearLayout;
39 import android.widget.Spinner;
40 import android.widget.Switch;
41 import android.widget.TextView;
42
43 import com.stoutner.privacybrowser.R;
44 import com.stoutner.privacybrowser.activities.MainWebViewActivity;
45 import com.stoutner.privacybrowser.helpers.DomainsDatabaseHelper;
46
47 public class DomainSettingsFragment extends Fragment {
48     // `DATABASE_ID` is used by activities calling this fragment.
49     public static final String DATABASE_ID = "database_id";
50
51     // `databaseId` is used in `onCreate()` and `onCreateView()`.
52     private int databaseId;
53
54     @Override
55     public void onCreate(Bundle savedInstanceState) {
56         super.onCreate(savedInstanceState);
57
58         // Store the database id in `databaseId`.
59         databaseId = getArguments().getInt(DATABASE_ID);
60     }
61
62     // We have to use the deprecated `getDrawable()` until the minimum API >= 21.
63     @SuppressWarnings("deprecation")
64     @Override
65     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
66         // Inflate `domain_settings`.  `false` does not attach it to the root `container`.
67         View domainSettingsView = inflater.inflate(R.layout.domain_settings, container, false);
68
69         // Get a handle for the `Context`.
70         Context context = getContext();
71
72         // Get handles for the views in the fragment.
73         EditText domainNameEditText = (EditText) domainSettingsView.findViewById(R.id.domain_settings_name_edittext);
74         Switch javaScriptEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_javascript_switch);
75         final ImageView javaScriptImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_javascript_imageview);
76         Switch firstPartyCookiesEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_first_party_cookies_switch);
77         final ImageView firstPartyCookiesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_first_party_cookies_imageview);
78         LinearLayout thirdPartyCookiesLinearLayout = (LinearLayout) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_linearlayout);
79         final Switch thirdPartyCookiesEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_switch);
80         final ImageView thirdPartyCookiesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_third_party_cookies_imageview);
81         final Switch domStorageEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_dom_storage_switch);
82         final ImageView domStorageImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_dom_storage_imageview);
83         Switch formDataEnabledSwitch = (Switch) domainSettingsView.findViewById(R.id.domain_settings_form_data_switch);
84         final ImageView formDataImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_form_data_imageview);
85         Spinner userAgentSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_user_agent_spinner);
86         final TextView userAgentTextView = (TextView) domainSettingsView.findViewById(R.id.domain_settings_user_agent_textview);
87         final EditText customUserAgentEditText = (EditText) domainSettingsView.findViewById(R.id.domain_settings_custom_user_agent_edittext);
88         Spinner fontSizeSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_font_size_spinner);
89         final ImageView displayWebpageImagesImageView = (ImageView) domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_imageview);
90         Spinner displayWebpageImagesSpinner = (Spinner) domainSettingsView.findViewById(R.id.domain_settings_display_webpage_images_spinner);
91
92         // Initialize the database handler.  `this` specifies the context.  The two `nulls` do not specify the database name or a `CursorFactory`.
93         // The `0` specifies the database version, but that is ignored and set instead using a constant in `DomainsDatabaseHelper`.
94         DomainsDatabaseHelper domainsDatabaseHelper = new DomainsDatabaseHelper(getContext(), null, null, 0);
95
96         // Get the database `Cursor` for this ID and move it to the first row.
97         Cursor domainCursor = domainsDatabaseHelper.getCursorForId(databaseId);
98         domainCursor.moveToFirst();
99
100         // Save the `Cursor` entries as variables.
101         String domainNameString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.DOMAIN_NAME));
102         int javaScriptEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_JAVASCRIPT));
103         int firstPartyCookiesEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FIRST_PARTY_COOKIES));
104         int thirdPartyCookiesEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_THIRD_PARTY_COOKIES));
105         int domStorageEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_DOM_STORAGE));
106         int formDataEnabledInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.ENABLE_FORM_DATA));
107         final String currentUserAgentString = domainCursor.getString(domainCursor.getColumnIndex(DomainsDatabaseHelper.USER_AGENT));
108         int fontSizeInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.FONT_SIZE));
109         int displayImagesInt = domainCursor.getInt(domainCursor.getColumnIndex(DomainsDatabaseHelper.DISPLAY_IMAGES));
110
111         // Create `ArrayAdapters` for the `Spinners`and their `entry values`.
112         ArrayAdapter<CharSequence> userAgentArrayAdapter = ArrayAdapter.createFromResource(context, R.array.user_agent_entries, android.R.layout.simple_spinner_item);
113         final ArrayAdapter<CharSequence> userAgentEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.user_agent_entry_values, android.R.layout.simple_spinner_item);
114         ArrayAdapter<CharSequence> fontSizeArrayAdapter = ArrayAdapter.createFromResource(context, R.array.default_font_size_entries, android.R.layout.simple_spinner_item);
115         ArrayAdapter<CharSequence> fontSizeEntryValuesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.default_font_size_entry_values, android.R.layout.simple_spinner_item);
116         final ArrayAdapter<CharSequence> displayImagesArrayAdapter = ArrayAdapter.createFromResource(context, R.array.display_website_images_array, android.R.layout.simple_spinner_item);
117
118         // Set the drop down style for the `ArrayAdapters`.
119         userAgentArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
120         fontSizeArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
121         displayImagesArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
122
123         // Set the `ArrayAdapters` for the `Spinners`.
124         userAgentSpinner.setAdapter(userAgentArrayAdapter);
125         fontSizeSpinner.setAdapter(fontSizeArrayAdapter);
126         displayWebpageImagesSpinner.setAdapter(displayImagesArrayAdapter);
127
128         // Set the domain name from the the database cursor.
129         domainNameEditText.setText(domainNameString);
130
131         // Set the JavaScript status.
132         if (javaScriptEnabledInt == 1) {  // JavaScript is enabled.
133             javaScriptEnabledSwitch.setChecked(true);
134             javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.javascript_enabled));
135         } else {  // JavaScript is disabled.
136             javaScriptEnabledSwitch.setChecked(false);
137             javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.privacy_mode));
138         }
139
140         // Set the first-party cookies status.  Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
141         if (firstPartyCookiesEnabledInt == 1) {  // First-party cookies are enabled.
142             firstPartyCookiesEnabledSwitch.setChecked(true);
143             firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_enabled));
144         } else {  // First-party cookies are disabled.
145             firstPartyCookiesEnabledSwitch.setChecked(false);
146             firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled));
147         }
148
149         // Only display third-party cookies if SDK_INT >= 21.
150         if (Build.VERSION.SDK_INT >= 21) {  // Third-party cookies can be configured for API >= 21.
151             // Only enable third-party-cookies if first-party cookies are enabled.
152             if (firstPartyCookiesEnabledInt == 1) {  // First-party cookies are enabled.
153                 // Set the third-party cookies status.  Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
154                 if (thirdPartyCookiesEnabledInt == 1) {  // Both first-party and third-party cookies are enabled.
155                     thirdPartyCookiesEnabledSwitch.setChecked(true);
156                     thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
157                 } else {  // First party cookies are enabled but third-party cookies are disabled.
158                     thirdPartyCookiesEnabledSwitch.setChecked(false);
159                     thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled));
160                 }
161             } else {  // First-party cookies are disabled.
162                 // Set the status of third-party cookies, but disable it.
163                 if (thirdPartyCookiesEnabledInt == 1) {  // Third-party cookies are enabled but first-party cookies are disabled.
164                     thirdPartyCookiesEnabledSwitch.setChecked(true);
165                     thirdPartyCookiesEnabledSwitch.setEnabled(false);
166                     thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted));
167                 } else {  // Both first party and third-party cookies are disabled.
168                     thirdPartyCookiesEnabledSwitch.setChecked(false);
169                     thirdPartyCookiesEnabledSwitch.setEnabled(false);
170                     thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted));
171                 }
172             }
173         } else {  // Third-party cookies cannot be configured for API <= 21.
174             // Hide the `LinearLayout` for third-party cookies.
175             thirdPartyCookiesLinearLayout.setVisibility(View.GONE);
176         }
177
178         // Only enable DOM storage if JavaScript is enabled.
179         if (javaScriptEnabledInt == 1) {  // JavaScript is enabled.
180             // Set the DOM storage status.  Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
181             if (domStorageEnabledInt == 1) {  // Both JavaScript and DOM storage are enabled.
182                 domStorageEnabledSwitch.setChecked(true);
183                 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_enabled));
184             } else {  // JavaScript is enabled but DOM storage is disabled.
185                 domStorageEnabledSwitch.setChecked(false);
186                 domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled));
187             }
188         } else {  // JavaScript is disabled.
189             // Set the checked status of DOM storage.
190             if (domStorageEnabledInt == 1) {  // DOM storage is enabled but JavaScript is disabled.
191                 domStorageEnabledSwitch.setChecked(true);
192             } else {  // Both JavaScript and DOM storage are disabled.
193                 domStorageEnabledSwitch.setChecked(false);
194             }
195
196             // Disable `domStorageEnabledSwitch` and set the icon to be ghosted.
197             domStorageEnabledSwitch.setEnabled(false);
198             domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted));
199         }
200
201         // Set the form data status.  Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
202         if (formDataEnabledInt == 1) {  // Form data is enabled.
203             formDataEnabledSwitch.setChecked(true);
204             formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_enabled));
205         } else {  // Form data is disabled.
206             formDataEnabledSwitch.setChecked(false);
207             formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled));
208         }
209
210         // We need to inflated a `WebView` to get the default user agent.
211         // `@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.
212         @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
213         WebView bareWebView = (WebView) bareWebViewLayout.findViewById(R.id.bare_webview);
214         final String webViewDefaultUserAgentString = bareWebView.getSettings().getUserAgentString();
215
216         // Get the position of the user agent in `userAgentEntryValuesArrayAdapter`.
217         int userAgentArrayPosition = userAgentEntryValuesArrayAdapter.getPosition(currentUserAgentString);
218
219         // Set the user agent.
220         if (userAgentArrayPosition == -1) {  // We are using a custom `userAgentString`.
221             // Set `userAgentSpinner` to `Custom`.
222             userAgentSpinner.setSelection(userAgentEntryValuesArrayAdapter.getPosition("Custom user agent"));
223
224             // Hide `userAgentTextView`.
225             userAgentTextView.setVisibility(View.GONE);
226
227             // Show `customUserAgentEditText` and set `userAgentString` as the text.
228             customUserAgentEditText.setVisibility(View.VISIBLE);
229             customUserAgentEditText.setText(currentUserAgentString);
230         } else if (currentUserAgentString.equals("WebView default user agent")) {  // We are using the `WebView` default user agent.
231             // Set the `userAgentSpinner` selection.
232             userAgentSpinner.setSelection(userAgentArrayPosition);
233
234             // Show `userAgentTextView` and set the text.
235             userAgentTextView.setVisibility(View.VISIBLE);
236             userAgentTextView.setText(webViewDefaultUserAgentString);
237
238             // Hide `customUserAgentEditText`.
239             customUserAgentEditText.setVisibility(View.GONE);
240         } else {  // We are using a standard user agent.
241             // Set the `userAgentSpinner` selection.
242             userAgentSpinner.setSelection(userAgentArrayPosition);
243
244             // Show `userAgentTextView` and set the text.
245             userAgentTextView.setVisibility(View.VISIBLE);
246             userAgentTextView.setText(currentUserAgentString);
247
248             // Hide `customUserAgentEditText`.
249             customUserAgentEditText.setVisibility(View.GONE);
250         }
251
252         // Set the selected font size.
253         int fontSizeArrayPosition = fontSizeEntryValuesArrayAdapter.getPosition(String.valueOf(fontSizeInt));
254         fontSizeSpinner.setSelection(fontSizeArrayPosition);
255
256         // Set the selected display website images mode.
257         displayWebpageImagesSpinner.setSelection(displayImagesInt);
258
259         // Set the display website images icon.
260         switch (displayImagesInt) {
261             case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
262                 if (MainWebViewActivity.displayWebpageImagesBoolean) {
263                     displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled));
264                 } else {
265                     displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled));
266                 }
267                 break;
268
269             case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_ENABLED:
270                 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled));
271                 break;
272
273             case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_DISABLED:
274                 displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled));
275                 break;
276         }
277
278
279         // Set the `javaScriptEnabledSwitch` `OnCheckedChangeListener()`.
280         javaScriptEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
281             @Override
282             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
283                 if (isChecked) {  // JavaScript is enabled.
284                     // Update the JavaScript icon.
285                     javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.javascript_enabled));
286
287                     // Enable the DOM storage `Switch`.
288                     domStorageEnabledSwitch.setEnabled(true);
289
290                     // Update the DOM storage icon.
291                     if (domStorageEnabledSwitch.isChecked()) {  // DOM storage is enabled.
292                         domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_enabled));
293                     } else {  // DOM storage is disabled.
294                         domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled));
295                     }
296                 } else {  // JavaScript is disabled.
297                     // Update the JavaScript icon.
298                     javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.privacy_mode));
299
300                     // Disable the DOM storage `Switch`.
301                     domStorageEnabledSwitch.setEnabled(false);
302
303                     // Set the DOM storage icon to be ghosted.
304                     domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted));
305                 }
306             }
307         });
308
309         // Set the `firstPartyCookiesEnabledSwitch` `OnCheckedChangeListener()`.
310         firstPartyCookiesEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
311             @Override
312             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
313                 if (isChecked) {  // First-party cookies are enabled.
314                     // Update the first-party cookies icon.
315                     firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_enabled));
316
317                     // Enable the third-party cookies `Switch`.
318                     thirdPartyCookiesEnabledSwitch.setEnabled(true);
319
320                     // Update the third-party cookies icon.
321                     if (thirdPartyCookiesEnabledSwitch.isChecked()) {  // Third-party cookies are enabled.
322                         thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
323                     } else {  // Third-party cookies are disabled.
324                         thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled));
325                     }
326                 } else {  // First-party cookies are disabled.
327                     // Update the first-party cookies icon.
328                     firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled));
329
330                     // Disable the third-party cookies `Switch`.
331                     thirdPartyCookiesEnabledSwitch.setEnabled(false);
332
333                     // Set the third-party cookies icon to be ghosted.
334                     thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted));
335                 }
336             }
337         });
338
339         // Set the `thirdPartyCookiesEnabledSwitch` `OnCheckedChangeListener()`.
340         thirdPartyCookiesEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
341             @Override
342             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
343                 // Update the icon.
344                 if (isChecked) {
345                     thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
346                 } else {
347                     thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled));
348                 }
349             }
350         });
351
352         // Set the `domStorageEnabledSwitch` `OnCheckedChangeListener()`.
353         domStorageEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
354             @Override
355             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
356                 // Update the icon.
357                 if (isChecked) {
358                     domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_enabled));
359                 } else {
360                     domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled));
361                 }
362             }
363         });
364
365         // Set the `formDataEnabledSwitch` `OnCheckedChangeListener()`.
366         formDataEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
367             @Override
368             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
369                 // Update the icon.
370                 if (isChecked) {
371                     formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_enabled));
372                 } else {
373                     formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled));
374                 }
375             }
376         });
377
378         // Set the `userAgentSpinner` `onItemClickListener()`.
379         userAgentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
380             @Override
381             public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
382                 // Store the new user agent string.
383                 String newUserAgentString = getResources().getStringArray(R.array.user_agent_entry_values)[position];
384
385                 // Set the new user agent.
386                 switch (newUserAgentString) {
387                     case "Custom user agent":
388                         // Hide `userAgentTextView`.
389                         userAgentTextView.setVisibility(View.GONE);
390
391                         // Show `customUserAgentEditText` and set `userAgentString` as the text.
392                         customUserAgentEditText.setVisibility(View.VISIBLE);
393                         customUserAgentEditText.setText(currentUserAgentString);
394                         break;
395
396                     case "WebView default user agent":
397                         // Show `userAgentTextView` and set the text.
398                         userAgentTextView.setVisibility(View.VISIBLE);
399                         userAgentTextView.setText(webViewDefaultUserAgentString);
400
401                         // Hide `customUserAgentEditText`.
402                         customUserAgentEditText.setVisibility(View.GONE);
403                         break;
404
405                     default:
406                         // Show `userAgentTextView` and set the text.
407                         userAgentTextView.setVisibility(View.VISIBLE);
408                         userAgentTextView.setText(getResources().getStringArray(R.array.user_agent_entry_values)[position]);
409
410                         // Hide `customUserAgentEditText`.
411                         customUserAgentEditText.setVisibility(View.GONE);
412                         break;
413                 }
414             }
415
416             @Override
417             public void onNothingSelected(AdapterView<?> parent) {
418                 // Do nothing.
419             }
420         });
421
422         // Set the `displayImagesSwitch` `onItemClickListener()`.
423         displayWebpageImagesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
424             @Override
425             public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
426                 // Update the icon.
427                 switch (position) {
428                     case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
429                         if (MainWebViewActivity.displayWebpageImagesBoolean) {
430                             displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled));
431                         } else {
432                             displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled));
433                         }
434                         break;
435
436                     case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_ENABLED:
437                         displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_enabled));
438                         break;
439
440                     case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_DISABLED:
441                         displayWebpageImagesImageView.setImageDrawable(getResources().getDrawable(R.drawable.images_disabled));
442                         break;
443                 }
444             }
445
446             @Override
447             public void onNothingSelected(AdapterView<?> parent) {
448                 // Do nothing.
449             }
450         });
451
452         return domainSettingsView;
453     }
454 }