+ // Initialize `primaryErrorString`.
+ String primaryErrorString = "";
+
+ // Highlight the primary error in red and store the primary error string in `primaryErrorString`.
+ switch (primaryErrorInt) {
+ case SslError.SSL_IDMISMATCH:
+ // Change the URL span colors to red.
+ urlStringBuilder.setSpan(redColorSpan, urlLabel.length(), urlStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ issuedToCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length(), issuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ // Store the primary error string.
+ primaryErrorString = getString(R.string.cn_mismatch);
+ break;
+
+ case SslError.SSL_UNTRUSTED:
+ // Change the `issuesByTextView` text to red. We have to use the deprecated `getColor()` until API >= 23.
+ issuedByTextView.setTextColor(getResources().getColor(R.color.red_a700));
+
+ // Change the issued by span color to red.
+ issuedByCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length(), issuedByCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ issuedByONameStringBuilder.setSpan(redColorSpan, oNameLabel.length(), issuedByONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ issuedByUNameStringBuilder.setSpan(redColorSpan, uNameLabel.length(), issuedByUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ // Store the primary error string.
+ primaryErrorString = getString(R.string.untrusted);
+ break;
+
+ case SslError.SSL_DATE_INVALID:
+ // Change the `validDatesTextView` text to red. We have to use the deprecated `getColor()` until API >= 23.
+ validDatesTextView.setTextColor(getResources().getColor(R.color.red_a700));
+
+ // Change the date span colors to red.
+ startDateStringBuilder.setSpan(redColorSpan, startDateLabel.length(), startDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ endDateStringBuilder.setSpan(redColorSpan, endDateLabel.length(), endDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ // Store the primary error string.
+ primaryErrorString = getString(R.string.invalid_date);
+ break;
+
+ case SslError.SSL_NOTYETVALID:
+ // Change the start date span color to red.
+ startDateStringBuilder.setSpan(redColorSpan, startDateLabel.length(), startDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ // Store the primary error string.
+ primaryErrorString = getString(R.string.future_certificate);
+ break;
+
+ case SslError.SSL_EXPIRED:
+ // Change the end date span color to red.
+ endDateStringBuilder.setSpan(redColorSpan, endDateLabel.length(), endDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ // Store the primary error string.
+ primaryErrorString = getString(R.string.expired_certificate);
+ break;
+
+ case SslError.SSL_INVALID:
+ // Store the primary error string.
+ primaryErrorString = getString(R.string.invalid_certificate);
+ break;
+ }
+