Search in sources :

Example 1 with SpannableString

use of android.text.SpannableString in project cw-advandroid by commonsguy.

the class RichTextSearchActivity method searchFor.

private void searchFor(String text) {
    TextView prose = (TextView) findViewById(R.id.prose);
    Spannable raw = new SpannableString(prose.getText());
    BackgroundColorSpan[] spans = raw.getSpans(0, raw.length(), BackgroundColorSpan.class);
    for (BackgroundColorSpan span : spans) {
        raw.removeSpan(span);
    }
    int index = TextUtils.indexOf(raw, text);
    while (index >= 0) {
        raw.setSpan(new BackgroundColorSpan(0xFF8B008B), index, index + text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        index = TextUtils.indexOf(raw, text, index + text.length());
    }
    prose.setText(raw);
}
Also used : SpannableString(android.text.SpannableString) TextView(android.widget.TextView) Spannable(android.text.Spannable) BackgroundColorSpan(android.text.style.BackgroundColorSpan)

Example 2 with SpannableString

use of android.text.SpannableString in project Libraries-for-Android-Developers by eoecn.

the class SuggestionsAdapter method formatUrl.

private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }
    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}
Also used : SpannableString(android.text.SpannableString) TextAppearanceSpan(android.text.style.TextAppearanceSpan) TypedValue(android.util.TypedValue)

Example 3 with SpannableString

use of android.text.SpannableString in project android_frameworks_base by ParanoidAndroid.

the class TextView method onSaveInstanceState.

@Override
public Parcelable onSaveInstanceState() {
    Parcelable superState = super.onSaveInstanceState();
    // Save state if we are forced to
    boolean save = mFreezesText;
    int start = 0;
    int end = 0;
    if (mText != null) {
        start = getSelectionStart();
        end = getSelectionEnd();
        if (start >= 0 || end >= 0) {
            // Or save state if there is a selection
            save = true;
        }
    }
    if (save) {
        SavedState ss = new SavedState(superState);
        // XXX Should also save the current scroll position!
        ss.selStart = start;
        ss.selEnd = end;
        if (mText instanceof Spanned) {
            /*
                 * Calling setText() strips off any ChangeWatchers;
                 * strip them now to avoid leaking references.
                 * But do it to a copy so that if there are any
                 * further changes to the text of this view, it
                 * won't get into an inconsistent state.
                 */
            Spannable sp = new SpannableString(mText);
            for (ChangeWatcher cw : sp.getSpans(0, sp.length(), ChangeWatcher.class)) {
                sp.removeSpan(cw);
            }
            if (mEditor != null) {
                removeMisspelledSpans(sp);
                sp.removeSpan(mEditor.mSuggestionRangeSpan);
            }
            ss.text = sp;
        } else {
            ss.text = mText.toString();
        }
        if (isFocused() && start >= 0 && end >= 0) {
            ss.frozenWithFocus = true;
        }
        ss.error = getError();
        return ss;
    }
    return superState;
}
Also used : SpannableString(android.text.SpannableString) Parcelable(android.os.Parcelable) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Spannable(android.text.Spannable)

Example 4 with SpannableString

use of android.text.SpannableString in project android_frameworks_base by ParanoidAndroid.

the class TextView method removeSuggestionSpans.

/**
     * Removes the suggestion spans.
     */
CharSequence removeSuggestionSpans(CharSequence text) {
    if (text instanceof Spanned) {
        Spannable spannable;
        if (text instanceof Spannable) {
            spannable = (Spannable) text;
        } else {
            spannable = new SpannableString(text);
            text = spannable;
        }
        SuggestionSpan[] spans = spannable.getSpans(0, text.length(), SuggestionSpan.class);
        for (int i = 0; i < spans.length; i++) {
            spannable.removeSpan(spans[i]);
        }
    }
    return text;
}
Also used : SpannableString(android.text.SpannableString) SuggestionSpan(android.text.style.SuggestionSpan) Spanned(android.text.Spanned) Spannable(android.text.Spannable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 5 with SpannableString

use of android.text.SpannableString in project MPAndroidChart by PhilJay.

the class PieChartItem method generateCenterText.

private SpannableString generateCenterText() {
    SpannableString s = new SpannableString("MPAndroidChart\ncreated by\nPhilipp Jahoda");
    s.setSpan(new RelativeSizeSpan(1.6f), 0, 14, 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.VORDIPLOM_COLORS[0]), 0, 14, 0);
    s.setSpan(new RelativeSizeSpan(.9f), 14, 25, 0);
    s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, 25, 0);
    s.setSpan(new RelativeSizeSpan(1.4f), 25, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 25, s.length(), 0);
    return s;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Aggregations

SpannableString (android.text.SpannableString)319 Spannable (android.text.Spannable)60 TextView (android.widget.TextView)60 View (android.view.View)56 StyleSpan (android.text.style.StyleSpan)53 ForegroundColorSpan (android.text.style.ForegroundColorSpan)45 TextPaint (android.text.TextPaint)25 Spanned (android.text.Spanned)22 TextAppearanceSpan (android.text.style.TextAppearanceSpan)21 Paint (android.graphics.Paint)20 ImageView (android.widget.ImageView)19 RelativeSizeSpan (android.text.style.RelativeSizeSpan)18 Bundle (android.os.Bundle)17 TypedValue (android.util.TypedValue)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)16 Intent (android.content.Intent)15 SpannableStringBuilder (android.text.SpannableStringBuilder)15 ClickableSpan (android.text.style.ClickableSpan)13 URLSpan (android.text.style.URLSpan)13 LayoutInflater (android.view.LayoutInflater)13