Search in sources :

Example 86 with Spanned

use of android.text.Spanned in project WordPress-Android by wordpress-mobile.

the class NotesParseTest method testParagraphInListItem1.

public void testParagraphInListItem1() {
    String text = "<li><p>Paragraph in li</p></li>";
    Spanned spanned = HtmlUtils.fromHtml(text);
    // if this didn't throw a RuntimeException we're ok
    assertNotNull(spanned);
}
Also used : Spanned(android.text.Spanned)

Example 87 with Spanned

use of android.text.Spanned in project WordPress-Android by wordpress-mobile.

the class NotesParseTest method testSpanInListItemFullTest.

public void testSpanInListItemFullTest() {
    String text = "<p>Au Mercredi 18 septembre 2013 vous avez pulvérisé votre précédent record de follows enregistrés en un seul jour, sur votre blog <a href=\"http://taliwutblog.wordpress.com\" title=\"taliwut &amp; blog\" target=\"_blank\" notes-data-click=\"best_period_ever_feat\">taliwut &amp; blog</a>. Super!</p><ul><li><span  class=\"wpn-feat-current-record-title\">Current Record: </span><span class=\"wpn-feat-new-record-count\">20</span></li><li><span  class=\"wpn-feat-old-record-title\">Old Record: </span><span class=\"wpn-feat-old-record-count\">1</span></li></ul>";
    Spanned spanned = HtmlUtils.fromHtml(text);
    assertTrue(spanned.toString().contains("Current Record: 20\nOld Record: 1\n"));
}
Also used : Spanned(android.text.Spanned)

Example 88 with Spanned

use of android.text.Spanned in project WordPress-Android by wordpress-mobile.

the class CommentUtils method displayHtmlComment.

/*
     * displays comment text as html, including retrieving images
     */
public static void displayHtmlComment(TextView textView, String content, int maxImageSize, ImageLoader imageLoader) {
    if (textView == null) {
        return;
    }
    if (content == null) {
        textView.setText(null);
        return;
    }
    // skip performance hit of html conversion if content doesn't contain html
    if (!content.contains("<") && !content.contains("&")) {
        content = content.trim();
        textView.setText(content);
        // make sure unnamed links are clickable
        if (content.contains("://")) {
            Linkify.addLinks(textView, Linkify.WEB_URLS);
        }
        return;
    }
    // convert emoticons first (otherwise they'll be downloaded)
    content = EmoticonsUtils.replaceEmoticonsWithEmoji(content);
    // now convert to HTML with an image getter that enforces a max image size
    final Spanned html;
    if (maxImageSize > 0 && content.contains("<img")) {
        Drawable loading = ContextCompat.getDrawable(textView.getContext(), R.drawable.legacy_dashicon_format_image_big_grey);
        Drawable failed = ContextCompat.getDrawable(textView.getContext(), R.drawable.ic_notice_grey_500_48dp);
        html = HtmlUtils.fromHtml(content, new WPImageGetter(textView, maxImageSize, imageLoader, loading, failed));
    } else {
        html = HtmlUtils.fromHtml(content);
    }
    // remove extra \n\n added by Html.convert()
    int start = 0;
    int end = html.length();
    while (start < end && Character.isWhitespace(html.charAt(start))) {
        start++;
    }
    while (end > start && Character.isWhitespace(html.charAt(end - 1))) {
        end--;
    }
    textView.setText(html.subSequence(start, end));
}
Also used : Drawable(android.graphics.drawable.Drawable) WPImageGetter(org.wordpress.android.util.helpers.WPImageGetter) Spanned(android.text.Spanned) Paint(android.graphics.Paint)

Example 89 with Spanned

use of android.text.Spanned in project pictureapp by EyeSeeTea.

the class LayoutUtils method setActionBarAppAndUser.

public static void setActionBarAppAndUser(ActionBar actionBar) {
    Context context = PreferencesState.getInstance().getContext();
    actionBar.setLogo(R.drawable.pictureapp_logo);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    int color = ContextCompat.getColor(context, R.color.text_first_color);
    String colorString = String.format("%X", color).substring(2);
    Spanned spannedTitle = Html.fromHtml(String.format("<font color=\"#%s\" size=\"10\"><b>%s</b></font>", colorString, context.getString(R.string.malaria_case_based_reporting)));
    color = ContextCompat.getColor(context, R.color.text_second_color);
    colorString = String.format("%X", color).substring(2);
    User user = User.getLoggedUser();
    String userName;
    userName = (user == null) ? "" : user.getName();
    String volunteer = context.getString(R.string.volunteer_label);
    Spanned spannedSubTitle = Html.fromHtml(String.format("<font color=\"#%s\"><b>%s</b></font>", colorString, volunteer + " " + userName + ""));
    actionBar.setCustomView(R.layout.custom_action_bar);
    TextView title = (TextView) actionBar.getCustomView().findViewById(R.id.action_bar_multititle_title);
    title.setText(spannedTitle);
    Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/" + context.getString(R.string.light_font));
    title.setTypeface(tf);
    TextView subtitle = (TextView) actionBar.getCustomView().findViewById(R.id.action_bar_multititle_subtitle);
    subtitle.setText(spannedSubTitle);
    tf = Typeface.createFromAsset(context.getAssets(), "fonts/" + context.getString(R.string.light_font));
    subtitle.setTypeface(tf);
}
Also used : Context(android.content.Context) User(org.eyeseetea.malariacare.data.database.model.User) Typeface(android.graphics.Typeface) TextView(android.widget.TextView) Spanned(android.text.Spanned)

Example 90 with Spanned

use of android.text.Spanned in project BBS-Android by bdpqchen.

the class JellyBeanSpanFixTextView method fixOnMeasure.

/**
     * If possible, fixes the Spanned text by adding spaces around spans when needed.
     */
private void fixOnMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    CharSequence text = getText();
    if (text instanceof Spanned) {
        SpannableStringBuilder builder = new SpannableStringBuilder(text);
        fixSpannedWithSpaces(builder, widthMeasureSpec, heightMeasureSpec);
    } else {
        if (HtmlTextView.DEBUG) {
            Log.d(HtmlTextView.TAG, "The text isn't a Spanned");
        }
        fallbackToString(widthMeasureSpec, heightMeasureSpec);
    }
}
Also used : Spanned(android.text.Spanned) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

Spanned (android.text.Spanned)200 Paint (android.graphics.Paint)81 TextPaint (android.text.TextPaint)63 Spannable (android.text.Spannable)32 SpannableStringBuilder (android.text.SpannableStringBuilder)26 SuggestionSpan (android.text.style.SuggestionSpan)24 SpannableString (android.text.SpannableString)23 Editable (android.text.Editable)22 TextAppearanceSpan (android.text.style.TextAppearanceSpan)15 SpannedString (android.text.SpannedString)14 TypedArray (android.content.res.TypedArray)12 URLSpan (android.text.style.URLSpan)12 View (android.view.View)11 Context (android.content.Context)9 StyleSpan (android.text.style.StyleSpan)9 InputMethodManager (android.view.inputmethod.InputMethodManager)9 Parcelable (android.os.Parcelable)8 TextView (android.widget.TextView)8 WordIterator (android.text.method.WordIterator)7 CharacterStyle (android.text.style.CharacterStyle)7