Search in sources :

Example 31 with SpannableString

use of android.text.SpannableString 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 32 with SpannableString

use of android.text.SpannableString in project qksms by moezbhatti.

the class LinkifyUtils method replaceAll.

// thanks to @commonsware https://stackoverflow.com/a/11417498
public static <A extends CharacterStyle, B extends CharacterStyle> Spannable replaceAll(CharSequence original, Class<A> sourceType, SpanConverter<A, B> converter) {
    SpannableString result = new SpannableString(original);
    A[] spans = result.getSpans(0, result.length(), sourceType);
    for (A span : spans) {
        int start = result.getSpanStart(span);
        int end = result.getSpanEnd(span);
        int flags = result.getSpanFlags(span);
        result.removeSpan(span);
        result.setSpan(converter.convert(span), start, end, flags);
    }
    return (result);
}
Also used : SpannableString(android.text.SpannableString)

Example 33 with SpannableString

use of android.text.SpannableString in project Signal-Android by WhisperSystems.

the class RecipientsEditor method contactToToken.

/*public boolean containsEmail() {
        if (TextUtils.indexOf(getText(), '@') == -1)
            return false;

        List<String> numbers = mTokenizer.getNumbers();
        for (String number : numbers) {
            if (Mms.isEmailAddress(number))
                return true;
        }
        return false;
    }*/
public static CharSequence contactToToken(Recipient c) {
    String name = c.getName();
    String number = c.getNumber();
    SpannableString s = new SpannableString(RecipientsFormatter.formatNameAndNumber(name, number));
    int len = s.length();
    if (len == 0) {
        return s;
    }
    s.setSpan(new Annotation("number", c.getNumber()), 0, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return s;
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) Annotation(android.text.Annotation)

Example 34 with SpannableString

use of android.text.SpannableString in project Signal-Android by WhisperSystems.

the class SpanUtil method italic.

public static CharSequence italic(CharSequence sequence, int length) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan)

Example 35 with SpannableString

use of android.text.SpannableString in project Signal-Android by WhisperSystems.

the class SpanUtil method bold.

public static CharSequence bold(CharSequence sequence) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan)

Aggregations

SpannableString (android.text.SpannableString)325 TextView (android.widget.TextView)61 Spannable (android.text.Spannable)60 View (android.view.View)57 StyleSpan (android.text.style.StyleSpan)53 ForegroundColorSpan (android.text.style.ForegroundColorSpan)47 TextPaint (android.text.TextPaint)25 Spanned (android.text.Spanned)24 TextAppearanceSpan (android.text.style.TextAppearanceSpan)21 Paint (android.graphics.Paint)20 RelativeSizeSpan (android.text.style.RelativeSizeSpan)19 ImageView (android.widget.ImageView)19 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)14 URLSpan (android.text.style.URLSpan)13 LayoutInflater (android.view.LayoutInflater)13