+ // Display the font size settings.
+ if (fontSizeInt == 0) { // `0` is the code for system default font size.
+ // Set the font size to the system default
+ fontSizeSpinner.setSelection(0);
+
+ // Show the default font size text view.
+ defaultFontSizeTextView.setVisibility(View.VISIBLE);
+
+ // Hide the custom font size edit text.
+ customFontSizeEditText.setVisibility(View.GONE);
+
+ // Set the default font size as the text of the custom font size edit text. This way, if the user switches to custom it will already be populated.
+ customFontSizeEditText.setText(defaultFontSizeString);
+ } else { // A custom font size is selected.
+ // Set the spinner to the custom font size.
+ fontSizeSpinner.setSelection(1);
+
+ // Hide the default font size text view.
+ defaultFontSizeTextView.setVisibility(View.GONE);
+
+ // Show the custom font size edit text.
+ customFontSizeEditText.setVisibility(View.GONE);
+
+ // Set the custom font size.
+ customFontSizeEditText.setText(String.valueOf(fontSizeInt));
+ }
+
+ // Initialize the default font size percentage string.
+ String defaultFontSizePercentageString = defaultFontSizeString + "%";
+
+ // Set the default font size text in the text view.
+ defaultFontSizeTextView.setText(defaultFontSizePercentageString);
+
+ // Open the font size spinner when the text view is clicked.
+ defaultFontSizeTextView.setOnClickListener((View v) -> {
+ // Open the user agent spinner.
+ fontSizeSpinner.performClick();
+ });
+
+ // Select the swipe to refresh selection in the spinner.
+ swipeToRefreshSpinner.setSelection(swipeToRefreshInt);
+
+ // Set the swipe to refresh text.
+ if (defaultSwipeToRefresh)
+ swipeToRefreshTextView.setText(swipeToRefreshArrayAdapter.getItem(DomainsDatabaseHelper.ENABLED));
+ else
+ swipeToRefreshTextView.setText(swipeToRefreshArrayAdapter.getItem(DomainsDatabaseHelper.DISABLED));
+
+ // Set the swipe to refresh icon and text view settings.
+ switch (swipeToRefreshInt) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT:
+ // Set the icon color.
+ swipeToRefreshImageView.setSelected(defaultSwipeToRefresh);
+
+ // Show the swipe to refresh text view.
+ swipeToRefreshTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.ENABLED:
+ // Set the icon color.
+ swipeToRefreshImageView.setSelected(true);
+
+ // Hide the swipe to refresh text view.
+ swipeToRefreshTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DISABLED:
+ // Set the icon color.
+ swipeToRefreshImageView.setSelected(false);
+
+ // Hide the swipe to refresh text view.
+ swipeToRefreshTextView.setVisibility(View.GONE);
+ break;
+ }
+
+ // Open the swipe to refresh spinner when the text view is clicked.
+ swipeToRefreshTextView.setOnClickListener((View v) -> {
+ // Open the swipe to refresh spinner.
+ swipeToRefreshSpinner.performClick();
+ });
+
+ // Get the WebView theme string arrays.
+ String[] webViewThemeStringArray = resources.getStringArray(R.array.webview_theme_array);
+ String[] webViewThemeEntryValuesStringArray = resources.getStringArray(R.array.webview_theme_entry_values);
+
+ // Define an app WebView theme entry number.
+ int appWebViewThemeEntryNumber;
+
+ // 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.
+ if (defaultWebViewTheme.equals(webViewThemeEntryValuesStringArray[1])) { // The light theme is selected.
+ // Store the default WebView theme entry number.
+ appWebViewThemeEntryNumber = 1;
+ } else if (defaultWebViewTheme.equals(webViewThemeEntryValuesStringArray[2])) { // The dark theme is selected.
+ // Store the default WebView theme entry number.
+ appWebViewThemeEntryNumber = 2;
+ } else { // The system default theme is selected.
+ // Store the default WebView theme entry number.
+ appWebViewThemeEntryNumber = 0;
+ }
+
+ // Select the WebView theme in the spinner.
+ webViewThemeSpinner.setSelection(webViewThemeInt);
+
+ // Set the WebView theme text.
+ if (appWebViewThemeEntryNumber == DomainsDatabaseHelper.SYSTEM_DEFAULT) { // The app WebView theme is system default.
+ // Set the text according to the current UI theme.
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ webViewThemeTextView.setText(webViewThemeStringArray[DomainsDatabaseHelper.LIGHT_THEME]);
+ } else {
+ webViewThemeTextView.setText(webViewThemeStringArray[DomainsDatabaseHelper.DARK_THEME]);
+ }
+ } else { // The app WebView theme is not system default.
+ // Set the text according to the app WebView theme.
+ webViewThemeTextView.setText(webViewThemeStringArray[appWebViewThemeEntryNumber]);
+ }
+
+ // Set the WebView theme icon and text visibility.
+ switch (webViewThemeInt) {
+ 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 color.
+ webViewThemeImageView.setSelected(currentThemeStatus == Configuration.UI_MODE_NIGHT_NO);
+ break;
+
+ case DomainsDatabaseHelper.LIGHT_THEME: // the default WebView theme is light.
+ // Set the icon color.
+ webViewThemeImageView.setSelected(true);
+ break;
+
+ case DomainsDatabaseHelper.DARK_THEME: // the default WebView theme is dark.
+ // Set the icon color.
+ webViewThemeImageView.setSelected(false);
+ 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 color.
+ webViewThemeImageView.setSelected(true);
+
+ // Hide the WebView theme text view.
+ webViewThemeTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DARK_THEME: // The domain WebView theme is dark.
+ // Set the icon color.
+ webViewThemeImageView.setSelected(false);
+
+ // Hide the WebView theme text view.
+ webViewThemeTextView.setVisibility(View.GONE);
+ break;
+ }
+
+ // Open the WebView theme spinner when the text view is clicked.
+ webViewThemeTextView.setOnClickListener((View v) -> {
+ // Open the WebView theme spinner.
+ webViewThemeSpinner.performClick();
+ });
+
+ // Select the wide viewport in the spinner.
+ wideViewportSpinner.setSelection(wideViewportInt);
+
+ // Set the default wide viewport text.
+ if (defaultWideViewport)
+ wideViewportTextView.setText(wideViewportArrayAdapter.getItem(DomainsDatabaseHelper.ENABLED));
+ else
+ wideViewportTextView.setText(wideViewportArrayAdapter.getItem(DomainsDatabaseHelper.DISABLED));
+
+ // Set the wide viewport icon and text view settings.
+ switch (wideViewportInt) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT:
+ // Set the icon color.
+ wideViewportImageView.setSelected(defaultWideViewport);
+
+ // Show the wide viewport text view.
+ wideViewportTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.ENABLED:
+ // Set the icon color.
+ wideViewportImageView.setSelected(true);
+
+ // Hide the wide viewport text view.
+ wideViewportTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DISABLED:
+ // Set the icon color.
+ wideViewportImageView.setSelected(false);
+
+ // Hide the wide viewport text view.
+ wideViewportTextView.setVisibility(View.GONE);
+ break;
+ }
+
+ // Open the wide viewport spinner when the text view is clicked.
+ wideViewportTextView.setOnClickListener((View view) -> {
+ // Open the wide viewport spinner.
+ wideViewportSpinner.performClick();
+ });
+
+ // Display the website images mode in the spinner.
+ displayWebpageImagesSpinner.setSelection(displayImagesInt);
+
+ // Set the default display images text.
+ if (defaultDisplayWebpageImages) {
+ displayImagesTextView.setText(displayImagesArrayAdapter.getItem(DomainsDatabaseHelper.ENABLED));
+ } else {
+ displayImagesTextView.setText(displayImagesArrayAdapter.getItem(DomainsDatabaseHelper.DISABLED));
+ }
+
+ // Set the display website images icon and text view settings.
+ switch (displayImagesInt) {
+ case DomainsDatabaseHelper.SYSTEM_DEFAULT:
+ // Set the icon color.
+ displayWebpageImagesImageView.setSelected(defaultDisplayWebpageImages);
+
+ // Show the display images text view.
+ displayImagesTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.ENABLED:
+ // Set the icon color.
+ displayWebpageImagesImageView.setSelected(true);
+
+ // Hide the display images text view.
+ displayImagesTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.DISABLED:
+ // Set the icon color.
+ displayWebpageImagesImageView.setSelected(false);
+
+ // Hide the display images text view.
+ displayImagesTextView.setVisibility(View.GONE);
+ break;
+ }
+
+ // Open the display images spinner when the text view is clicked.
+ displayImagesTextView.setOnClickListener((View view) -> {
+ // Open the user agent spinner.
+ displayWebpageImagesSpinner.performClick();
+ });
+
+ // Set the switch positions.
+ pinnedSslCertificateSwitch.setChecked(pinnedSslCertificateInt == 1);
+ pinnedIpAddressesSwitch.setChecked(pinnedIpAddressesInt == 1);
+
+ // Set the switch icon colors.
+ pinnedSslCertificateImageView.setSelected(pinnedSslCertificateInt == 1);
+ pinnedIpAddressesImageView.setSelected(pinnedIpAddressesInt == 1);
+
+ // Store the current date.
+ Date currentDate = Calendar.getInstance().getTime();
+
+ // Setup the string builders to display the general certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ savedSslIssuedToONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), savedSslIssuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ savedSslIssuedToUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), savedSslIssuedToUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ savedSslIssuedByCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), savedSslIssuedByCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ savedSslIssuedByONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), savedSslIssuedByONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ savedSslIssuedByUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), savedSslIssuedByUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ // Check the certificate Common Name against the domain name.
+ boolean savedSslCommonNameMatchesDomainName = checkDomainNameAgainstCertificate(domainNameString, savedSslIssuedToCNameString);
+
+ // Format the issued to Common Name color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if (savedSslCommonNameMatchesDomainName) {
+ savedSslIssuedToCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), savedSslIssuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else {
+ savedSslIssuedToCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length(), savedSslIssuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Format the start date color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if ((savedSslStartDate != null) && savedSslStartDate.after(currentDate)) { // The certificate start date is in the future.
+ savedSslStartDateStringBuilder.setSpan(redColorSpan, startDateLabel.length(), savedSslStartDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else { // The certificate start date is in the past.
+ savedSslStartDateStringBuilder.setSpan(blueColorSpan, startDateLabel.length(), savedSslStartDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Format the end date color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if ((savedSslEndDate != null) && savedSslEndDate.before(currentDate)) { // The certificate end date is in the past.
+ savedSslEndDateStringBuilder.setSpan(redColorSpan, endDateLabel.length(), savedSslEndDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else { // The certificate end date is in the future.
+ savedSslEndDateStringBuilder.setSpan(blueColorSpan, endDateLabel.length(), savedSslEndDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Display the saved website SSL certificate strings.
+ savedSslIssuedToCNameTextView.setText(savedSslIssuedToCNameStringBuilder);
+ savedSslIssuedToONameTextView.setText(savedSslIssuedToONameStringBuilder);
+ savedSslIssuedToUNameTextView.setText(savedSslIssuedToUNameStringBuilder);
+ savedSslIssuedByCNameTextView.setText(savedSslIssuedByCNameStringBuilder);
+ savedSslIssuedByONameTextView.setText(savedSslIssuedByONameStringBuilder);
+ savedSslIssuedByUNameTextView.setText(savedSslIssuedByUNameStringBuilder);
+ savedSslStartDateTextView.setText(savedSslStartDateStringBuilder);
+ savedSslEndDateTextView.setText(savedSslEndDateStringBuilder);
+
+ // Populate the current website SSL certificate if there is one.
+ if (DomainsActivity.sslIssuedToCName != null) {
+ // Get dates from the raw long values.
+ Date currentSslStartDate = new Date(DomainsActivity.sslStartDateLong);
+ Date currentSslEndDate = new Date(DomainsActivity.sslEndDateLong);
+
+ // Create a spannable string builder for each text view that needs multiple colors of text.
+ SpannableStringBuilder currentSslIssuedToCNameStringBuilder = new SpannableStringBuilder(cNameLabel + DomainsActivity.sslIssuedToCName);
+ SpannableStringBuilder currentSslIssuedToONameStringBuilder = new SpannableStringBuilder(oNameLabel + DomainsActivity.sslIssuedToOName);
+ SpannableStringBuilder currentSslIssuedToUNameStringBuilder = new SpannableStringBuilder(uNameLabel + DomainsActivity.sslIssuedToUName);
+ SpannableStringBuilder currentSslIssuedByCNameStringBuilder = new SpannableStringBuilder(cNameLabel + DomainsActivity.sslIssuedByCName);
+ SpannableStringBuilder currentSslIssuedByONameStringBuilder = new SpannableStringBuilder(oNameLabel + DomainsActivity.sslIssuedByOName);
+ SpannableStringBuilder currentSslIssuedByUNameStringBuilder = new SpannableStringBuilder(uNameLabel + DomainsActivity.sslIssuedByUName);
+ SpannableStringBuilder currentSslStartDateStringBuilder = new SpannableStringBuilder(startDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG)
+ .format(currentSslStartDate));
+ SpannableStringBuilder currentSslEndDateStringBuilder = new SpannableStringBuilder(endDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG)
+ .format(currentSslEndDate));
+
+ // Setup the string builders to display the general certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ currentSslIssuedToONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), currentSslIssuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ currentSslIssuedToUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), currentSslIssuedToUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ currentSslIssuedByCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), currentSslIssuedByCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ currentSslIssuedByONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), currentSslIssuedByONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ currentSslIssuedByUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), currentSslIssuedByUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ // Check the certificate Common Name against the domain name.
+ boolean currentSslCommonNameMatchesDomainName = checkDomainNameAgainstCertificate(domainNameString, DomainsActivity.sslIssuedToCName);
+
+ // Format the issued to Common Name color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if (currentSslCommonNameMatchesDomainName) {
+ currentSslIssuedToCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), currentSslIssuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else {
+ currentSslIssuedToCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length(), currentSslIssuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Format the start date color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if (currentSslStartDate.after(currentDate)) { // The certificate start date is in the future.
+ currentSslStartDateStringBuilder.setSpan(redColorSpan, startDateLabel.length(), currentSslStartDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else { // The certificate start date is in the past.
+ currentSslStartDateStringBuilder.setSpan(blueColorSpan, startDateLabel.length(), currentSslStartDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Format the end date color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if (currentSslEndDate.before(currentDate)) { // The certificate end date is in the past.
+ currentSslEndDateStringBuilder.setSpan(redColorSpan, endDateLabel.length(), currentSslEndDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else { // The certificate end date is in the future.
+ currentSslEndDateStringBuilder.setSpan(blueColorSpan, endDateLabel.length(), currentSslEndDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Display the current website SSL certificate strings.
+ currentSslIssuedToCNameTextView.setText(currentSslIssuedToCNameStringBuilder);
+ currentSslIssuedToONameTextView.setText(currentSslIssuedToONameStringBuilder);
+ currentSslIssuedToUNameTextView.setText(currentSslIssuedToUNameStringBuilder);
+ currentSslIssuedByCNameTextView.setText(currentSslIssuedByCNameStringBuilder);
+ currentSslIssuedByONameTextView.setText(currentSslIssuedByONameStringBuilder);
+ currentSslIssuedByUNameTextView.setText(currentSslIssuedByUNameStringBuilder);
+ currentSslStartDateTextView.setText(currentSslStartDateStringBuilder);
+ currentSslEndDateTextView.setText(currentSslEndDateStringBuilder);
+ }
+
+ // Set the initial display status of the SSL certificates card views.
+ if (pinnedSslCertificateSwitch.isChecked()) { // An SSL certificate is pinned.
+ // Set the visibility of the saved SSL certificate.
+ if (savedSslIssuedToCNameString == null) {
+ savedSslCardView.setVisibility(View.GONE);
+ } else {
+ savedSslCardView.setVisibility(View.VISIBLE);
+ }
+
+ // Set the visibility of the current website SSL certificate.
+ if (DomainsActivity.sslIssuedToCName == null) { // There is no current SSL certificate.
+ // Hide the SSL certificate.
+ currentSslCardView.setVisibility(View.GONE);
+
+ // Show the instruction.
+ noCurrentWebsiteCertificateTextView.setVisibility(View.VISIBLE);
+ } else { // There is a current SSL certificate.
+ // Show the SSL certificate.
+ currentSslCardView.setVisibility(View.VISIBLE);
+
+ // Hide the instruction.
+ noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
+ }
+
+ // Set the status of the radio buttons and the card view backgrounds.
+ 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);
+
+ // 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);