Search in sources :

Example 71 with SpannableString

use of android.text.SpannableString in project wh-app-android by WhiteHouse.

the class FeedItemListFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    showList(false);
    showProgress(true);
    if (mFeedType == TYPE_FAVORITES) {
        bindSubscription(AndroidObservable.bindFragment(this, FeedManager.observeFavorites()).map(feedItems -> {
            List<FeedItemData> processed = new ArrayList<>(feedItems.size());
            FeedItemData data;
            for (FeedItem item : feedItems) {
                data = new FeedItemData();
                data.item = item;
                processed.add(data);
            }
            return processed;
        }).subscribe(this));
        FeedManager.updateFavorites(getActivity());
    } else {
        bindSubscription(fetchData());
        String viewType;
        switch(mFeedType) {
            default:
            case TYPE_ARTICLE:
                viewType = FeedCategoryItem.VIEW_TYPE_ARTICLE_LIST;
                break;
            case TYPE_LIVE:
                viewType = FeedCategoryItem.VIEW_TYPE_LIVE;
                break;
            case TYPE_PHOTOS:
                viewType = FeedCategoryItem.VIEW_TYPE_PHOTO_GALLERY;
                break;
            case TYPE_VIDEOS:
                viewType = FeedCategoryItem.VIEW_TYPE_VIDEO_GALLERY;
                break;
        }
        FeedManager.updateFeedFromServer(mFeedUrl, mFeedTitle, viewType);
    }
    if (mFeedType == TYPE_FAVORITES) {
        Drawable d = getResources().getDrawable(R.drawable.ic_action_bookmark_outline);
        String s = getString(R.string.empty_favorites_list);
        SpannableString ss = new SpannableString(s);
        ImageSpan is = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
        int index = s.indexOf("{icon}");
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        d.setColorFilter(Color.DKGRAY, PorterDuff.Mode.MULTIPLY);
        ss.setSpan(is, index, index + 6, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        getEmptyView().setText(ss);
    } else if (mFeedType == TYPE_LIVE) {
        getEmptyView().setText(R.string.empty_live_list);
    }
    if (getTracker() != null) {
        getTracker().setScreenName("FeedItemList");
        if (mFeedType == TYPE_FAVORITES) {
            getTracker().setPage("Favorites");
        } else {
            getTracker().setPage(mFeedUrl);
        }
    }
}
Also used : SpannableString(android.text.SpannableString) FeedItem(gov.whitehouse.data.model.FeedItem) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) SpannableString(android.text.SpannableString) FeedItemData(gov.whitehouse.core.FeedItemData) ImageSpan(android.text.style.ImageSpan)

Example 72 with SpannableString

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

the class ValidateNotificationPeopleTest method testSingleCharSequence.

@SmallTest
public void testSingleCharSequence() throws Exception {
    String[] expected = { "foobar" };
    Bundle bundle = new Bundle();
    bundle.putCharSequence(Notification.EXTRA_PEOPLE, new SpannableString(expected[0]));
    String[] result = ValidateNotificationPeople.getExtraPeople(bundle);
    assertStringArrayEquals("charSequence should be in result[0]", expected, result);
}
Also used : SpannableString(android.text.SpannableString) Bundle(android.os.Bundle) SpannableString(android.text.SpannableString) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 73 with SpannableString

use of android.text.SpannableString in project Rocket.Chat.Android by RocketChat.

the class Linkify method markupInner.

private static SpannableString markupInner(final CharSequence text) {
    LinkExtractor linkExtractor = LinkExtractor.builder().linkTypes(sTargetType).build();
    SpannableString spannableString = new SpannableString(text);
    for (LinkSpan link : linkExtractor.extractLinks(text)) {
        final int idx1 = link.getBeginIndex();
        final int idx2 = link.getEndIndex();
        final String url = text.subSequence(idx1, idx2).toString();
        spannableString.setSpan(MarkDown.createLinkSpan(url), idx1, idx2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return spannableString;
}
Also used : SpannableString(android.text.SpannableString) LinkExtractor(org.nibor.autolink.LinkExtractor) LinkSpan(org.nibor.autolink.LinkSpan) SpannableString(android.text.SpannableString)

Example 74 with SpannableString

use of android.text.SpannableString in project Rocket.Chat.Android by RocketChat.

the class MarkDown method apply.

/**
   * transform MarkDown text into Spans.
   */
public static void apply(TextView textView) {
    SpannableString text = new SpannableString(textView.getText());
    removeImage(text);
    highlightLink1(text);
    highlightLink2(text);
    bold(text);
    italic(text);
    strike(text);
    textView.setText(text);
}
Also used : SpannableString(android.text.SpannableString)

Example 75 with SpannableString

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

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)

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