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);
}
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 & blog\" target=\"_blank\" notes-data-click=\"best_period_ever_feat\">taliwut & 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"));
}
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));
}
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);
}
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);
}
}
Aggregations