Java Code Examples for android.text.TextUtils#htmlEncode()

The following examples show how to use android.text.TextUtils#htmlEncode() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
public UpdateInfo parse(String content) throws UpdateFeedParseException {
    try {
        if (!StringUtils.mayBeJson(content))
            return null;
        JSONObject json = new JSONObject(content);
        int versionCode = getVersionCode(json);
        String versionName = getVersionName(json);
        DownloadLink[] downloadLinks = getDownloadLinks(json);
        UpdateInfo updateInfo = new UpdateInfo(versionCode, versionName);
        updateInfo.addDownloadLinks(downloadLinks);
        return updateInfo;
    } catch (JSONException ex) {
        Timber.w("parse(): Error while parsing JSON response");
        throw new UpdateFeedParseException("Cannot parse update feed: `" + TextUtils.htmlEncode(content) + "`", ex);
    }
}
 
Example 2
Source Project: thermalprinterhelper   File: UtilsHtml.java    License: Apache License 2.0 5 votes vote down vote up
public static String HtmlDecode(String oldStr){

        if(oldStr == null || oldStr.isEmpty()) return "";

        String result = oldStr;

        result = result.replace("#015;","");
        result = result.replace("#012;","");
        result = result.replace("&","&");
        result = result.replace("&","{AND}");
        result = TextUtils.htmlEncode(result);
        result = result.replace("{AND}","&");
        return result;
    }
 
Example 3
Source Project: memoir   File: ConverterTextToHtml.java    License: Apache License 2.0 5 votes vote down vote up
public static String convert(String text) {
    // Escape the entities and add newlines.
    String htmlified = text == null ? "" : TextUtils.htmlEncode(text);

    // Linkify the message.
    StringBuffer linkified = new StringBuffer(htmlified.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);
    linkifyText(htmlified, linkified);

    // For some reason, TextUtils.htmlEncode escapes ' into ', which is technically part of the XHTML 1.0
    // standard, but Gmail doesn't recognize it as an HTML entity. We unescape that here.
    String result = linkified.toString().replace("\n", "<br>\n").replace("&apos;", "&#39;");
    return result;
}
 
Example 4
Source Project: memoir   File: ConverterTextToHtml.java    License: Apache License 2.0 5 votes vote down vote up
public static String convert(String text) {
    // Escape the entities and add newlines.
    String htmlified = text == null ? "" : TextUtils.htmlEncode(text);

    // Linkify the message.
    StringBuffer linkified = new StringBuffer(htmlified.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);
    linkifyText(htmlified, linkified);

    // For some reason, TextUtils.htmlEncode escapes ' into &apos;, which is technically part of the XHTML 1.0
    // standard, but Gmail doesn't recognize it as an HTML entity. We unescape that here.
    String result = linkified.toString().replace("\n", "<br>\n").replace("&apos;", "&#39;");
    return result;
}
 
Example 5
public ChangelogInfo parse(String content) throws ChangelogFeedParseException {
    try {
        if (!StringUtils.mayBeJson(content))
            return new ChangelogInfo();
        JSONObject json = new JSONObject(content);
        List<ChangelogEntry> entries = getEntries(json);
        ChangelogInfo changelog = new ChangelogInfo();
        changelog.addEntries(entries);
        return changelog;
    } catch (JSONException ex) {
        Timber.w("parse(): Error while parsing JSON content");
        throw new ChangelogFeedParseException("Cannot parse changelog feed: `" + TextUtils.htmlEncode(content) + "`", ex);
    }
}
 
Example 6
public static String convert(String text) {
    // Escape the entities and add newlines.
    String htmlified = text == null ? "" : TextUtils.htmlEncode(text);

    // Linkify the message.
    StringBuffer linkified = new StringBuffer(htmlified.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);
    linkifyText(htmlified, linkified);

    // For some reason, TextUtils.htmlEncode escapes ' into &apos;, which is technically part of the XHTML 1.0
    // standard, but Gmail doesn't recognize it as an HTML entity. We unescape that here.
    String result = linkified.toString().replace("\n", "<br>\n").replace("&apos;", "&#39;");
    return result;
}
 
Example 7
Source Project: ForPDA   File: ApiUtils.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static String htmlEncode(String s) {
    if (s == null) return null;
    return TextUtils.htmlEncode(s);
}
 
Example 8
Source Project: WeGit   File: CodeActivity.java    License: Apache License 2.0 4 votes vote down vote up
@JavascriptInterface
public String getCode() {
    return TextUtils.htmlEncode(content.replace("\t", "    "));
}
 
Example 9
Source Project: something.apk   File: ThreadPageRequest.java    License: MIT License 4 votes vote down vote up
public static ThreadPage processThreadPage(Document document, boolean showImages, boolean showAvatars, boolean hidePreviouslyReadImages, long jumpToPost, String redirectedUrl){
    ArrayList<HashMap<String, String>> posts = new ArrayList<HashMap<String, String>>();

    int currentPage, maxPage = 1, threadId, forumId, unread;
    String jumpToId = jumpToPost > 0 ? "#post"+jumpToPost : null;

    String ptiFragment = null;
    if(!TextUtils.isEmpty(redirectedUrl)){
        Uri url = Uri.parse(redirectedUrl);
        ptiFragment = url.getFragment();
        if("lastpost".matches(ptiFragment)){
            ptiFragment = null;
            jumpToId = "#lastpost";
        }
    }


    Element pages = document.getElementsByClass("pages").first();
    currentPage = FastUtils.safeParseInt(pages.getElementsByAttribute("selected").attr("value"), 1);
    Element lastPage = pages.getElementsByTag("option").last();
    if(lastPage != null){
        maxPage = FastUtils.safeParseInt(lastPage.attr("value"), 1);
    }

    boolean bookmarked = document.getElementsByClass("unbookmark").size() > 0;

    String threadTitle = TextUtils.htmlEncode(document.getElementsByClass("bclast").first().text());

    Element body = document.body();
    forumId = Integer.parseInt(body.attr("data-forum"));
    threadId = Integer.parseInt(body.attr("data-thread"));

    Elements threadbars = document.getElementsByClass("threadbar");
    boolean canReply = !Constants.isArchiveForum(forumId) && threadbars.first().getElementsByAttributeValueContaining("src", "images/forum-closed.gif").size() == 0;

    unread = parsePosts(document, posts, showImages, showAvatars, hidePreviouslyReadImages, ptiFragment, canReply, currentPage == maxPage, forumId);

    StringBuilder builder = new StringBuilder(2048);

    int previouslyRead = posts.size()-unread;

    HashMap<String, String> headerArgs = new HashMap<String, String>();
    headerArgs.put("jumpToPostId", jumpToId);
    headerArgs.put("fontSize", SomePreferences.fontSize);
    headerArgs.put("theme", getTheme(forumId));
    headerArgs.put("previouslyRead", previouslyRead > 0 && unread > 0 ? previouslyRead+" Previous Post"+(previouslyRead > 1 ? "s":"") : null);
    MustCache.applyHeaderTemplate(builder, headerArgs);

    for(HashMap<String, String> post : posts){
        MustCache.applyPostTemplate(builder, post);
    }

    MustCache.applyFooterTemplate(builder, null);

    ThreadItem cachedThread = ThreadManager.getThread(threadId);
    if(cachedThread != null){
        cachedThread.updateUnreadCount(currentPage, maxPage, SomePreferences.threadPostPerPage);
    }

    return new ThreadPage(builder.toString(), currentPage, maxPage, threadId, forumId, threadTitle, -unread, bookmarked, canReply);

}