Added an onclick to the middle text of a Notification (#1872)

* Enhancement issue #1862

Added on click to the "middle text" of a Notification item.

* Added comment #1862

Added comment to better explain method usage.
This commit is contained in:
Bruno 2018-11-04 12:34:40 -02:00 committed by Adam Jones
parent 27123f5317
commit 0cf2299e49

View file

@ -1,6 +1,11 @@
package fr.free.nrw.commons.notification;
import android.graphics.Color;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -60,7 +65,25 @@ public class NotificationRenderer extends Renderer<Notification> {
notificationText = notificationText.trim().replaceAll("(^\\s*)|(\\s*$)", "");
notificationText = Html.fromHtml(notificationText).toString();
notificationText = notificationText.concat(" ");
title.setText(notificationText);
SpannableString ss = new SpannableString(notificationText);
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View view) {
listener.notificationClicked(getContent());
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setColor(Color.BLACK);
}
};
// Attach a ClickableSpan to the range (start:0, end:notificationText.length()) of the String
ss.setSpan(clickableSpan, 0, notificationText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
title.setText(ss, TextView.BufferType.SPANNABLE);
}
public interface NotificationClicked{