Java Code Examples for android.text.Html#escapeHtml()
The following examples show how to use
android.text.Html#escapeHtml() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From NaviBee with GNU General Public License v3.0 | 5 votes |
private void setupWelcomeBanner() { mOverflowButton = findViewById(R.id.landing_user_icon); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mOverflowButton.setClipToOutline(true); } mOverflowButton.setOnClickListener(v -> mPopupWindow.show()); new URLImageViewCacheLoader( Objects.requireNonNull(mUser.getPhotoUrl()).toString(), mOverflowButton).roundImage(true).execute(); TextView welcomeLine = findViewById(R.id.landing_welcome_line); String format = getResources().getString(R.string.landing_welcome_line); format = format.replace("\n", "<br>"); String name = Objects.requireNonNull(mUser.getDisplayName()); name = Html.escapeHtml(name.split(" ", 2)[0]); String text = String.format(format, "<b>" + name + "</b>"); Spanned spannedText; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { spannedText = Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT); } else { spannedText = Html.fromHtml(text); } welcomeLine.setText(spannedText); }
Example 2
Source File: EncodeUtils.java From Android-UtilCode with Apache License 2.0 | 5 votes |
/** * Html编码 * * @param input 要Html编码的字符串 * @return Html编码后的字符串 */ public static String htmlEncode(CharSequence input) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { return Html.escapeHtml(input); } else { // 参照Html.escapeHtml()中代码 StringBuilder out = new StringBuilder(); for (int i = 0, len = input.length(); i < len; i++) { char c = input.charAt(i); if (c == '<') { out.append("<"); } else if (c == '>') { out.append(">"); } else if (c == '&') { out.append("&"); } else if (c >= 0xD800 && c <= 0xDFFF) { if (c < 0xDC00 && i + 1 < len) { char d = input.charAt(i + 1); if (d >= 0xDC00 && d <= 0xDFFF) { i++; int codepoint = 0x010000 | (int) c - 0xD800 << 10 | (int) d - 0xDC00; out.append("&#").append(codepoint).append(";"); } } } else if (c > 0x7E || c < ' ') { out.append("&#").append((int) c).append(";"); } else if (c == ' ') { while (i + 1 < len && input.charAt(i + 1) == ' ') { out.append(" "); i++; } out.append(' '); } else { out.append(c); } } return out.toString(); } }
Example 3
Source File: RxEncodeTool.java From RxTools-master with Apache License 2.0 | 5 votes |
/** * Html编码 * * @param input 要Html编码的字符串 * @return Html编码后的字符串 */ public static String htmlEncode(String input) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { return Html.escapeHtml(input); } else { // 参照Html.escapeHtml()中代码 StringBuilder out = new StringBuilder(); for (int i = 0, len = input.length(); i < len; i++) { char c = input.charAt(i); if (c == '<') { out.append("<"); } else if (c == '>') { out.append(">"); } else if (c == '&') { out.append("&"); } else if (c >= 0xD800 && c <= 0xDFFF) { if (c < 0xDC00 && i + 1 < len) { char d = input.charAt(i + 1); if (d >= 0xDC00 && d <= 0xDFFF) { i++; int codepoint = 0x010000 | (int) c - 0xD800 << 10 | (int) d - 0xDC00; out.append("&#").append(codepoint).append(";"); } } } else if (c > 0x7E || c < ' ') { out.append("&#").append((int) c).append(";"); } else if (c == ' ') { while (i + 1 < len && input.charAt(i + 1) == ' ') { out.append(" "); i++; } out.append(' '); } else { out.append(c); } } return out.toString(); } }
Example 4
Source File: EncodeUtils.java From ZhiHu-TopAnswer with Apache License 2.0 | 5 votes |
/** * Html编码 * * @param input 要Html编码的字符串 * @return Html编码后的字符串 */ public static String htmlEncode(String input) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { return Html.escapeHtml(input); } else { // 参照Html.escapeHtml()中代码 StringBuilder out = new StringBuilder(); for (int i = 0, len = input.length(); i < len; i++) { char c = input.charAt(i); if (c == '<') { out.append("<"); } else if (c == '>') { out.append(">"); } else if (c == '&') { out.append("&"); } else if (c >= 0xD800 && c <= 0xDFFF) { if (c < 0xDC00 && i + 1 < len) { char d = input.charAt(i + 1); if (d >= 0xDC00 && d <= 0xDFFF) { i++; int codepoint = 0x010000 | (int) c - 0xD800 << 10 | (int) d - 0xDC00; out.append("&#").append(codepoint).append(";"); } } } else if (c > 0x7E || c < ' ') { out.append("&#").append((int) c).append(";"); } else if (c == ' ') { while (i + 1 < len && input.charAt(i + 1) == ' ') { out.append(" "); i++; } out.append(' '); } else { out.append(c); } } return out.toString(); } }
Example 5
Source File: EncodeUtils.java From JianshuApp with GNU General Public License v3.0 | 5 votes |
/** * Html编码 * * @param input 要Html编码的字符串 * @return Html编码后的字符串 */ public static String htmlEncode(CharSequence input) { if (Build.VERSION_CODES.JELLY_BEAN <= Build.VERSION.SDK_INT) { return Html.escapeHtml(input); } else { // 参照Html.escapeHtml()中代码 StringBuilder out = new StringBuilder(); for (int i = 0, len = input.length(); i < len; i++) { char c = input.charAt(i); if (c == '<') { out.append("<"); } else if (c == '>') { out.append(">"); } else if (c == '&') { out.append("&"); } else if (c >= 0xD800 && c <= 0xDFFF) { if (c < 0xDC00 && i + 1 < len) { char d = input.charAt(i + 1); if (d >= 0xDC00 && d <= 0xDFFF) { i++; int codepoint = 0x010000 | (int) c - 0xD800 << 10 | (int) d - 0xDC00; out.append("&#").append(codepoint).append(";"); } } } else if (c > 0x7E || c < ' ') { out.append("&#").append((int) c).append(";"); } else if (c == ' ') { while (i + 1 < len && input.charAt(i + 1) == ' ') { out.append(" "); i++; } out.append(' '); } else { out.append(c); } } return out.toString(); } }
Example 6
Source File: JsonUtils.java From MongoExplorer with MIT License | 5 votes |
private static String formatString(String value) { if (isUrl(value)) { value = Html.escapeHtml(value); value = "<a href=\"" + value + "\">" + value + "</a>"; } else { value = Html.escapeHtml(value); } return "<font color=\"#006600\">\"" + value + "\"</font>"; }
Example 7
Source File: ClipData.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Turn this item into HTML text, regardless of the type of data it * actually contains. * * <p>The algorithm for deciding what text to return is: * <ul> * <li> If {@link #getHtmlText} is non-null, return that. * <li> If {@link #getText} is non-null, return that, converting to * valid HTML text. If this text contains style spans, * {@link Html#toHtml(Spanned) Html.toHtml(Spanned)} is used to * convert them to HTML formatting. * <li> If {@link #getUri} is non-null, try to retrieve its data * as a text stream from its content provider. If the provider can * supply text/html data, that will be preferred and returned as-is. * Otherwise, any text/* data will be returned and escaped to HTML. * If it is not a content: URI or the content provider does not supply * a text representation, HTML text containing a link to the URI * will be returned. * <li> If {@link #getIntent} is non-null, convert that to an intent: * URI and return as an HTML link. * <li> Otherwise, return an empty string. * </ul> * * @param context The caller's Context, from which its ContentResolver * and other things can be retrieved. * @return Returns the item's representation as HTML text. */ public String coerceToHtmlText(Context context) { // If the item has an explicit HTML value, simply return that. String htmlText = getHtmlText(); if (htmlText != null) { return htmlText; } // If this Item has a plain text value, return it as HTML. CharSequence text = getText(); if (text != null) { if (text instanceof Spanned) { return Html.toHtml((Spanned)text); } return Html.escapeHtml(text); } text = coerceToHtmlOrStyledText(context, false); return text != null ? text.toString() : null; }
Example 8
Source File: HtmlHelper.java From FairEmail with GNU General Public License v3.0 | 4 votes |
static String formatPre(String text, boolean quote) { int level = 0; StringBuilder sb = new StringBuilder(); String[] lines = text.split("\\r?\\n"); for (String line : lines) { // Opening quotes // https://tools.ietf.org/html/rfc3676#section-4.5 if (quote) { int tlevel = 0; while (line.startsWith(">")) { tlevel++; if (tlevel > level) sb.append("<blockquote>"); line = line.substring(1); // > if (line.startsWith(" >")) line = line.substring(1); } if (tlevel > 0) if (line.length() > 0 && line.charAt(0) == ' ') line = line.substring(1); // Closing quotes for (int i = 0; i < level - tlevel; i++) sb.append("</blockquote>"); level = tlevel; } // Tabs characters StringBuilder l = new StringBuilder(); for (int j = 0; j < line.length(); j++) { char kar = line.charAt(j); if (kar == '\t') { l.append(' '); while (l.length() % TAB_SIZE != 0) l.append(' '); } else l.append(kar); } line = l.toString(); // Html characters // This will handle spaces / word wrapping as well line = Html.escapeHtml(line); sb.append(line); sb.append("<br>"); } // Closing quotes for (int i = 0; i < level; i++) sb.append("</blockquote>"); return sb.toString(); }
Example 9
Source File: ad.java From MiBandDecompiled with Apache License 2.0 | 4 votes |
public static String a(CharSequence charsequence) { return Html.escapeHtml(charsequence); }
Example 10
Source File: ShareCompatJB.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public static String escapeHtml(CharSequence html) { return Html.escapeHtml(html); }
Example 11
Source File: JsonUtils.java From MongoExplorer with MIT License | 4 votes |
private static String formatObjectString(String value) { return "<font color=\"#004488\">\"" + Html.escapeHtml(value) + "\"</font>"; }
Example 12
Source File: ShareCompatJB.java From adt-leanback-support with Apache License 2.0 | 4 votes |
public static String escapeHtml(CharSequence html) { return Html.escapeHtml(html); }
Example 13
Source File: ShareCompatJB.java From V.FlyoutTest with MIT License | 4 votes |
public static String escapeHtml(CharSequence html) { return Html.escapeHtml(html); }
Example 14
Source File: ShareCompatJB.java From guideshow with MIT License | 4 votes |
public static String escapeHtml(CharSequence html) { return Html.escapeHtml(html); }
Example 15
Source File: NetUtils.java From Qiitanium with MIT License | 4 votes |
public static String escapeHtml(CharSequence text) { return Html.escapeHtml(text); }