mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
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:
parent
27123f5317
commit
0cf2299e49
1 changed files with 24 additions and 1 deletions
|
|
@ -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{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue