use of android.text.style.CharacterStyle in project Jota-Text-Editor-old by jiro-aqua.
the class TextUtils method writeToParcel.
/**
* Flatten a CharSequence and whatever styles can be copied across processes
* into the parcel.
*/
public static void writeToParcel(CharSequence cs, Parcel p, int parcelableFlags) {
if (cs instanceof Spanned) {
p.writeInt(0);
p.writeString(cs.toString());
Spanned sp = (Spanned) cs;
Object[] os = sp.getSpans(0, cs.length(), Object.class);
for (int i = 0; i < os.length; i++) {
Object o = os[i];
Object prop = os[i];
if (prop instanceof CharacterStyle) {
prop = ((CharacterStyle) prop).getUnderlying();
}
if (prop instanceof ParcelableSpan) {
ParcelableSpan ps = (ParcelableSpan) prop;
p.writeInt(ps.getSpanTypeId());
ps.writeToParcel(p, parcelableFlags);
writeWhere(p, sp, o);
}
}
p.writeInt(0);
} else {
p.writeInt(1);
if (cs != null) {
p.writeString(cs.toString());
} else {
p.writeString(null);
}
}
}
use of android.text.style.CharacterStyle in project smartmodule by carozhu.
the class StringUtil method highlight.
/**
* 关键字高亮显示
*
* @param target 需要高亮的关键字
*/
public static String highlight(String strold, String target) {
String temp = strold.toString();
SpannableStringBuilder spannable = new SpannableStringBuilder(temp);
CharacterStyle span = null;
Pattern p = Pattern.compile(target);
Matcher m = p.matcher(temp);
while (m.find()) {
// 需要重复! //span = new
span = new ForegroundColorSpan(Color.RED);
// ImageSpan(drawable,ImageSpan.XX);//设置现在图片
spannable.setSpan(span, m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return spannable.toString();
}
use of android.text.style.CharacterStyle in project Signal-Android by WhisperSystems.
the class ConversationItem method getLongMessageSpan.
// / Event handlers
private Spannable getLongMessageSpan(@NonNull MessageRecord messageRecord) {
String message;
Runnable action;
if (messageRecord.isMms()) {
TextSlide slide = ((MmsMessageRecord) messageRecord).getSlideDeck().getTextSlide();
if (slide != null && slide.asAttachment().getTransferState() == AttachmentDatabase.TRANSFER_PROGRESS_DONE) {
message = getResources().getString(R.string.ConversationItem_read_more);
action = () -> eventListener.onMoreTextClicked(conversationRecipient.getId(), messageRecord.getId(), messageRecord.isMms());
} else if (slide != null && slide.asAttachment().getTransferState() == AttachmentDatabase.TRANSFER_PROGRESS_STARTED) {
message = getResources().getString(R.string.ConversationItem_pending);
action = () -> {
};
} else if (slide != null) {
message = getResources().getString(R.string.ConversationItem_download_more);
action = () -> singleDownloadClickListener.onClick(bodyText, slide);
} else {
message = getResources().getString(R.string.ConversationItem_read_more);
action = () -> eventListener.onMoreTextClicked(conversationRecipient.getId(), messageRecord.getId(), messageRecord.isMms());
}
} else {
message = getResources().getString(R.string.ConversationItem_read_more);
action = () -> eventListener.onMoreTextClicked(conversationRecipient.getId(), messageRecord.getId(), messageRecord.isMms());
}
SpannableStringBuilder span = new SpannableStringBuilder(message);
CharacterStyle style = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
if (eventListener != null && batchSelected.isEmpty()) {
action.run();
}
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.setTypeface(Typeface.DEFAULT_BOLD);
}
};
span.setSpan(style, 0, span.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return span;
}
Aggregations