Search in sources :

Example 1 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 2 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 3 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 4 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project actor-platform by actorapp.

the class ActorBinder method bind.

public void bind(final TextView textView, final View titleContainer, final GroupVM value) {
    bind(value.getPresence(), value.getMembersCount(), value.isMember(), (online, onlineModel, membersCount, membersModel, isMember, isMemberModel) -> {
        if (isMember) {
            titleContainer.setVisibility(View.VISIBLE);
            if (online <= 0) {
                SpannableStringBuilder builder = new SpannableStringBuilder(messenger().getFormatter().formatGroupMembers(membersCount));
                builder.setSpan(new ForegroundColorSpan(0xB7ffffff), 0, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                textView.setText(builder);
            } else {
                SpannableStringBuilder builder = new SpannableStringBuilder(messenger().getFormatter().formatGroupMembers(membersCount) + ", ");
                builder.setSpan(new ForegroundColorSpan(0xB7ffffff), 0, builder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                builder.append(messenger().getFormatter().formatGroupOnline(online));
                textView.setText(builder);
            }
        } else {
            titleContainer.setVisibility(View.GONE);
        }
    });
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 5 with ForegroundColorSpan

use of android.text.style.ForegroundColorSpan in project actor-platform by actorapp.

the class AndroidMarkdown method processText.

private static Spannable processText(String markdown, int mode) {
    MDDocument doc = new MarkdownParser(mode).processDocument(markdown);
    SpannableStringBuilder builder = new SpannableStringBuilder();
    boolean isFirst = true;
    for (MDSection s : doc.getSections()) {
        if (isFirst) {
            isFirst = false;
        } else {
            builder.append("\n");
        }
        if (s.getType() == MDSection.TYPE_CODE) {
            int start = builder.length();
            builder.append("View Source Code");
            final String text = s.getCode().getCode();
            builder.setSpan(new RelativeSizeSpan(1.1f), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            builder.setSpan(new ForegroundColorSpan(Color.RED), start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            builder.setSpan(new ClickableSpan() {

                @Override
                public void onClick(View view) {
                    AndroidContext.getContext().startActivity(new Intent(AndroidContext.getContext(), CodePreviewActivity.class).putExtra("source_code", text).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                }
            }, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else if (s.getType() == MDSection.TYPE_TEXT) {
            writeText(s.getText(), builder);
        } else {
            throw new RuntimeException("Unknown section type: " + s.getType());
        }
    }
    return builder;
}
Also used : MDSection(im.actor.runtime.markdown.MDSection) ForegroundColorSpan(android.text.style.ForegroundColorSpan) MDDocument(im.actor.runtime.markdown.MDDocument) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) RelativeSizeSpan(android.text.style.RelativeSizeSpan) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) MarkdownParser(im.actor.runtime.markdown.MarkdownParser) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

ForegroundColorSpan (android.text.style.ForegroundColorSpan)307 SpannableString (android.text.SpannableString)114 SpannableStringBuilder (android.text.SpannableStringBuilder)109 StyleSpan (android.text.style.StyleSpan)74 Spannable (android.text.Spannable)52 TextView (android.widget.TextView)50 RelativeSizeSpan (android.text.style.RelativeSizeSpan)48 View (android.view.View)45 BackgroundColorSpan (android.text.style.BackgroundColorSpan)38 TypefaceSpan (android.text.style.TypefaceSpan)34 ImageSpan (android.text.style.ImageSpan)32 StrikethroughSpan (android.text.style.StrikethroughSpan)26 UnderlineSpan (android.text.style.UnderlineSpan)23 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)20 CharacterStyle (android.text.style.CharacterStyle)19 TextPaint (android.text.TextPaint)18 ImageView (android.widget.ImageView)18 URLSpan (android.text.style.URLSpan)16 Intent (android.content.Intent)15 Drawable (android.graphics.drawable.Drawable)15