+ // Set the domain name from the the database cursor.
+ domainNameEditText.setText(domainNameString);
+
+ // Set the JavaScript status.
+ if (javaScriptEnabledInt == 1) { // JavaScript is enabled.
+ javaScriptEnabledSwitch.setChecked(true);
+ javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.javascript_enabled));
+ } else { // JavaScript is disabled.
+ javaScriptEnabledSwitch.setChecked(false);
+ javaScriptImageView.setImageDrawable(getResources().getDrawable(R.drawable.privacy_mode));
+ }
+
+ // Set the first-party cookies status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
+ if (firstPartyCookiesEnabledInt == 1) { // First-party cookies are enabled.
+ firstPartyCookiesEnabledSwitch.setChecked(true);
+ firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_enabled));
+ } else { // First-party cookies are disabled.
+ firstPartyCookiesEnabledSwitch.setChecked(false);
+ firstPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled));
+ }
+
+ // Only display third-party cookies if SDK_INT >= 21.
+ if (Build.VERSION.SDK_INT >= 21) { // Third-party cookies can be configured for API >= 21.
+ // Only enable third-party-cookies if first-party cookies are enabled.
+ if (firstPartyCookiesEnabledInt == 1) { // First-party cookies are enabled.
+ // Set the third-party cookies status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
+ if (thirdPartyCookiesEnabledInt == 1) { // Both first-party and third-party cookies are enabled.
+ thirdPartyCookiesEnabledSwitch.setChecked(true);
+ thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_warning));
+ } else { // First party cookies are enabled but third-party cookies are disabled.
+ thirdPartyCookiesEnabledSwitch.setChecked(false);
+ thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_disabled));
+ }
+ } else { // First-party cookies are disabled.
+ // Set the status of third-party cookies, but disable it.
+ if (thirdPartyCookiesEnabledInt == 1) { // Third-party cookies are enabled but first-party cookies are disabled.
+ thirdPartyCookiesEnabledSwitch.setChecked(true);
+ thirdPartyCookiesEnabledSwitch.setEnabled(false);
+ thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted));
+ } else { // Both first party and third-party cookies are disabled.
+ thirdPartyCookiesEnabledSwitch.setChecked(false);
+ thirdPartyCookiesEnabledSwitch.setEnabled(false);
+ thirdPartyCookiesImageView.setImageDrawable(getResources().getDrawable(R.drawable.cookies_ghosted));
+ }
+ }
+ } else { // Third-party cookies cannot be configured for API <= 21.
+ // Hide the `LinearLayout` for third-party cookies.
+ thirdPartyCookiesLinearLayout.setVisibility(View.GONE);
+ }
+
+ // Only enable DOM storage if JavaScript is enabled.
+ if (javaScriptEnabledInt == 1) { // JavaScript is enabled.
+ // Set the DOM storage status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
+ if (domStorageEnabledInt == 1) { // Both JavaScript and DOM storage are enabled.
+ domStorageEnabledSwitch.setChecked(true);
+ domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_enabled));
+ } else { // JavaScript is enabled but DOM storage is disabled.
+ domStorageEnabledSwitch.setChecked(false);
+ domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_disabled));
+ }
+ } else { // JavaScript is disabled.
+ // Set the status of DOM storage, but disable it.
+ if (domStorageEnabledInt == 1) { // DOM storage is enabled but JavaScript is disabled.
+ domStorageEnabledSwitch.setChecked(true);
+ domStorageEnabledSwitch.setEnabled(false);
+ domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted));
+ } else { // Both JavaScript and DOM storage are disabled.
+ domStorageEnabledSwitch.setChecked(false);
+ domStorageEnabledSwitch.setEnabled(false);
+ domStorageImageView.setImageDrawable(getResources().getDrawable(R.drawable.dom_storage_ghosted));
+ }
+ }
+
+ // Set the form data status. Once minimum API >= 21 we can use a selector as the tint mode instead of specifying different icons.
+ if (formDataEnabledInt == 1) { // Form data is enabled.
+ formDataEnabledSwitch.setChecked(true);
+ formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_enabled));
+ } else { // Form data is disabled.
+ formDataEnabledSwitch.setChecked(false);
+ formDataImageView.setImageDrawable(getResources().getDrawable(R.drawable.form_data_disabled));
+ }
+
+ // We need to inflated a `WebView` to get the default user agent.
+ // `@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.
+ @SuppressLint("InflateParams") View bareWebViewLayout = inflater.inflate(R.layout.bare_webview, null, false);
+ WebView bareWebView = (WebView) bareWebViewLayout.findViewById(R.id.bare_webview);
+ final String webViewDefaultUserAgentString = bareWebView.getSettings().getUserAgentString();
+
+ // Get the position of the user agent in `userAgentEntryValuesArrayAdapter`.
+ int userAgentArrayPosition = userAgentEntryValuesArrayAdapter.getPosition(currentUserAgentString);
+
+ // Set the user agent.
+ if (userAgentArrayPosition == -1) { // We are using a custom `userAgentString`.
+ // Set `userAgentSpinner` to `Custom`.
+ userAgentSpinner.setSelection(userAgentEntryValuesArrayAdapter.getPosition("Custom user agent"));
+
+ // Hide `userAgentTextView`.
+ userAgentTextView.setVisibility(View.GONE);
+
+ // Show `customUserAgentEditText` and set `userAgentString` as the text.
+ customUserAgentEditText.setVisibility(View.VISIBLE);
+ customUserAgentEditText.setText(currentUserAgentString);
+ } else if (currentUserAgentString.equals("WebView default user agent")) { // We are using the `WebView` default user agent.
+ // Set the `userAgentSpinner` selection.
+ userAgentSpinner.setSelection(userAgentArrayPosition);
+
+ // Show `userAgentTextView` and set the text.
+ userAgentTextView.setVisibility(View.VISIBLE);
+ userAgentTextView.setText(webViewDefaultUserAgentString);
+
+ // Hide `customUserAgentEditText`.
+ customUserAgentEditText.setVisibility(View.GONE);
+ } else { // We are using a standard user agent.
+ // Set the `userAgentSpinner` selection.
+ userAgentSpinner.setSelection(userAgentArrayPosition);
+
+ // Show `userAgentTextView` and set the text.
+ userAgentTextView.setVisibility(View.VISIBLE);
+ userAgentTextView.setText(currentUserAgentString);
+
+ // Hide `customUserAgentEditText`.
+ customUserAgentEditText.setVisibility(View.GONE);
+ }