|
1 | 1 | package ir.ammari.rasad; |
2 | 2 |
|
3 | 3 | import android.app.Activity; |
| 4 | +import android.graphics.Color; |
4 | 5 | import android.os.Bundle; |
| 6 | +import android.text.Spannable; |
| 7 | +import android.text.SpannableString; |
| 8 | +import android.text.SpannableStringBuilder; |
| 9 | +import android.text.style.ForegroundColorSpan; |
5 | 10 | import android.widget.TextView; |
6 | 11 |
|
7 | 12 | import java.io.ByteArrayOutputStream; |
8 | 13 | import java.io.IOException; |
9 | | -import java.io.InputStream; |
10 | 14 | import java.net.MalformedURLException; |
11 | 15 | import java.net.URL; |
12 | 16 | import java.util.HashMap; |
@@ -52,14 +56,19 @@ private void testURL(TextView textView, String name, URL url) { |
52 | 56 | } |
53 | 57 |
|
54 | 58 | void displayResult(TextView textView) { |
55 | | - final var text = new StringBuilder(); |
| 59 | + final var text = new SpannableStringBuilder(); |
56 | 60 | text.append("Begin\n\n\n"); |
57 | 61 | for (Map.Entry<String, String> entry : sites.entrySet()) { |
58 | 62 | final var key = entry.getKey(); |
59 | 63 | text.append(key); |
60 | 64 | if (result.containsKey(key)) { |
61 | 65 | text.append(" - "); |
62 | | - text.append(result.get(key)); |
| 66 | + final var success = Boolean.TRUE.equals(result.get(key)); |
| 67 | + final var color = new ForegroundColorSpan(success ? Color.GREEN : Color.RED); |
| 68 | + final var string = success ? "success" : "fail"; |
| 69 | + SpannableString spannable = new SpannableString(string); |
| 70 | + spannable.setSpan(color, 0, string.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 71 | + text.append(spannable); |
63 | 72 | text.append("\n"); |
64 | 73 | } else text.append("…\n"); |
65 | 74 | } |
|
0 commit comments