Search in sources :

Example 61 with ForegroundColorSpan

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;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan)

Example 62 with ForegroundColorSpan

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);
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) ImageSpan(android.text.style.ImageSpan)

Example 63 with ForegroundColorSpan

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;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ArrayList(java.util.ArrayList) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Pair(android.util.Pair)

Example 64 with ForegroundColorSpan

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;
}
Also used : SpannableString(android.text.SpannableString) SpannableStringBuilder(android.text.SpannableStringBuilder) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 65 with ForegroundColorSpan

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);
        }
    });
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) Spannable(android.text.Spannable)

Aggregations

ForegroundColorSpan (android.text.style.ForegroundColorSpan)157 SpannableStringBuilder (android.text.SpannableStringBuilder)57 SpannableString (android.text.SpannableString)50 StyleSpan (android.text.style.StyleSpan)25 TextView (android.widget.TextView)25 ImageSpan (android.text.style.ImageSpan)23 Spannable (android.text.Spannable)22 RelativeSizeSpan (android.text.style.RelativeSizeSpan)22 View (android.view.View)22 BackgroundColorSpan (android.text.style.BackgroundColorSpan)19 TypefaceSpan (android.text.style.TypefaceSpan)16 StrikethroughSpan (android.text.style.StrikethroughSpan)14 UnderlineSpan (android.text.style.UnderlineSpan)13 Drawable (android.graphics.drawable.Drawable)12 CharacterStyle (android.text.style.CharacterStyle)11 EditText (android.widget.EditText)11 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)8 LinearLayout (android.widget.LinearLayout)8 URLSpan (android.text.style.URLSpan)7