Search in sources :

Example 1 with QuoteSpan

use of eu.siacs.conversations.ui.text.QuoteSpan in project Conversations by siacs.

the class MessageAdapter method transformText.

private String transformText(CharSequence text, int start, int end, boolean forCopy) {
    SpannableStringBuilder builder = new SpannableStringBuilder(text);
    Object copySpan = new Object();
    builder.setSpan(copySpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    DividerSpan[] dividerSpans = builder.getSpans(0, builder.length(), DividerSpan.class);
    for (DividerSpan dividerSpan : dividerSpans) {
        builder.replace(builder.getSpanStart(dividerSpan), builder.getSpanEnd(dividerSpan), dividerSpan.isLarge() ? "\n\n" : "\n");
    }
    start = builder.getSpanStart(copySpan);
    end = builder.getSpanEnd(copySpan);
    if (start == -1 || end == -1)
        return "";
    builder = new SpannableStringBuilder(builder, start, end);
    if (forCopy) {
        QuoteSpan[] quoteSpans = builder.getSpans(0, builder.length(), QuoteSpan.class);
        for (QuoteSpan quoteSpan : quoteSpans) {
            builder.insert(builder.getSpanStart(quoteSpan), "> ");
        }
    }
    return builder.toString();
}
Also used : DividerSpan(eu.siacs.conversations.ui.text.DividerSpan) QuoteSpan(eu.siacs.conversations.ui.text.QuoteSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 2 with QuoteSpan

use of eu.siacs.conversations.ui.text.QuoteSpan in project Conversations by siacs.

the class MessageAdapter method applyQuoteSpan.

private int applyQuoteSpan(SpannableStringBuilder body, int start, int end, boolean darkBackground) {
    if (start > 1 && !"\n\n".equals(body.subSequence(start - 2, start).toString())) {
        body.insert(start++, "\n");
        body.setSpan(new DividerSpan(false), start - 2, start, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        end++;
    }
    if (end < body.length() - 1 && !"\n\n".equals(body.subSequence(end, end + 2).toString())) {
        body.insert(end, "\n");
        body.setSpan(new DividerSpan(false), end, end + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    int color = darkBackground ? this.getMessageTextColor(darkBackground, false) : getContext().getResources().getColor(R.color.bubble);
    DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    body.setSpan(new QuoteSpan(color, metrics), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return 0;
}
Also used : DividerSpan(eu.siacs.conversations.ui.text.DividerSpan) QuoteSpan(eu.siacs.conversations.ui.text.QuoteSpan) DisplayMetrics(android.util.DisplayMetrics)

Aggregations

DividerSpan (eu.siacs.conversations.ui.text.DividerSpan)2 QuoteSpan (eu.siacs.conversations.ui.text.QuoteSpan)2 SpannableStringBuilder (android.text.SpannableStringBuilder)1 DisplayMetrics (android.util.DisplayMetrics)1