use of android.text.style.StyleSpan in project FlexibleAdapter by davideas.
the class Utils method highlightText.
/**
* Sets a spannable text with the accent color (if available) into the provided TextView.
* <p>Internally calls {@link #fetchAccentColor(Context, int)}.</p>
*
* @param context context
* @param textView the TextView to transform
* @param originalText the original text which the transformation is applied to
* @param constraint the text to highlight
* @param defColor the default color in case accentColor is not found
* @see #fetchAccentColor(Context, int)
* @deprecated Use
* {@link #highlightText(TextView, String, String, int)} OR
* {@link #highlightText(TextView, String, String)}
*/
@Deprecated
public static void highlightText(@NonNull Context context, @NonNull TextView textView, String originalText, String constraint, @ColorInt int defColor) {
if (originalText == null)
originalText = "";
if (constraint == null)
constraint = "";
int i = originalText.toLowerCase(Locale.getDefault()).indexOf(constraint.toLowerCase(Locale.getDefault()));
if (i != -1) {
Spannable spanText = Spannable.Factory.getInstance().newSpannable(originalText);
spanText.setSpan(new ForegroundColorSpan(fetchAccentColor(context, defColor)), i, i + constraint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spanText.setSpan(new StyleSpan(Typeface.BOLD), i, i + constraint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spanText, TextView.BufferType.SPANNABLE);
} else {
textView.setText(originalText, TextView.BufferType.NORMAL);
}
}
use of android.text.style.StyleSpan in project android_frameworks_base by ParanoidAndroid.
the class HtmlToSpannedConverter method handleEndTag.
private void handleEndTag(String tag) {
if (tag.equalsIgnoreCase("br")) {
handleBr(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("p")) {
handleP(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("div")) {
handleP(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("strong")) {
end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
} else if (tag.equalsIgnoreCase("b")) {
end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD));
} else if (tag.equalsIgnoreCase("em")) {
end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
} else if (tag.equalsIgnoreCase("cite")) {
end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
} else if (tag.equalsIgnoreCase("dfn")) {
end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
} else if (tag.equalsIgnoreCase("i")) {
end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC));
} else if (tag.equalsIgnoreCase("big")) {
end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f));
} else if (tag.equalsIgnoreCase("small")) {
end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(0.8f));
} else if (tag.equalsIgnoreCase("font")) {
endFont(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("blockquote")) {
handleP(mSpannableStringBuilder);
end(mSpannableStringBuilder, Blockquote.class, new QuoteSpan());
} else if (tag.equalsIgnoreCase("tt")) {
end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan("monospace"));
} else if (tag.equalsIgnoreCase("a")) {
endA(mSpannableStringBuilder);
} else if (tag.equalsIgnoreCase("u")) {
end(mSpannableStringBuilder, Underline.class, new UnderlineSpan());
} else if (tag.equalsIgnoreCase("sup")) {
end(mSpannableStringBuilder, Super.class, new SuperscriptSpan());
} else if (tag.equalsIgnoreCase("sub")) {
end(mSpannableStringBuilder, Sub.class, new SubscriptSpan());
} else if (tag.length() == 2 && Character.toLowerCase(tag.charAt(0)) == 'h' && tag.charAt(1) >= '1' && tag.charAt(1) <= '6') {
handleP(mSpannableStringBuilder);
endHeader(mSpannableStringBuilder);
} else if (mTagHandler != null) {
mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader);
}
}
use of android.text.style.StyleSpan in project android_frameworks_base by ParanoidAndroid.
the class HtmlToSpannedConverter method endHeader.
private static void endHeader(SpannableStringBuilder text) {
int len = text.length();
Object obj = getLast(text, Header.class);
int where = text.getSpanStart(obj);
text.removeSpan(obj);
// Back off not to change only the text, not the blank line.
while (len > where && text.charAt(len - 1) == '\n') {
len--;
}
if (where != len) {
Header h = (Header) obj;
text.setSpan(new RelativeSizeSpan(HEADER_SIZES[h.mLevel]), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new StyleSpan(Typeface.BOLD), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
use of android.text.style.StyleSpan in project MPAndroidChart by PhilJay.
the class PiePolylineChartActivity method generateCenterSpannableText.
private SpannableString generateCenterSpannableText() {
SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
s.setSpan(new RelativeSizeSpan(1.5f), 0, 14, 0);
s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
s.setSpan(new RelativeSizeSpan(.65f), 14, s.length() - 15, 0);
s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
return s;
}
use of android.text.style.StyleSpan in project MPAndroidChart by PhilJay.
the class RealmDatabaseActivityPie method generateCenterSpannableText.
private SpannableString generateCenterSpannableText() {
SpannableString s = new SpannableString("Realm.io\nmobile database");
s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
return s;
}
Aggregations