Search in sources :

Example 81 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project run-wallet-android by runplay.

the class NetworkNodeInfoFragment method generateCenterSpannableText.

private SpannableString generateCenterSpannableText() {
    SpannableString s = new SpannableString("");
    s.setSpan(new RelativeSizeSpan(0.75f), 0, 0, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    s.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getActivity(), AppTheme.getAccent())), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return s;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 82 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project materialistic by hidroh.

the class HelpListView method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    ((TextView) findViewById(R.id.item_new).findViewById(R.id.rank)).append(makeAsteriskSpan());
    SpannableString spannable = new SpannableString("+5");
    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(ContextCompat.getColor(getContext(), R.color.greenA700)), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    ((TextView) findViewById(R.id.item_promoted).findViewById(R.id.rank)).append(spannable);
    TextView comments = (TextView) findViewById(R.id.item_new_comments).findViewById(R.id.comment);
    SpannableStringBuilder sb = new SpannableStringBuilder("46");
    sb.append(makeAsteriskSpan());
    comments.setText(sb);
}
Also used : SpannableString(android.text.SpannableString) SuperscriptSpan(android.text.style.SuperscriptSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextView(android.widget.TextView) RelativeSizeSpan(android.text.style.RelativeSizeSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 83 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project android-betterpickers by code-troopers.

the class TimeZonePickerUtils method buildGmtDisplayName.

private CharSequence buildGmtDisplayName(TimeZone tz, long timeMillis, boolean grayGmt) {
    Time time = new Time(tz.getID());
    time.set(timeMillis);
    StringBuilder sb = new StringBuilder();
    String displayName = getDisplayName(tz, time.isDst != 0);
    sb.append(displayName);
    sb.append("  ");
    final int gmtOffset = tz.getOffset(timeMillis);
    int gmtStart = sb.length();
    appendGmtOffset(sb, gmtOffset);
    int gmtEnd = sb.length();
    int symbolStart = 0;
    int symbolEnd = 0;
    if (tz.useDaylightTime()) {
        sb.append(" ");
        symbolStart = sb.length();
        // Sun symbol
        sb.append(getDstSymbol());
        symbolEnd = sb.length();
    }
    // Set the gray colors.
    Spannable spannableText = mSpannableFactory.newSpannable(sb);
    if (grayGmt) {
        spannableText.setSpan(new ForegroundColorSpan(GMT_TEXT_COLOR), gmtStart, gmtEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    if (tz.useDaylightTime()) {
        spannableText.setSpan(new ForegroundColorSpan(DST_SYMBOL_COLOR), symbolStart, symbolEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    CharSequence gmtDisplayName = spannableText;
    return gmtDisplayName;
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Time(android.text.format.Time) Spannable(android.text.Spannable)

Example 84 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project android-betterpickers by code-troopers.

the class TimeZoneInfo method getGmtDisplayName.

/*
     * The method is synchronized because there's one mSB, which is used by
     * mFormatter, per instance. If there are multiple callers for
     * getGmtDisplayName, the output may be mangled.
     */
public synchronized CharSequence getGmtDisplayName(Context context) {
    // TODO Note: The local time is shown in current time (current GMT
    // offset) which may be different from the time specified by
    // mTimeMillis
    final long nowMinute = System.currentTimeMillis() / DateUtils.MINUTE_IN_MILLIS;
    final long now = nowMinute * DateUtils.MINUTE_IN_MILLIS;
    final int gmtOffset = mTz.getOffset(now);
    int cacheKey;
    boolean hasFutureDST = mTz.useDaylightTime();
    if (hasFutureDST) {
        cacheKey = (int) (gmtOffset + 36 * DateUtils.HOUR_IN_MILLIS);
    } else {
        cacheKey = (int) (gmtOffset - 36 * DateUtils.HOUR_IN_MILLIS);
    }
    CharSequence displayName = null;
    if (mGmtDisplayNameUpdateTime != nowMinute) {
        mGmtDisplayNameUpdateTime = nowMinute;
        mGmtDisplayNameCache.clear();
    } else {
        displayName = mGmtDisplayNameCache.get(cacheKey);
    }
    if (displayName == null) {
        mSB.setLength(0);
        int flags = DateUtils.FORMAT_ABBREV_ALL;
        flags |= DateUtils.FORMAT_SHOW_TIME;
        if (TimeZoneInfo.is24HourFormat) {
            flags |= DateUtils.FORMAT_24HOUR;
        }
        // mFormatter writes to mSB
        DateUtils.formatDateRange(context, mFormatter, now, now, flags, mTzId);
        mSB.append("  ");
        int gmtStart = mSB.length();
        TimeZonePickerUtils.appendGmtOffset(mSB, gmtOffset);
        int gmtEnd = mSB.length();
        int symbolStart = 0;
        int symbolEnd = 0;
        if (hasFutureDST) {
            mSB.append(' ');
            symbolStart = mSB.length();
            // Sun symbol
            mSB.append(TimeZonePickerUtils.getDstSymbol());
            symbolEnd = mSB.length();
        }
        // Set the gray colors.
        Spannable spannableText = mSpannableFactory.newSpannable(mSB);
        spannableText.setSpan(new ForegroundColorSpan(GMT_TEXT_COLOR), gmtStart, gmtEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (hasFutureDST) {
            spannableText.setSpan(new ForegroundColorSpan(DST_SYMBOL_COLOR), symbolStart, symbolEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        displayName = spannableText;
        mGmtDisplayNameCache.put(cacheKey, displayName);
    }
    return displayName;
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Spannable(android.text.Spannable)

Example 85 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project k-9 by k9mail.

the class RecipientAdapter method highlightText.

public Spannable highlightText(String text) {
    Spannable highlightedSpannable = Spannable.Factory.getInstance().newSpannable(text);
    if (highlight == null) {
        return highlightedSpannable;
    }
    Pattern pattern = Pattern.compile(highlight, Pattern.LITERAL | Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(text);
    while (matcher.find()) {
        highlightedSpannable.setSpan(new ForegroundColorSpan(context.getResources().getColor(android.R.color.holo_blue_light)), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return highlightedSpannable;
}
Also used : Pattern(java.util.regex.Pattern) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Matcher(java.util.regex.Matcher) 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