|
1 | 1 | package fr.free.nrw.commons.notification;
|
2 | 2 |
|
| 3 | +import android.graphics.Color; |
3 | 4 | import android.text.Html;
|
| 5 | +import android.text.SpannableString; |
| 6 | +import android.text.Spanned; |
| 7 | +import android.text.TextPaint; |
| 8 | +import android.text.style.ClickableSpan; |
4 | 9 | import android.view.LayoutInflater;
|
5 | 10 | import android.view.View;
|
6 | 11 | import android.view.ViewGroup;
|
@@ -60,7 +65,25 @@ private void setTitle(String notificationText) {
|
60 | 65 | notificationText = notificationText.trim().replaceAll("(^\\s*)|(\\s*$)", "");
|
61 | 66 | notificationText = Html.fromHtml(notificationText).toString();
|
62 | 67 | notificationText = notificationText.concat(" ");
|
63 |
| - title.setText(notificationText); |
| 68 | + |
| 69 | + SpannableString ss = new SpannableString(notificationText); |
| 70 | + ClickableSpan clickableSpan = new ClickableSpan() { |
| 71 | + @Override |
| 72 | + public void onClick(View view) { |
| 73 | + listener.notificationClicked(getContent()); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public void updateDrawState(TextPaint ds) { |
| 78 | + super.updateDrawState(ds); |
| 79 | + ds.setUnderlineText(false); |
| 80 | + ds.setColor(Color.BLACK); |
| 81 | + } |
| 82 | + }; |
| 83 | + |
| 84 | + // Attach a ClickableSpan to the range (start:0, end:notificationText.length()) of the String |
| 85 | + ss.setSpan(clickableSpan, 0, notificationText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); |
| 86 | + title.setText(ss, TextView.BufferType.SPANNABLE); |
64 | 87 | }
|
65 | 88 |
|
66 | 89 | public interface NotificationClicked{
|
|
0 commit comments