+ // Store the current date.
+ Date currentDate = Calendar.getInstance().getTime();
+
+ // Setup the `StringBuilders` to display the general certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ savedSslCertificateIssuedToONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), savedSslCertificateIssuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ savedSslCertificateIssuedToUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), savedSslCertificateIssuedToUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ savedSslCertificateIssuedByCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), savedSslCertificateIssuedByCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ savedSslCertificateIssuedByONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), savedSslCertificateIssuedByONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ savedSslCertificateIssuedByUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), savedSslCertificateIssuedByUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ // Check the certificate `Common Name` against the domain name.
+ boolean savedSSlCertificateCommonNameMatchesDomainName = checkDomainNameAgainstCertificate(domainNameString, savedSslCertificateIssuedToCNameString);
+
+ // Format the `issuedToCommonName` color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if (savedSSlCertificateCommonNameMatchesDomainName) {
+ savedSslCertificateIssuedToCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), savedSslCertificateIssuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else {
+ savedSslCertificateIssuedToCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length(), savedSslCertificateIssuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Format the start date color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if ((savedSslCertificateStartDate != null) && savedSslCertificateStartDate.after(currentDate)) { // The certificate start date is in the future.
+ savedSslCertificateStartDateStringBuilder.setSpan(redColorSpan, startDateLabel.length(), savedSslCertificateStartDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else { // The certificate start date is in the past.
+ savedSslCertificateStartDateStringBuilder.setSpan(blueColorSpan, startDateLabel.length(), savedSslCertificateStartDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Format the end date color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if ((savedSslCertificateEndDate != null) && savedSslCertificateEndDate.before(currentDate)) { // The certificate end date is in the past.
+ savedSslCertificateEndDateStringBuilder.setSpan(redColorSpan, endDateLabel.length(), savedSslCertificateEndDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else { // The certificate end date is in the future.
+ savedSslCertificateEndDateStringBuilder.setSpan(blueColorSpan, endDateLabel.length(), savedSslCertificateEndDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Display the current website SSL certificate strings.
+ savedSslCertificateIssuedToCNameTextView.setText(savedSslCertificateIssuedToCNameStringBuilder);
+ savedSslCertificateIssuedToONameTextView.setText(savedSslCertificateIssuedToONameStringBuilder);
+ savedSslCertificateIssuedToUNameTextView.setText(savedSslCertificateIssuedToUNameStringBuilder);
+ savedSslCertificateIssuedByCNameTextView.setText(savedSslCertificateIssuedByCNameStringBuilder);
+ savedSslCertificateIssuedByONameTextView.setText(savedSslCertificateIssuedByONameStringBuilder);
+ savedSslCertificateIssuedByUNameTextView.setText(savedSslCertificateIssuedByUNameStringBuilder);
+ savedSslCertificateStartDateTextView.setText(savedSslCertificateStartDateStringBuilder);
+ savedSslCertificateEndDateTextView.setText(savedSslCertificateEndDateStringBuilder);
+
+ // Populate the current website SSL certificate if there is one.
+ if (currentWebsiteSslCertificate != null) {
+ // Get the strings from the SSL certificate.
+ String currentWebsiteCertificateIssuedToCNameString = currentWebsiteSslCertificate.getIssuedTo().getCName();
+ String currentWebsiteCertificateIssuedToONameString = currentWebsiteSslCertificate.getIssuedTo().getOName();
+ String currentWebsiteCertificateIssuedToUNameString = currentWebsiteSslCertificate.getIssuedTo().getUName();
+ String currentWebsiteCertificateIssuedByCNameString = currentWebsiteSslCertificate.getIssuedBy().getCName();
+ String currentWebsiteCertificateIssuedByONameString = currentWebsiteSslCertificate.getIssuedBy().getOName();
+ String currentWebsiteCertificateIssuedByUNameString = currentWebsiteSslCertificate.getIssuedBy().getUName();
+ Date currentWebsiteCertificateStartDate = currentWebsiteSslCertificate.getValidNotBeforeDate();
+ Date currentWebsiteCertificateEndDate = currentWebsiteSslCertificate.getValidNotAfterDate();
+
+ // Create a `SpannableStringBuilder` for each `TextView` that needs multiple colors of text.
+ SpannableStringBuilder currentWebsiteCertificateIssuedToCNameStringBuilder = new SpannableStringBuilder(cNameLabel + currentWebsiteCertificateIssuedToCNameString);
+ SpannableStringBuilder currentWebsiteCertificateIssuedToONameStringBuilder = new SpannableStringBuilder(oNameLabel + currentWebsiteCertificateIssuedToONameString);
+ SpannableStringBuilder currentWebsiteCertificateIssuedToUNameStringBuilder = new SpannableStringBuilder(uNameLabel + currentWebsiteCertificateIssuedToUNameString);
+ SpannableStringBuilder currentWebsiteCertificateIssuedByCNameStringBuilder = new SpannableStringBuilder(cNameLabel + currentWebsiteCertificateIssuedByCNameString);
+ SpannableStringBuilder currentWebsiteCertificateIssuedByONameStringBuilder = new SpannableStringBuilder(oNameLabel + currentWebsiteCertificateIssuedByONameString);
+ SpannableStringBuilder currentWebsiteCertificateIssuedByUNameStringBuilder = new SpannableStringBuilder(uNameLabel + currentWebsiteCertificateIssuedByUNameString);
+ SpannableStringBuilder currentWebsiteCertificateStartDateStringBuilder = new SpannableStringBuilder(startDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG)
+ .format(currentWebsiteCertificateStartDate));
+ SpannableStringBuilder currentWebsiteCertificateEndDateStringBuilder = new SpannableStringBuilder(endDateLabel + DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.LONG)
+ .format(currentWebsiteCertificateEndDate));
+
+ // Setup the `StringBuilders` to display the general certificate information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ currentWebsiteCertificateIssuedToONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), currentWebsiteCertificateIssuedToONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ currentWebsiteCertificateIssuedToUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), currentWebsiteCertificateIssuedToUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ currentWebsiteCertificateIssuedByCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), currentWebsiteCertificateIssuedByCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ currentWebsiteCertificateIssuedByONameStringBuilder.setSpan(blueColorSpan, oNameLabel.length(), currentWebsiteCertificateIssuedByONameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ currentWebsiteCertificateIssuedByUNameStringBuilder.setSpan(blueColorSpan, uNameLabel.length(), currentWebsiteCertificateIssuedByUNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+ // Check the certificate `Common Name` against the domain name.
+ boolean currentWebsiteCertificateCommonNameMatchesDomainName = checkDomainNameAgainstCertificate(domainNameString, currentWebsiteCertificateIssuedToCNameString);
+
+ // Format the `issuedToCommonName` color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if (currentWebsiteCertificateCommonNameMatchesDomainName) {
+ currentWebsiteCertificateIssuedToCNameStringBuilder.setSpan(blueColorSpan, cNameLabel.length(), currentWebsiteCertificateIssuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else {
+ currentWebsiteCertificateIssuedToCNameStringBuilder.setSpan(redColorSpan, cNameLabel.length(), currentWebsiteCertificateIssuedToCNameStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Format the start date color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if (currentWebsiteCertificateStartDate.after(currentDate)) { // The certificate start date is in the future.
+ currentWebsiteCertificateStartDateStringBuilder.setSpan(redColorSpan, startDateLabel.length(), currentWebsiteCertificateStartDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else { // The certificate start date is in the past.
+ currentWebsiteCertificateStartDateStringBuilder.setSpan(blueColorSpan, startDateLabel.length(), currentWebsiteCertificateStartDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Format the end date color. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction.
+ if (currentWebsiteCertificateEndDate.before(currentDate)) { // The certificate end date is in the past.
+ currentWebsiteCertificateEndDateStringBuilder.setSpan(redColorSpan, endDateLabel.length(), currentWebsiteCertificateEndDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ } else { // The certificate end date is in the future.
+ currentWebsiteCertificateEndDateStringBuilder.setSpan(blueColorSpan, endDateLabel.length(), currentWebsiteCertificateEndDateStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ }
+
+ // Display the current website SSL certificate strings.
+ currentWebsiteCertificateIssuedToCNameTextView.setText(currentWebsiteCertificateIssuedToCNameStringBuilder);
+ currentWebsiteCertificateIssuedToONameTextView.setText(currentWebsiteCertificateIssuedToONameStringBuilder);
+ currentWebsiteCertificateIssuedToUNameTextView.setText(currentWebsiteCertificateIssuedToUNameStringBuilder);
+ currentWebsiteCertificateIssuedByCNameTextView.setText(currentWebsiteCertificateIssuedByCNameStringBuilder);
+ currentWebsiteCertificateIssuedByONameTextView.setText(currentWebsiteCertificateIssuedByONameStringBuilder);
+ currentWebsiteCertificateIssuedByUNameTextView.setText(currentWebsiteCertificateIssuedByUNameStringBuilder);
+ currentWebsiteCertificateStartDateTextView.setText(currentWebsiteCertificateStartDateStringBuilder);
+ currentWebsiteCertificateEndDateTextView.setText(currentWebsiteCertificateEndDateStringBuilder);
+ }
+
+ // Set the initial display status for the SSL certificates.
+ if (pinnedSslCertificateSwitch.isChecked()) {
+ // Set the visibility of the saved SSL certificate.
+ if (savedSslCertificateIssuedToCNameString == null) {
+ savedSslCertificateLinearLayout.setVisibility(View.GONE);
+ } else {
+ savedSslCertificateLinearLayout.setVisibility(View.VISIBLE);
+ }
+
+ // Set the visibility of the current website SSL certificate.
+ if (currentWebsiteSslCertificate == null) {
+ // Hide the SSL certificate.
+ currentWebsiteCertificateLinearLayout.setVisibility(View.GONE);
+
+ // Show the instruction.
+ noCurrentWebsiteCertificateTextView.setVisibility(View.VISIBLE);
+ } else {
+ // Show the SSL certificate.
+ currentWebsiteCertificateLinearLayout.setVisibility(View.VISIBLE);
+
+ // Hide the instruction.
+ noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
+ }
+
+ // Set the status of the radio buttons.
+ if (savedSslCertificateLinearLayout.getVisibility() == View.VISIBLE) { // The saved SSL certificate is displayed.
+ savedSslCertificateRadioButton.setChecked(true);
+ currentWebsiteCertificateRadioButton.setChecked(false);
+ } else if (currentWebsiteCertificateLinearLayout.getVisibility() == View.VISIBLE) { // The saved SSL certificate is hidden but the current website SSL certificate is visible.
+ currentWebsiteCertificateRadioButton.setChecked(true);
+ savedSslCertificateRadioButton.setChecked(false);
+ } else { // Neither SSL certificate is visible.
+ savedSslCertificateRadioButton.setChecked(false);
+ currentWebsiteCertificateRadioButton.setChecked(false);
+ }
+ } else { // `pinnedSslCertificateSwitch` is not checked.
+ // Hide the SSl certificates and instructions.
+ savedSslCertificateLinearLayout.setVisibility(View.GONE);
+ currentWebsiteCertificateLinearLayout.setVisibility(View.GONE);
+ noCurrentWebsiteCertificateTextView.setVisibility(View.GONE);
+
+ // Uncheck the radio buttons.
+ savedSslCertificateRadioButton.setChecked(false);
+ currentWebsiteCertificateRadioButton.setChecked(false);
+ }
+
+
+ // Set the JavaScript switch listener.
+ javaScriptEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ if (isChecked) { // JavaScript is enabled.
+ // Update the JavaScript icon.
+ javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled));
+
+ // Enable the DOM storage `Switch`.
+ domStorageEnabledSwitch.setEnabled(true);
+
+ // Update the DOM storage icon.
+ if (domStorageEnabledSwitch.isChecked()) { // DOM storage is enabled.
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled));
+ } else { // DOM storage is disabled.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark));
+ } else {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light));
+ }
+ }
+ } else { // JavaScript is disabled.
+ // Update the JavaScript icon.
+ javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.privacy_mode));
+
+ // Disable the DOM storage `Switch`.
+ domStorageEnabledSwitch.setEnabled(false);
+
+ // Set the DOM storage icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark));
+ } else {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light));
+ }
+ }
+ });
+
+ // Set the first-party cookies switch listener.
+ firstPartyCookiesEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ if (isChecked) { // First-party cookies are enabled.
+ // Update the first-party cookies icon.
+ firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_enabled));
+
+ // Enable the third-party cookies switch.
+ thirdPartyCookiesEnabledSwitch.setEnabled(true);
+
+ // Update the third-party cookies icon.
+ if (thirdPartyCookiesEnabledSwitch.isChecked()) { // Third-party cookies are enabled.
+ thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning));
+ } else { // Third-party cookies are disabled.
+ // Set the third-party cookies icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark));
+ } else {
+ thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light));
+ }
+ }
+ } else { // First-party cookies are disabled.
+ // Update the first-party cookies icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark));
+ } else {
+ firstPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light));
+ }
+
+ // Disable the third-party cookies switch.
+ thirdPartyCookiesEnabledSwitch.setEnabled(false);
+
+ // Set the third-party cookies icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_dark));
+ } else {
+ thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_ghosted_light));
+ }
+ }
+ });
+
+ // Set the third-party cookies switch listener.
+ thirdPartyCookiesEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) {
+ thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_warning));
+ } else {
+ // Update the third-party cookies icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_dark));
+ } else {
+ thirdPartyCookiesImageView.setImageDrawable(resources.getDrawable(R.drawable.cookies_disabled_light));
+ }
+ }
+ });
+
+ // Set the DOM Storage switch listener.
+ domStorageEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled));
+ } else {
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark));
+ } else {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light));
+ }
+ }
+ });
+
+ // Set the form data switch listener. It can be removed once the minimum API >= 26.
+ if (Build.VERSION.SDK_INT < 26) {
+ formDataEnabledSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) {
+ formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_enabled));
+ } else {
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_dark));
+ } else {
+ formDataImageView.setImageDrawable(resources.getDrawable(R.drawable.form_data_disabled_light));
+ }
+ }
+ });
+ }
+
+ // Set the EasyList switch listener.
+ easyListSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // EasyList is on.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_dark));
+ } else {
+ easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_enabled_light));
+ }
+ } else { // EasyList is off.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_dark));
+ } else {
+ easyListImageView.setImageDrawable(resources.getDrawable(R.drawable.block_ads_disabled_light));
+ }
+ }
+ });
+
+ // Set the EasyPrivacy switch listener.
+ easyPrivacySwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // EasyPrivacy is on.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_dark));
+ } else {
+ easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_enabled_light));
+ }
+ } else { // EasyPrivacy is off.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_dark));
+ } else {
+ easyPrivacyImageView.setImageDrawable(resources.getDrawable(R.drawable.block_tracking_disabled_light));
+ }
+ }
+ });
+
+ // Set the Fanboy's Annoyance List switch listener.
+ fanboysAnnoyanceListSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon and Fanboy's Social Blocking List.
+ if (isChecked) { // Fanboy's Annoyance List is on.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark));
+ } else {
+ fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light));
+ }
+
+ // Disable the Fanboy's Social Blocking List switch.
+ fanboysSocialBlockingListSwitch.setEnabled(false);
+
+ // Update the Fanboy's Social Blocking List icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_dark));
+ } else {
+ fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_ghosted_light));
+ }
+ } else { // Fanboy's Annoyance List is off.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark));
+ } else {
+ fanboysAnnoyanceListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light));
+ }
+
+ // Enable the Fanboy's Social Blocking List switch.
+ fanboysSocialBlockingListSwitch.setEnabled(true);
+
+ // Update the Fanboy's Social Blocking List icon.
+ if (fanboysSocialBlockingListSwitch.isChecked()) { // Fanboy's Social Blocking List is on.
+ // Update the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark));
+ } else {
+ fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light));
+ }
+ } else { // Fanboy's Social Blocking List is off.
+ // Update the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark));
+ } else {
+ fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light));
+ }
+ }
+ }
+
+ });
+
+ // Set the Fanboy's Social Blocking List switch listener.
+ fanboysSocialBlockingListSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {
+ // Update the icon.
+ if (isChecked) { // Fanboy's Social Blocking List is on.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_dark));
+ } else {
+ fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_enabled_light));
+ }
+ } else { // Fanboy's Social Blocking List is off.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_dark));
+ } else {
+ fanboysSocialBlockingListImageView.setImageDrawable(resources.getDrawable(R.drawable.social_media_disabled_light));
+ }
+ }
+ });
+
+ // Set the user agent spinner listener.
+ userAgentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Set the new user agent.
+ switch (position) {
+ case MainWebViewActivity.DOMAINS_SYSTEM_DEFAULT_USER_AGENT:
+ // Show the user agent TextView.
+ userAgentTextView.setVisibility(View.VISIBLE);
+
+ // Hide the custom user agent EditText.
+ customUserAgentEditText.setVisibility(View.GONE);
+
+ // Set the user text.
+ switch (defaultUserAgentArrayPosition) {
+ case MainWebViewActivity.UNRECOGNIZED_USER_AGENT: // The default user agent name is not on the canonical list.
+ // This is probably because it was set in an older version of Privacy Browser before the switch to persistent user agent names.
+ userAgentTextView.setText(defaultUserAgentName);
+ break;
+
+ case MainWebViewActivity.SETTINGS_WEBVIEW_DEFAULT_USER_AGENT:
+ // Display the `WebView` default user agent.
+ userAgentTextView.setText(webViewDefaultUserAgentString);
+ break;
+
+ case MainWebViewActivity.SETTINGS_CUSTOM_USER_AGENT:
+ // Display the custom user agent.
+ userAgentTextView.setText(defaultCustomUserAgentString);
+ break;
+
+ default:
+ // Get the user agent string from the user agent data array.
+ userAgentTextView.setText(userAgentDataArray[defaultUserAgentArrayPosition]);
+ }
+ break;
+
+ case MainWebViewActivity.DOMAINS_WEBVIEW_DEFAULT_USER_AGENT:
+ // Show the user agent TextView and set the text.
+ userAgentTextView.setVisibility(View.VISIBLE);
+ userAgentTextView.setText(webViewDefaultUserAgentString);
+
+ // Hide the custom user agent EditTex.
+ customUserAgentEditText.setVisibility(View.GONE);
+ break;
+
+ case MainWebViewActivity.DOMAINS_CUSTOM_USER_AGENT:
+ // Hide the user agent TextView.
+ userAgentTextView.setVisibility(View.GONE);
+
+ // Show the custom user agent EditText and set the current user agent name as the text.
+ customUserAgentEditText.setVisibility(View.VISIBLE);
+ customUserAgentEditText.setText(currentUserAgentName);
+ break;
+
+ default:
+ // Show the user agent TextView and set the text from the user agent data array, which has one less entry than the spinner, so the position must be decremented.
+ userAgentTextView.setVisibility(View.VISIBLE);
+ userAgentTextView.setText(userAgentDataArray[position - 1]);
+
+ // Hide `customUserAgentEditText`.
+ customUserAgentEditText.setVisibility(View.GONE);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the font size spinner listener.
+ fontSizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the display options for `fontSizeTextView`.
+ if (position == 0) { // System default font size has been selected. Display `fontSizeTextView`.
+ fontSizeTextView.setVisibility(View.VISIBLE);
+ } else { // A custom font size has been selected. Hide `fontSizeTextView`.
+ fontSizeTextView.setVisibility(View.GONE);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the swipe to refresh spinner listener.
+ swipeToRefreshSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the icon and the visibility of `nightModeTextView`. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
+ switch (position) {
+ case DomainsDatabaseHelper.SWIPE_TO_REFRESH_SYSTEM_DEFAULT:
+ if (defaultSwipeToRefreshBoolean) { // Swipe to refresh enabled by default.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_light));
+ }
+ } else { // Swipe to refresh disabled by default.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_dark));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_light));
+ }
+ }
+
+ // Show the swipe to refresh TextView.
+ swipeToRefreshTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.SWIPE_TO_REFRESH_ENABLED:
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_dark));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_enabled_light));
+ }
+
+ // Hide the swipe to refresh TextView.
+ swipeToRefreshTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.SWIPE_TO_REFRESH_DISABLED:
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_dark));
+ } else {
+ swipeToRefreshImageView.setImageDrawable(resources.getDrawable(R.drawable.refresh_disabled_light));
+ }
+
+ // Hide the swipe to refresh TextView.
+ swipeToRefreshTextView.setVisibility(View.GONE);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
+
+ // Set the night mode spinner listener.
+ nightModeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Update the icon and the visibility of `nightModeTextView`. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
+ switch (position) {
+ case DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT:
+ if (defaultNightModeBoolean) { // Night mode enabled by default.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark));
+ } else {
+ nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light));
+ }
+ } else { // Night mode disabled by default.
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark));
+ } else {
+ nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light));
+ }
+ }
+
+ // Show the night mode TextView.
+ nightModeTextView.setVisibility(View.VISIBLE);
+ break;
+
+ case DomainsDatabaseHelper.NIGHT_MODE_ENABLED:
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_dark));
+ } else {
+ nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_enabled_light));
+ }
+
+ // Hide `nightModeTextView`.
+ nightModeTextView.setVisibility(View.GONE);
+ break;
+
+ case DomainsDatabaseHelper.NIGHT_MODE_DISABLED:
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_dark));
+ } else {
+ nightModeImageView.setImageDrawable(resources.getDrawable(R.drawable.night_mode_disabled_light));
+ }
+
+ // Hide `nightModeTextView`.
+ nightModeTextView.setVisibility(View.GONE);
+ break;
+ }
+
+ // Create a `boolean` to store the current night mode setting.
+ boolean currentNightModeEnabled = (position == DomainsDatabaseHelper.NIGHT_MODE_ENABLED) || ((position == DomainsDatabaseHelper.NIGHT_MODE_SYSTEM_DEFAULT) && defaultNightModeBoolean);
+
+ // Disable the JavaScript `Switch` if night mode is enabled.
+ if (currentNightModeEnabled) {
+ javaScriptEnabledSwitch.setEnabled(false);
+ } else {
+ javaScriptEnabledSwitch.setEnabled(true);
+ }
+
+ // Update the JavaScript icon.
+ if ((javaScriptEnabledInt == 1) || currentNightModeEnabled) {
+ javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.javascript_enabled));
+ } else {
+ javaScriptImageView.setImageDrawable(resources.getDrawable(R.drawable.privacy_mode));
+ }
+
+ // Update the DOM storage status.
+ if ((javaScriptEnabledInt == 1) || currentNightModeEnabled) { // JavaScript is enabled.
+ // Enable the DOM storage `Switch`.
+ domStorageEnabledSwitch.setEnabled(true);
+
+ // Set the DOM storage status. Once the minimum API >= 21 a selector can be used as the tint mode instead of specifying different icons.
+ if (domStorageEnabledInt == 1) { // Both JavaScript and DOM storage are enabled.
+ domStorageEnabledSwitch.setChecked(true);
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_enabled));
+ } else { // JavaScript is enabled but DOM storage is disabled.
+ // Set the DOM storage switch to off.
+ domStorageEnabledSwitch.setChecked(false);
+
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_dark));
+ } else {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_disabled_light));
+ }
+ }
+ } else { // JavaScript is disabled.
+ // Disable the DOM storage `Switch`.
+ domStorageEnabledSwitch.setEnabled(false);
+
+ // Set the checked status of DOM storage.
+ if (domStorageEnabledInt == 1) { // DOM storage is enabled but JavaScript is disabled.
+ domStorageEnabledSwitch.setChecked(true);
+ } else { // Both JavaScript and DOM storage are disabled.
+ domStorageEnabledSwitch.setChecked(false);
+ }
+
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_dark));
+ } else {
+ domStorageImageView.setImageDrawable(resources.getDrawable(R.drawable.dom_storage_ghosted_light));
+ }
+ }
+ }
+
+ @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 `displayImagesTextView`.
+ switch (position) {
+ case DomainsDatabaseHelper.DISPLAY_WEBPAGE_IMAGES_SYSTEM_DEFAULT:
+ if (defaultDisplayWebpageImagesBoolean) {
+ // Set the icon according to the theme.
+ if (MainWebViewActivity.darkTheme) {
+ displayWebpageImagesImageView.setImageDrawable(resources.getDrawable(R.drawable.images_enabled_dark));