+ // Set the WebView theme spinner listener.
+ webViewThemeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the icon and the visibility of the WebView theme text view. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
+ // Doing this makes no sense until it can also be done with the preferences.
+ switch (position) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT: // the domain WebView theme is system default.
+ // Set the icon according to the app WebView theme.
+ switch (appWebViewThemeEntryNumber) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT: // The default WebView theme is system default.
+ // Set the icon according to the app theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ // Set the light theme icon.
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme, null));
+ } else {
+ // Set the dark theme icon.
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme, null));
+ }
+ break;
+
+ case DomainsDatabaseHelper.LIGHT_THEME: // The default WebView theme is light.
+ // Set the icon.
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme, null));
+ break;
+
+ case DomainsDatabaseHelper.DARK_THEME: // The default WebView theme is dark.
+ // Set the icon.
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme, null));
+ break;
+ }
+
+ // Show the WebView theme text view.
+ webViewThemeTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.LIGHT_THEME: // The domain WebView theme is light.
+ // Set the icon.
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_light_theme, null));
+
+ // Hide the WebView theme text view.
+ webViewThemeTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DARK_THEME: // The domain WebView theme is dark.
+ // Set the icon.
+ webViewThemeImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.webview_dark_theme, null));
+
+ // Hide the WebView theme text view.
+ webViewThemeTextView.setVisibility(View.GONE);
+ break;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the wide viewport spinner listener.
+ wideViewportSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the icon and the visibility of the wide viewport text view.
+ switch (position) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT:
+ // Set the icon.
+ if (defaultWideViewport) { // Wide viewport is enabled by default.
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled, null));
+ } else { // Wide viewport is disabled by default.
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled, null));
+ }
+
+ // Show the wide viewport text view.
+ wideViewportTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.ENABLED:
+ // Set the icon according to the theme.
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_enabled, null));
+
+ // Hide the wide viewport text view.
+ wideViewportTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DISABLED:
+ // Set the icon.
+ wideViewportImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.wide_viewport_disabled, null));
+
+ // Hid ethe wide viewport text view.
+ wideViewportTextView.setVisibility(View.GONE);
+ break;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the display webpage images spinner listener.
+ displayWebpageImagesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the icon and the visibility of the display images text view.
+ switch (position) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT:
+ if (defaultDisplayWebpageImages) { // Display webpage images is enabled by default.
+ // Set the icon.
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled, null));
+ } else { // Display webpage images is disabled by default.
+ // Set the icon.
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled, null));
+ }
+
+ // Show the display images text view.
+ displayImagesTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.ENABLED:
+ // Set the icon.
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_enabled, null));
+
+ // Hide the display images text view.
+ displayImagesTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DISABLED:
+ // Set the icon.
+ displayWebpageImagesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.images_disabled, null));
+
+ // Hide the display images text view.
+ displayImagesTextView.setVisibility(View.GONE);
+ break;
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the pinned SSL certificate switch listener.
+ pinnedSslCertificateSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // SSL certificate pinning is enabled.
+ // Set the icon.
+ pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled, null));
+
+ // Update the visibility of the saved SSL certificate.
+ if (savedSslIssuedToCNameString == null) {
+ savedSslCardView.setVisibility(View.GONE);
+ } else {
+ savedSslCardView.setVisibility(View.VISIBLE);
+ }
+
+ // Update the visibility of the current website SSL certificate.
+ if (DomainsActivity.sslIssuedToCName == null) {
+ // Hide the SSL certificate.
+ currentSslCardView.setVisibility(View.GONE);
+
+ // Show the instruction.
+ noCurrentWebsiteCertificateTextView.setVisibility(View.VISIBLE);
+ } else {
+ // Show the SSL certificate.
+ currentSslCardView.setVisibility(View.VISIBLE);
+
+ // Hide the instruction.
+ noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
+ }
+
+ // Set the status of the radio buttons.
+ if (savedSslCardView.getVisibility() == View.VISIBLE) { // The saved SSL certificate is displayed.
+ // Check the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(true);
+
+ // Uncheck the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(false);
+
+ // Set the background of the saved SSL certificate linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current website SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+
+ // Scroll to the current website SSL certificate card.
+ savedSslCardView.getParent().requestChildFocus(savedSslCardView, savedSslCardView);
+ } else if (currentSslCardView.getVisibility() == View.VISIBLE) { // The saved SSL certificate is hidden but the current website SSL certificate is visible.
+ // Check the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(true);
+
+ // Uncheck the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(false);
+
+ // Set the background of the current website SSL certificate linear layout to be transparent.
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+
+ // Scroll to the current website SSL certificate card.
+ currentSslCardView.getParent().requestChildFocus(currentSslCardView, currentSslCardView);
+ } else { // Neither SSL certificate is visible.
+ // Uncheck both radio buttons.
+ savedSslCertificateRadioButton.setChecked(false);
+ currentWebsiteCertificateRadioButton.setChecked(false);
+
+ // Scroll to the current website SSL certificate card.
+ noCurrentWebsiteCertificateTextView.getParent().requestChildFocus(noCurrentWebsiteCertificateTextView, noCurrentWebsiteCertificateTextView);
+ }
+ } else { // SSL certificate pinning is disabled.
+ // Set the icon.
+ pinnedSslCertificateImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled, null));
+
+ // Hide the SSl certificates and instructions.
+ savedSslCardView.setVisibility(View.GONE);
+ currentSslCardView.setVisibility(View.GONE);
+ noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
+
+ // Uncheck the radio buttons.
+ savedSslCertificateRadioButton.setChecked(false);
+ currentWebsiteCertificateRadioButton.setChecked(false);
+ }
+ });
+
+ savedSslCardView.setOnClickListener((View view) -> {
+ // Check the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(true);
+
+ // Uncheck the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(false);
+
+ // Set the background of the saved SSL certificate linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current website SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ savedSslCertificateRadioButton.setOnClickListener((View view) -> {
+ // Check the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(true);
+
+ // Uncheck the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(false);
+
+ // Set the background of the saved SSL certificate linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current website SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ currentSslCardView.setOnClickListener((View view) -> {
+ // Check the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(true);
+
+ // Uncheck the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(false);
+
+ // Set the background of the current website SSL certificate linear layout to be transparent.
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ currentWebsiteCertificateRadioButton.setOnClickListener((View view) -> {
+ // Check the current website SSL certificate radio button.
+ currentWebsiteCertificateRadioButton.setChecked(true);
+
+ // Uncheck the saved SSL certificate radio button.
+ savedSslCertificateRadioButton.setChecked(false);
+
+ // Set the background of the current website SSL certificate linear layout to be transparent.
+ currentWebsiteCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved SSL certificate linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ // Set the pinned IP addresses switch listener.
+ pinnedIpAddressesSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // IP addresses pinning is enabled.
+ // Set the icon.
+ pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_enabled, null));
+
+ // Update the visibility of the saved IP addresses card view.
+ if (savedIpAddresses == null) { // There are no saved IP addresses.
+ savedIpAddressesCardView.setVisibility(View.GONE);
+ } else { // There are saved IP addresses.
+ savedIpAddressesCardView.setVisibility(View.VISIBLE);
+ }
+
+ // Show the current IP addresses card view.
+ currentIpAddressesCardView.setVisibility(View.VISIBLE);
+
+ // Set the status of the radio buttons.
+ if (savedIpAddressesCardView.getVisibility() == View.VISIBLE) { // The saved IP addresses are visible.
+ // Check the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the current IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the saved IP addresses linear layout to be transparent.
+ savedSslCertificateLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ } else { // The saved IP addresses are not visible.
+ // Check the current IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the current IP addresses linear layout to be transparent.
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ }
+
+ // Scroll to the bottom of the card views.
+ currentIpAddressesCardView.getParent().requestChildFocus(currentIpAddressesCardView, currentIpAddressesCardView);
+ } else { // IP addresses pinning is disabled.
+ // Set the icon.
+ pinnedIpAddressesImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ssl_certificate_disabled, null));
+
+ // Hide the IP addresses card views.
+ savedIpAddressesCardView.setVisibility(View.GONE);
+ currentIpAddressesCardView.setVisibility(View.GONE);
+
+ // Uncheck the radio buttons.
+ savedIpAddressesRadioButton.setChecked(false);
+ currentIpAddressesRadioButton.setChecked(false);
+ }
+ });
+
+ savedIpAddressesCardView.setOnClickListener((View view) -> {
+ // Check the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the current website IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the saved IP addresses linear layout to be transparent.
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ savedIpAddressesRadioButton.setOnClickListener((View view) -> {
+ // Check the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the current website IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the saved IP addresses linear layout to be transparent.
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the current IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ currentIpAddressesCardView.setOnClickListener((View view) -> {
+ // Check the current IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the current IP addresses linear layout to be transparent.
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ currentIpAddressesRadioButton.setOnClickListener((View view) -> {
+ // Check the current IP addresses radio button.
+ currentIpAddressesRadioButton.setChecked(true);
+
+ // Uncheck the saved IP addresses radio button.
+ savedIpAddressesRadioButton.setChecked(false);
+
+ // Set the background of the current IP addresses linear layout to be transparent.
+ currentIpAddressesLinearLayout.setBackgroundResource(R.color.transparent);
+
+ // Darken the background of the saved IP addresses linear layout according to the theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_33);
+ } else {
+ savedIpAddressesLinearLayout.setBackgroundResource(R.color.black_translucent_11);
+ }
+ });
+
+ // Set the scroll Y.
+ domainSettingsScrollView.post(() -> domainSettingsScrollView.setScrollY(scrollY));
+
+ // Return the domain settings view.