use of android.text.style.ForegroundColorSpan in project actor-platform by actorapp.
the class ActorBinder method bind.
public void bind(final TextView textView, final View titleContainer, final GroupVM value) {
bind(value.getPresence(), value.getMembersCount(), value.isMember(), (online, onlineModel, membersCount, membersModel, isMember, isMemberModel) -> {
if (isMember) {
titleContainer.setVisibility(View.VISIBLE);
if (online <= 0) {
SpannableStringBuilder builder = new SpannableStringBuilder(messenger().getFormatter().formatGroupMembers(membersCount));
builder.setSpan(new ForegroundColorSpan(0xB7ffffff), 0, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(builder);
} else {
SpannableStringBuilder builder = new SpannableStringBuilder(messenger().getFormatter().formatGroupMembers(membersCount) + ", ");
builder.setSpan(new ForegroundColorSpan(0xB7ffffff), 0, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
builder.append(messenger().getFormatter().formatGroupOnline(online));
textView.setText(builder);
}
} else {
titleContainer.setVisibility(View.GONE);
}
});
}
use of android.text.style.ForegroundColorSpan in project actor-platform by actorapp.
the class AndroidMarkdown method processText.
private static Spannable processText(String markdown, int mode) {
MDDocument doc = new MarkdownParser(mode).processDocument(markdown);
SpannableStringBuilder builder = new SpannableStringBuilder();
boolean isFirst = true;
for (MDSection s : doc.getSections()) {
if (isFirst) {
isFirst = false;
} else {
builder.append("\n");
}
if (s.getType() == MDSection.TYPE_CODE) {
int start = builder.length();
builder.append("View Source Code");
final String text = s.getCode().getCode();
builder.setSpan(new RelativeSizeSpan(1.1f), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new ForegroundColorSpan(Color.RED), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
AndroidContext.getContext().startActivity(new Intent(AndroidContext.getContext(), CodePreviewActivity.class).putExtra("source_code", text).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else if (s.getType() == MDSection.TYPE_TEXT) {
writeText(s.getText(), builder);
} else {
throw new RuntimeException("Unknown section type: " + s.getType());
}
}
return builder;
}
use of android.text.style.ForegroundColorSpan in project LuaViewSDK by alibaba.
the class UDSpannableString method initSpannableStringBuilder.
private void initSpannableStringBuilder(LuaValue text, LuaValue config) {
SpannableStringBuilder spannableStringBuilder = getSpannableStringBuilder();
if (text != null && text.isstring()) {
spannableStringBuilder = spannableStringBuilder.append(text.tojstring());
}
if (spannableStringBuilder.length() > 0) {
if (config != null && config.istable()) {
final int end = spannableStringBuilder.length();
final int fontSize = DimenUtil.spToPx(config.get("fontSize").optint(-1));
final Integer fontColor = ColorUtil.parse(LuaUtil.getValue(config, "fontColor"));
final String fontName = config.get("fontName").optjstring(null);
final LuaValue weightValue = config.get("fontWeight");
final int fontWeight = LuaUtil.isNumber(weightValue) ? weightValue.optint(UDFontWeight.WEIGHT_NORMAL_INT) : UDFontWeight.getValue(weightValue.optjstring(UDFontWeight.WEIGHT_NORMAL));
final LuaValue styleValue = config.get("fontStyle");
final int fontStyle = LuaUtil.isNumber(styleValue) ? styleValue.optint(Typeface.NORMAL) : UDFontStyle.getValue(styleValue.optjstring(UDFontStyle.STYLE_NORMAL));
final Integer backgroundColor = ColorUtil.parse(LuaUtil.getValue(config, "backgroundColor"));
final boolean strikethrough = config.get("strikethrough").optboolean(false);
final boolean underline = config.get("underline").optboolean(false);
if (fontSize != -1) {
//字体大小
spannableStringBuilder.setSpan(new AbsoluteSizeSpan(fontSize), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontColor != null) {
//字体颜色
spannableStringBuilder.setSpan(new ForegroundColorSpan(fontColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontName != null && getLuaResourceFinder() != null) {
//字体
spannableStringBuilder.setSpan(new CustomTypefaceSpan(fontName, getLuaResourceFinder().findTypeface(fontName)), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontWeight != -1 && fontWeight > UDFontWeight.WEIGHT_NORMAL_INT) {
//文字Weight
spannableStringBuilder.setSpan(new WeightStyleSpan(fontWeight), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (fontStyle != -1 && (fontStyle >= Typeface.NORMAL && fontStyle <= Typeface.BOLD_ITALIC)) {
//文字样式
spannableStringBuilder.setSpan(new StyleSpan(fontStyle), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (backgroundColor != null) {
//背景色
spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (strikethrough) {
//删除线
spannableStringBuilder.setSpan(new StrikethroughSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (underline) {
//下划线
spannableStringBuilder.setSpan(new UnderlineSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
}
use of android.text.style.ForegroundColorSpan in project materialistic by hidroh.
the class StoryView method setPromoted.
public void setPromoted(int change) {
SpannableString spannable = new SpannableString(String.format(Locale.US, PROMOTED, change));
spannable.setSpan(new SuperscriptSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
spannable.setSpan(new RelativeSizeSpan(0.6f), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
spannable.setSpan(new ForegroundColorSpan(mPromotedColorResId), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
mRankTextView.append(spannable);
}
use of android.text.style.ForegroundColorSpan in project materialistic by hidroh.
the class HackerNewsItem method getDisplayedAuthor.
@Override
public Spannable getDisplayedAuthor(Context context, boolean linkify, int color) {
if (displayedAuthor == null) {
if (TextUtils.isEmpty(by)) {
displayedAuthor = new SpannableString("");
} else {
defaultColor = ContextCompat.getColor(context, AppUtils.getThemedResId(context, linkify ? android.R.attr.textColorLink : android.R.attr.textColorSecondary));
displayedAuthor = createAuthorSpannable(linkify);
}
}
if (displayedAuthor.length() == 0) {
return displayedAuthor;
}
displayedAuthor.setSpan(new ForegroundColorSpan(color != 0 ? color : defaultColor), AUTHOR_SEPARATOR.length(), displayedAuthor.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
return displayedAuthor;
}
Aggregations