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;
}
use of android.text.style.ForegroundColorSpan in project android_frameworks_base by AOSPA.
the class RestrictedLockUtils method removeExistingRestrictedSpans.
private static void removeExistingRestrictedSpans(SpannableStringBuilder sb) {
final int length = sb.length();
RestrictedLockImageSpan[] imageSpans = sb.getSpans(length - 1, length, RestrictedLockImageSpan.class);
for (ImageSpan span : imageSpans) {
final int start = sb.getSpanStart(span);
final int end = sb.getSpanEnd(span);
sb.removeSpan(span);
sb.delete(start, end);
}
ForegroundColorSpan[] colorSpans = sb.getSpans(0, length, ForegroundColorSpan.class);
for (ForegroundColorSpan span : colorSpans) {
sb.removeSpan(span);
}
}
use of android.text.style.ForegroundColorSpan in project wire-android by wireapp.
the class TextViewUtils method getTypefaceHighlightText.
private static CharSequence getTypefaceHighlightText(Context context, String string, @StringRes int typefaceRes, Integer highlightColor, int colorHighlightStart, int colorHighlightEnd) {
List<Pair<Integer, Integer>> spanPositions = new ArrayList<>();
int highlightStart;
int highlightEnd = 0;
while (string.substring(highlightEnd, string.length()).contains("[[")) {
highlightStart = string.indexOf("[[");
highlightEnd = string.indexOf("]]") - 2;
spanPositions.add(new Pair<>(highlightStart, highlightEnd));
string = string.replaceFirst("\\[\\[", "").replaceFirst("]]", "");
if (highlightColor != null && colorHighlightStart <= highlightStart && colorHighlightEnd >= highlightEnd) {
// need to deduct the [[ and ]] from the color span
colorHighlightEnd -= 4;
}
}
SpannableString highlightSpannable = new SpannableString(string);
for (Pair<Integer, Integer> spanPosition : spanPositions) {
highlightSpannable.setSpan(new CustomTypefaceSpan("", context.getResources().getString(typefaceRes)), spanPosition.first, spanPosition.second, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
if (highlightColor != null) {
highlightSpannable.setSpan(new ForegroundColorSpan(highlightColor), colorHighlightStart, colorHighlightEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
return highlightSpannable;
}
use of android.text.style.ForegroundColorSpan in project wire-android by wireapp.
the class TextViewUtils method getHighlightText.
public static CharSequence getHighlightText(Context context, String string, int highlightColor, boolean bold) {
final int highlightStart = string.indexOf('_');
if (highlightStart < 0) {
Timber.e("Failed to highlight text - could not find _ marker in string.");
return string;
}
final int highlightEnd = string.lastIndexOf('_');
if (highlightStart >= highlightEnd) {
Timber.e("Failed to highlight text - make sure you have 2 _ markers to denote start and end of highlight region");
return string;
}
StringBuilder stringBuilder = new StringBuilder(string.substring(0, highlightStart));
stringBuilder.append(string.substring(highlightStart + 1, highlightEnd));
if (highlightEnd < string.length() - 1) {
stringBuilder.append(string.substring(highlightEnd + 1, string.length()));
}
SpannableString colorSpannable = new SpannableString(stringBuilder.toString());
colorSpannable.setSpan(new ForegroundColorSpan(highlightColor), highlightStart, highlightEnd - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
if (bold) {
colorSpannable.setSpan(new CustomTypefaceSpan("", context.getResources().getString(R.string.wire__typeface__bold)), highlightStart, highlightEnd - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return colorSpannable;
}
use of android.text.style.ForegroundColorSpan in project android-app by spark.
the class TinkerFragment method showInstructions.
private void showInstructions() {
View instructions = Ui.findView(this, R.id.tinker_instructions);
// set cyan on "D7" text
TextView instructions3 = Ui.findView(instructions, R.id.tinker_instructions_3);
String d7 = "D7";
String instructions3Text = getString(R.string.tinker_instructions_3);
int idx = instructions3Text.indexOf(d7);
int cyan = getResources().getColor(R.color.cyan);
Spannable str = (Spannable) instructions3.getText();
str.setSpan(new ForegroundColorSpan(cyan), idx, idx + d7.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
// set visible and then set it to disappear when we're done. and then
// never show up again.
instructions.setVisibility(View.VISIBLE);
instructions.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
v.setVisibility(View.GONE);
TinkerPrefs.getInstance().setVisited(true);
}
});
}
Aggregations