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 getStringToHtml(Context context, int format, Object... str) {
    return Html.fromHtml(String.format(context.getText(format).toString(), str));
}

From source file:Main.java

public static CharSequence getTextFromHtml(String content) {
    CharSequence text = "";
    if (isNotEmpty(content)) {
        text = Html.fromHtml(content);
    }/*  w ww .jav  a2  s. c  o m*/
    return text;
}

From source file:Main.java

public static void setError(Context context, EditText editText, int messageId) {
    editText.setError(Html.fromHtml("<font color='red'>" + context.getString(messageId) + "</font>"));
}

From source file:Main.java

private static void setText(TextView view, String text, boolean keepHtml) {
    CharSequence displayText = null;
    if (text != null) {
        displayText = keepHtml ? Html.fromHtml(text) : Html.fromHtml(text).toString();
    }//from ww  w.j av  a2 s  .  c  o  m
    if (view != null) {
        if (displayText != null && !"".equals(displayText)) {
            view.setVisibility(View.VISIBLE);
            view.setText(displayText);
        } else {
            view.setVisibility(View.GONE);
        }
    }
}

From source file:Main.java

public static void jumpToSystemDownloadApk(Context context, String url) {
    Intent intent = new Intent("android.intent.action.VIEW");
    Uri data = Uri.parse(Html.fromHtml(url).toString());
    intent.setData(data);//w ww.j a  va 2 s  . com
    intent.setPackage("com.google.android.browser");
    intent.addCategory("android.intent.category.BROWSABLE");
    intent.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
    context.startActivity(intent);
}

From source file:Main.java

public static void setText(Activity r, final TextView v, final String text) {
    r.runOnUiThread(new Runnable() {
        @Override/*from w w  w  .ja  v a 2s.co m*/
        public void run() {
            try {
                v.setSingleLine(false);
                v.setText(Html.fromHtml(text));
            } catch (Exception e) {
            }
        }
    });
}

From source file:Main.java

public static void setValue(TextView v, String value) {
    String err_msg_which = "";
    if (v != null) {
        if (TextUtils.isEmpty(value)) {
            err_msg_which = "Value";
            value = "";
        }//from  www . ja va  2 s. c  o m
        v.setText(Html.fromHtml(value));
    } else {
        err_msg_which = "TextView";
    }
}

From source file:Main.java

public static String fixHtmlText(String text) {
    if (text != null) {
        text = text.trim().replaceAll("\\\\+", "");
        text = text.replace("&amp;", "&");
        text = text.replace("&lt;", "<");
        text = text.replace("&gt;", ">");
        text = text.replace("&quot;", "\"");
    }//from   w  w  w  .j  a v  a 2  s .c  o  m
    text = Html.fromHtml(text).toString();
    return text;
}

From source file:Main.java

private static void makeHtml(ViewGroup viewGroup) {
    for (int i = 0; i < viewGroup.getChildCount(); i++) {
        final View childView = viewGroup.getChildAt(i);
        if (childView instanceof TextView) {
            final TextView curr = (TextView) childView;
            curr.setText(Html.fromHtml(curr.getText().toString()));
        }//www  .  ja  va  2 s  . com

        if (childView instanceof ViewGroup) {
            makeHtml((ViewGroup) childView);
        }
    }
}

From source file:Main.java

public static void buildLink(TextView view, String url) {
    Log.d(TAG, "buildLink(view = " + view + ", url = " + url + ")");

    StringBuilder sb = new StringBuilder();
    sb.append("<a href='").append(url).append("'>").append(view.getText()).append("</a>");
    view.setText(Html.fromHtml(sb.toString()));
    view.setMovementMethod(LinkMovementMethod.getInstance());
}