Skip to content

Commit da228c9

Browse files
committed
Make the result colored
1 parent 090a751 commit da228c9

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

app/src/main/java/ir/ammari/rasad/MainActivity.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package ir.ammari.rasad;
22

33
import android.app.Activity;
4+
import android.graphics.Color;
45
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;
510
import android.widget.TextView;
611

712
import java.io.ByteArrayOutputStream;
813
import java.io.IOException;
9-
import java.io.InputStream;
1014
import java.net.MalformedURLException;
1115
import java.net.URL;
1216
import java.util.HashMap;
@@ -52,14 +56,19 @@ private void testURL(TextView textView, String name, URL url) {
5256
}
5357

5458
void displayResult(TextView textView) {
55-
final var text = new StringBuilder();
59+
final var text = new SpannableStringBuilder();
5660
text.append("Begin\n\n\n");
5761
for (Map.Entry<String, String> entry : sites.entrySet()) {
5862
final var key = entry.getKey();
5963
text.append(key);
6064
if (result.containsKey(key)) {
6165
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);
6372
text.append("\n");
6473
} else text.append("…\n");
6574
}

0 commit comments

Comments
 (0)