Example usage for android.text Html fromHtml

List of usage examples for android.text Html fromHtml

Introduction

In this page you can find the example usage for android.text Html fromHtml.

Prototype

@Deprecated
public static Spanned fromHtml(String source) 

Source Link

Document

Returns displayable styled text from the provided HTML string with the legacy flags #FROM_HTML_MODE_LEGACY .

Usage

From source file:Main.java

public static Spanned toSpanned(final Context context, final String toastString,
        @ColorRes final int toastColor) {
    final String string = "" + context.getResources().getColor(toastColor);
    final Spannable spannable = (Spannable) Html
            .fromHtml(colorize_a(colorize_em(toastString, string, true), string));
    for (final URLSpan urlSpan : (URLSpan[]) spannable.getSpans(0, spannable.length(), (Class) URLSpan.class)) {
        spannable.setSpan(urlSpan, spannable.getSpanStart(urlSpan), spannable.getSpanEnd(urlSpan), 0);
    }//from   w  w  w  .  java  2s .c o m
    return spannable;
}

From source file:Main.java

public static void formatHtmlString(String string, TextView textView) {

    textView.setText(Html.fromHtml(string));
    Linkify.addLinks(textView, Pattern.compile(FILICK_URL_EXPRESSION), "http://", new MatchFilter() { //$NON-NLS-1$

        @Override/*from w  ww  .  j a v  a  2s  .c  om*/
        public boolean acceptMatch(CharSequence s, int start, int end) {
            return true;
        }

    }, new TransformFilter() {

        @Override
        public String transformUrl(Matcher matcher, String data) {
            if (data.length() > 2) {
                return data.substring(1, data.length() - 1);
            }
            return data;
        }

    });
}

From source file:Main.java

public static void showMessage(Context _context, String title, String message, int icon,
        DialogInterface.OnClickListener ackHandler) {
    AlertDialog.Builder builder = new AlertDialog.Builder(_context);
    builder.setTitle(title);//ww w  .  j a v  a 2 s  . c o  m
    builder.setMessage(Html.fromHtml(message));
    builder.setCancelable(false);
    builder.setPositiveButton("Acknowledged", ackHandler);
    builder.setIcon(icon);
    builder.show();
}

From source file:Main.java

public static void showMessage(Context _context, String title, String message, int icon,
        DialogInterface.OnClickListener ackHandler) {
    try {/*from   w ww.j  av  a2  s .  c  o  m*/
        AlertDialog.Builder builder = new AlertDialog.Builder(_context);
        builder.setTitle(title);
        builder.setMessage(Html.fromHtml(message));
        builder.setCancelable(false);
        builder.setPositiveButton("Acknowledged", ackHandler);
        builder.setIcon(icon);
        builder.show();
    } catch (Exception e) {
    }
}

From source file:com.orange.ocara.model.export.docx.Presenter.java

protected static String toHtmlNotNull(String value) {
    return notNull(Html.fromHtml(value).toString());
}

From source file:Main.java

public static AlertDialog.Builder dialogBuilder(Context context, String title, String msg, int i) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    if (msg != null) {
        builder.setMessage(Html.fromHtml(msg));
    }//w  w w.j a  v a2 s. c o m
    if (title != null) {
        builder.setTitle(title);
    }
    return builder;
}

From source file:Main.java

public static Spanned fromHTML(String textToTransform) {
    return Html.fromHtml(textToTransform);
}

From source file:Main.java

public static void setValue(TextView v, String value, String defaultValue) {
    String err_msg_which = "";
    if (v != null) {
        if (TextUtils.isEmpty(value)) {
            err_msg_which = "Value";
            value = defaultValue;//from  www  .  ja  v  a2s  .com
        }
        v.setText(Html.fromHtml(value));
    } else {
        err_msg_which = "TextView";
    }
    String err_msg_format = "%s is null";
    //      LogU.eLog(String.format(err_msg_format, err_msg_which));
}

From source file:Main.java

public static void setHtmlText(TextView textView, String htmlText) {
    textView.setText(TextUtils.isEmpty(htmlText) ? null : Html.fromHtml(htmlText));
}

From source file:Main.java

public static CharSequence fixHtml(String brokenHtml) {
    // There's some terrible bug that displays all the text as the 
    // opening tag if a tag is the first thing in the string
    // so we hack around it so it begins with something else
    // when we convert it

    // terrible hack, just add some chars
    Spanned html = Html.fromHtml("aa" + brokenHtml);
    // after we have the good html, remove the chars
    CharSequence fixedText = html.subSequence(2, html.length());
    return fixedText;
}