Search in sources :

Example 1 with QuoteSpan

use of de.pixart.messenger.ui.text.QuoteSpan in project Pix-Art-Messenger by kriztan.

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(de.pixart.messenger.ui.text.DividerSpan) QuoteSpan(de.pixart.messenger.ui.text.QuoteSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 2 with QuoteSpan

use of de.pixart.messenger.ui.text.QuoteSpan in project Pix-Art-Messenger by kriztan.

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) : ContextCompat.getColor(activity, 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(de.pixart.messenger.ui.text.DividerSpan) QuoteSpan(de.pixart.messenger.ui.text.QuoteSpan) DisplayMetrics(android.util.DisplayMetrics)

Example 3 with QuoteSpan

use of de.pixart.messenger.ui.text.QuoteSpan in project Pix-Art-Messenger by kriztan.

the class StylingHelper method makeKeywordOpaque.

private static void makeKeywordOpaque(final Editable editable, int start, int end, @ColorInt int fallbackTextColor) {
    QuoteSpan[] quoteSpans = editable.getSpans(start, end, QuoteSpan.class);
    @ColorInt int textColor = quoteSpans.length > 0 ? quoteSpans[0].getColor() : fallbackTextColor;
    @ColorInt int keywordColor = transformColor(textColor);
    editable.setSpan(new ForegroundColorSpan(keywordColor), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Also used : ColorInt(android.support.annotation.ColorInt) ForegroundColorSpan(android.text.style.ForegroundColorSpan) QuoteSpan(de.pixart.messenger.ui.text.QuoteSpan)

Aggregations

QuoteSpan (de.pixart.messenger.ui.text.QuoteSpan)3 DividerSpan (de.pixart.messenger.ui.text.DividerSpan)2 ColorInt (android.support.annotation.ColorInt)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 DisplayMetrics (android.util.DisplayMetrics)1