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();
}
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;
}
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);
}
Aggregations