Search in sources :

Example 31 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project ActionBarSherlock by JakeWharton.

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 32 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project plaid by nickbutcher.

the class DesignerNewsStory method bindDescription.

private void bindDescription() {
    final TextView storyComment = (TextView) header.findViewById(R.id.story_comment);
    if (!TextUtils.isEmpty(story.comment)) {
        HtmlUtils.parseMarkdownAndSetText(storyComment, story.comment, markdown, new Bypass.LoadImageCallback() {

            @Override
            public void loadImage(String src, ImageLoadingSpan loadingSpan) {
                Glide.with(DesignerNewsStory.this).load(src).asBitmap().diskCacheStrategy(DiskCacheStrategy.ALL).into(new ImageSpanTarget(storyComment, loadingSpan));
            }
        });
    } else {
        storyComment.setVisibility(View.GONE);
    }
    upvoteStory = (TextView) header.findViewById(R.id.story_vote_action);
    upvoteStory.setText(getResources().getQuantityString(R.plurals.upvotes, story.vote_count, NumberFormat.getInstance().format(story.vote_count)));
    upvoteStory.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            upvoteStory();
        }
    });
    final TextView share = (TextView) header.findViewById(R.id.story_share_action);
    share.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((AnimatedVectorDrawable) share.getCompoundDrawables()[1]).start();
            startActivity(ShareCompat.IntentBuilder.from(DesignerNewsStory.this).setText(story.url).setType("text/plain").setSubject(story.title).getIntent());
        }
    });
    TextView storyPosterTime = (TextView) header.findViewById(R.id.story_poster_time);
    SpannableString poster = new SpannableString(story.user_display_name.toLowerCase());
    poster.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_CommentAuthor), 0, poster.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    CharSequence job = !TextUtils.isEmpty(story.user_job) ? "\n" + story.user_job.toLowerCase() : "";
    CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(story.created_at.getTime(), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS).toString().toLowerCase();
    storyPosterTime.setText(TextUtils.concat(poster, job, "\n", timeAgo));
    ImageView avatar = (ImageView) header.findViewById(R.id.story_poster_avatar);
    if (!TextUtils.isEmpty(story.user_portrait_url)) {
        Glide.with(this).load(story.user_portrait_url).placeholder(R.drawable.avatar_placeholder).transform(circleTransform).into(avatar);
    } else {
        avatar.setVisibility(View.GONE);
    }
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) ImageSpanTarget(io.plaidapp.util.glide.ImageSpanTarget) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) PinnedOffsetView(io.plaidapp.ui.widget.PinnedOffsetView) RecyclerView(android.support.v7.widget.RecyclerView) SpannableString(android.text.SpannableString) Bypass(in.uncod.android.bypass.Bypass) ImageLoadingSpan(in.uncod.android.bypass.style.ImageLoadingSpan) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 33 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project android_frameworks_base by ParanoidAndroid.

the class HtmlToSpannedConverter method endFont.

private static void endFont(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Font.class);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);
    if (where != len) {
        Font f = (Font) obj;
        if (!TextUtils.isEmpty(f.mColor)) {
            if (f.mColor.startsWith("@")) {
                Resources res = Resources.getSystem();
                String name = f.mColor.substring(1);
                int colorRes = res.getIdentifier(name, "color", "android");
                if (colorRes != 0) {
                    ColorStateList colors = res.getColorStateList(colorRes);
                    text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            } else {
                int c = Color.getHtmlColor(f.mColor);
                if (c != -1) {
                    text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }
        if (f.mFace != null) {
            text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ColorStateList(android.content.res.ColorStateList) Resources(android.content.res.Resources) TypefaceSpan(android.text.style.TypefaceSpan)

Example 34 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project android_frameworks_base by ParanoidAndroid.

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 35 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project android_frameworks_base by ParanoidAndroid.

the class HtmlTest method testResourceColor.

@SmallTest
public void testResourceColor() throws Exception {
    ColorStateList c = Resources.getSystem().getColorStateList(android.R.color.primary_text_dark);
    Spanned s;
    TextAppearanceSpan[] colors;
    s = Html.fromHtml("<font color=\"@android:color/primary_text_dark\">something</font>");
    colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
    assertEquals(1, colors.length);
    assertEquals(c.toString(), colors[0].getTextColor().toString());
    s = Html.fromHtml("<font color=\"@android:primary_text_dark\">something</font>");
    colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
    assertEquals(1, colors.length);
    assertEquals(c.toString(), colors[0].getTextColor().toString());
    s = Html.fromHtml("<font color=\"@color/primary_text_dark\">something</font>");
    colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
    assertEquals(1, colors.length);
    assertEquals(c.toString(), colors[0].getTextColor().toString());
    s = Html.fromHtml("<font color=\"@primary_text_dark\">something</font>");
    colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
    assertEquals(1, colors.length);
    assertEquals(c.toString(), colors[0].getTextColor().toString());
    s = Html.fromHtml("<font color=\"@" + android.R.color.primary_text_dark + "\">something</font>");
    colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
    assertEquals(1, colors.length);
    assertEquals(c.toString(), colors[0].getTextColor().toString());
    s = Html.fromHtml("<font color=\"gibberish\">something</font>");
    colors = s.getSpans(0, s.length(), TextAppearanceSpan.class);
    assertEquals(colors.length, 0);
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) ColorStateList(android.content.res.ColorStateList) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

TextAppearanceSpan (android.text.style.TextAppearanceSpan)52 SpannableString (android.text.SpannableString)21 SpannableStringBuilder (android.text.SpannableStringBuilder)15 Spanned (android.text.Spanned)15 TypedValue (android.util.TypedValue)15 View (android.view.View)10 ColorStateList (android.content.res.ColorStateList)9 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 Intent (android.content.Intent)5 TypedArray (android.content.res.TypedArray)5 Espresso.onView (android.support.test.espresso.Espresso.onView)5 NoMatchingViewException (android.support.test.espresso.NoMatchingViewException)5 ViewAssertion (android.support.test.espresso.ViewAssertion)5 RootMatchers.withDecorView (android.support.test.espresso.matcher.RootMatchers.withDecorView)5 TextPaint (android.text.TextPaint)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 CharacterStyle (android.text.style.CharacterStyle)5 RelativeSizeSpan (android.text.style.RelativeSizeSpan)5 SuggestionSpan (android.text.style.SuggestionSpan)5 ImageView (android.widget.ImageView)5