Code example for SpannedString

1
     * 
     * @param source the string to be transformed 
     * @return spanned text 
     */ 
    public static Spanned fromHtml(String source) {
        if (source == null || TextUtils.isEmpty(source)) return new SpannedString("");
 
        source = source.replace(System.getProperty("line.separator"), "<br/>");
 
        try { 
            return Html.fromHtml(source);
        } catch (RuntimeException e) {
            if (e.getCause() instanceof IOException) {
                // Pushback buffer full, retry with smaller input 
                return fromHtml(source.substring(0, source.length() / 2));
            } else { 
                throw e;
            } 
        } 
    }