Search in sources :

Example 16 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project ZhihuDailyPurify by izzyleung.

the class IzzySearchView method getDecoratedHint.

private CharSequence getDecoratedHint(CharSequence hintText) {
    Spannable ssb = new SpannableString(hintText);
    //noinspection deprecation
    ssb.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.search_view_hint_color)), 0, hintText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ssb;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Spannable(android.text.Spannable)

Example 17 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project Talon-for-Twitter by klinker24.

the class TextUtils method changeText.

public static Spannable changeText(Spannable original, String target, int colour) {
    target = target.replaceAll("\"", "");
    String vString = original.toString();
    int startSpan = 0, endSpan = 0;
    Spannable spanRange = original;
    while (true) {
        startSpan = vString.indexOf(target, endSpan);
        ForegroundColorSpan foreColour = new ForegroundColorSpan(colour);
        // Need a NEW span object every loop, else it just moves the span
        if (startSpan < 0)
            break;
        endSpan = startSpan + target.length();
        spanRange.setSpan(foreColour, startSpan, endSpan, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return spanRange;
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannableString(android.text.SpannableString) Spannable(android.text.Spannable)

Example 18 with ForegroundColorSpan

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

the class MessageListAdapter method formatPreviewText.

private void formatPreviewText(TextView preview, CharSequence beforePreviewText, String sigil) {
    Spannable previewText = (Spannable) preview.getText();
    previewText.setSpan(buildSenderSpan(), 0, beforePreviewText.length() + sigil.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    int previewSpanColor = buildPreviewSpanColor();
    // Set span (color) for preview message
    previewText.setSpan(new ForegroundColorSpan(previewSpanColor), beforePreviewText.length() + sigil.length(), previewText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Spannable(android.text.Spannable)

Example 19 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project Android-Iconics by mikepenz.

the class PlaygroundActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_playground);
    //Show how to style the text of an existing TextView
    TextView tv1 = (TextView) findViewById(R.id.test1);
    new Iconics.IconicsBuilder().ctx(this).style(new ForegroundColorSpan(Color.WHITE), new BackgroundColorSpan(Color.BLACK), new RelativeSizeSpan(2f)).styleFor("faw-adjust", new BackgroundColorSpan(Color.RED), new ForegroundColorSpan(Color.parseColor("#33000000")), new RelativeSizeSpan(2f)).on(tv1).build();
    //You can also do some advanced stuff like setting an image within a text
    TextView tv2 = (TextView) findViewById(R.id.test5);
    SpannableString sb = new SpannableString(tv2.getText());
    IconicsDrawable d = new IconicsDrawable(this, FontAwesome.Icon.faw_android).sizeDp(48).paddingDp(4);
    sb.setSpan(new ImageSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv2.setText(sb);
    //Set the icon of an ImageView (or something else) as drawable
    ImageView iv2 = (ImageView) findViewById(R.id.test2);
    iv2.setImageDrawable(new IconicsDrawable(this, FontAwesome.Icon.faw_thumbs_o_up).sizeDp(48).color(Color.parseColor("#aaFF0000")).contourWidthDp(1));
    //Set the icon of an ImageView (or something else) as bitmap
    ImageView iv3 = (ImageView) findViewById(R.id.test3);
    iv3.setImageBitmap(new IconicsDrawable(this, FontAwesome.Icon.faw_android).sizeDpX(48).sizeDpY(32).paddingDp(4).roundedCornersDp(8).color(Color.parseColor("#deFF0000")).toBitmap());
    //Show how to style the text of an existing button
    Button b4 = (Button) findViewById(R.id.test4);
    new Iconics.IconicsBuilder().ctx(this).style(new BackgroundColorSpan(Color.BLACK)).style(new RelativeSizeSpan(2f)).style(new ForegroundColorSpan(Color.WHITE)).on(b4).build();
    //Show how to style the text of an existing button
    ImageButton b6 = (ImageButton) findViewById(R.id.test6);
    StateListDrawable iconStateListDrawable = new StateListDrawable();
    iconStateListDrawable.addState(new int[] { android.R.attr.state_pressed }, new IconicsDrawable(this, FontAwesome.Icon.faw_thumbs_o_up).sizeDp(48).color(Color.parseColor("#aaFF0000")).contourWidthDp(1));
    iconStateListDrawable.addState(new int[] {}, new IconicsDrawable(this, FontAwesome.Icon.faw_thumbs_o_up).sizeDp(48).color(Color.parseColor("#aa00FF00")).contourWidthDp(2));
    b6.setImageDrawable(iconStateListDrawable);
    ListView listView = (ListView) findViewById(R.id.list);
    IconicsDrawable iconicsDrawableBase = new IconicsDrawable(this).actionBar().color(Color.GREEN).backgroundColor(Color.RED);
    IconicsDrawable[] array = new IconicsArrayBuilder(iconicsDrawableBase).add(FontAwesome.Icon.faw_android).add(Octicons.Icon.oct_octoface).add("Hallo").add('A').add(";)").build();
    listView.setAdapter(new IconsAdapter(this, array));
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Iconics(com.mikepenz.iconics.Iconics) RelativeSizeSpan(android.text.style.RelativeSizeSpan) StateListDrawable(android.graphics.drawable.StateListDrawable) SpannableString(android.text.SpannableString) ImageButton(android.widget.ImageButton) ListView(android.widget.ListView) ImageButton(android.widget.ImageButton) Button(android.widget.Button) IconicsArrayBuilder(com.mikepenz.iconics.IconicsArrayBuilder) TextView(android.widget.TextView) ImageView(android.widget.ImageView) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) BackgroundColorSpan(android.text.style.BackgroundColorSpan) ImageSpan(android.text.style.ImageSpan)

Example 20 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project KeepScore by nolanlawson.

the class AutofitTextView method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int height = getHeight() - getCompoundPaddingBottom() - getCompoundPaddingTop();
    int maxNumLines = (height / getLineHeight());
    if (maxNumLines >= 2) {
        String oldText = getText().toString();
        int cutoffIndex = StringUtil.getNthIndexOf('\n', oldText, maxNumLines);
        if (cutoffIndex != -1) {
            // cut off the text
            int startOfLastLine = StringUtil.getNthIndexOf('\n', oldText, maxNumLines - 1);
            // make the last line semi-transparent, to indicate that there
            // are more results left
            // (similar to the ellipsize effect in normal text views, but
            // vertical)
            // get the original color (blue or red)
            ForegroundColorSpan[] foregroundColorSpans = ((SpannedString) getText()).getSpans(startOfLastLine + 1, cutoffIndex, ForegroundColorSpan.class);
            // make an alpha-ized gradient out of the original color
            int originalColor = foregroundColorSpans[0].getForegroundColor();
            int startColor = (START_ALPHA << 24) | (0x00FFFFFF & originalColor);
            int endColor = (END_ALPHA << 24) | (0x00FFFFFF & originalColor);
            int numLines = StringUtil.count(getText().subSequence(0, cutoffIndex).toString(), "\n");
            float startY = (numLines * getLineHeight());
            float endY = startY + getLineHeight();
            // build up a new spannable
            SpannableStringBuilder builder = new SpannableStringBuilder().append(getText().subSequence(0, startOfLastLine)).append(getText().subSequence(startOfLastLine, cutoffIndex).toString());
            builder.setSpan(new TopDownGradientSpan(startColor, endColor, startY, endY), startOfLastLine, cutoffIndex, 0);
            setText(builder);
        }
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannedString(android.text.SpannedString) SpannedString(android.text.SpannedString) TopDownGradientSpan(com.nolanlawson.keepscore.android.TopDownGradientSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

ForegroundColorSpan (android.text.style.ForegroundColorSpan)152 SpannableStringBuilder (android.text.SpannableStringBuilder)56 SpannableString (android.text.SpannableString)48 StyleSpan (android.text.style.StyleSpan)25 TextView (android.widget.TextView)24 ImageSpan (android.text.style.ImageSpan)23 RelativeSizeSpan (android.text.style.RelativeSizeSpan)21 View (android.view.View)21 Spannable (android.text.Spannable)20 BackgroundColorSpan (android.text.style.BackgroundColorSpan)18 TypefaceSpan (android.text.style.TypefaceSpan)16 StrikethroughSpan (android.text.style.StrikethroughSpan)14 UnderlineSpan (android.text.style.UnderlineSpan)13 Drawable (android.graphics.drawable.Drawable)12 EditText (android.widget.EditText)11 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)10 CharacterStyle (android.text.style.CharacterStyle)10 SuperscriptSpan (android.text.style.SuperscriptSpan)8 LinearLayout (android.widget.LinearLayout)8 URLSpan (android.text.style.URLSpan)7