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

The following are Jave code examples for showing how to use htmlEncode() of the android.text.TextUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: q-mail   File: HtmlConverter.java   View Source Code Vote up 5 votes
/**
 * Naively convert a text string into an HTML document.
 *
 * <p>
 * This method avoids using regular expressions on the entire message body to save memory.
 * </p>
 * <p>
 * No HTML headers or footers are added to the result.  Headers and footers
 * are added at display time in
 * {@link com.fsck.k9.view#MessageWebView.setText(String) MessageWebView.setText()}
 * </p>
 *
 * @param text
 *         Plain text string.
 * @return HTML string.
 */
private static String simpleTextToHtml(String text) {
    // Encode HTML entities to make sure we don't display something evil.
    text = TextUtils.htmlEncode(text);

    StringBuilder buff = new StringBuilder(text.length() + TEXT_TO_HTML_EXTRA_BUFFER_LENGTH);

    buff.append(htmlifyMessageHeader());

    for (int index = 0; index < text.length(); index++) {
        char c = text.charAt(index);
        switch (c) {
        case '\n':
            // pine treats <br> as two newlines, but <br/> as one newline.  Use <br/> so our messages aren't
            // doublespaced.
            buff.append("<br />");
            break;
        case '\r':
            break;
        default:
            buff.append(c);
        }//switch
    }

    buff.append(htmlifyMessageFooter());

    return buff.toString();
}
 
Example 2
Project: q-mail   File: HtmlConverter.java   View Source Code Vote up 5 votes
/**
 * Convert a plain text string into an HTML fragment.
 * @param text Plain text.
 * @return HTML fragment.
 */
public static String textToHtmlFragment(final String text) {
    // Escape the entities and add newlines.
    String htmlified = TextUtils.htmlEncode(text);

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

    // Add newlines and unescaping.
    //
    // 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.
    return linkified.toString().replaceAll("\r?\n", "<br>\r\n").replace("&apos;", "&#39;");
}
 
Example 3
Project: thermalprinterhelper   File: UtilsHtml.java   View Source Code Vote up 5 votes
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("&amp;","&");
        result = result.replace("&","{AND}");
        result = TextUtils.htmlEncode(result);
        result = result.replace("{AND}","&");
        return result;
    }
 
Example 4
Project: boohee_v5.6   File: TextUtilsCompatJellybeanMr1.java   View Source Code Vote up 4 votes
@NonNull
public static String htmlEncode(@NonNull String s) {
    return TextUtils.htmlEncode(s);
}
 
Example 5
Project: SmartMath   File: ActivitySmartCalc.java   View Source Code Vote up 4 votes
public void setRecognizedInput(String strRecogResult, String strRecogErr) {
	EditText txtInput = (EditText)findViewById(R.id.edtSmartMathInput);
	// if strRecogResult is null, we do not change input text.
   	if (strRecogResult != null)	{
		txtInput.setText(strRecogResult);	// clear input and set text.
   	} else {
   		txtInput.setText("");
   	}

       String strConfirm = "<p>" + getString(R.string.please_confirm_recognized_result_and_calculation_result)
			+ "<a href=\"" + AOPER_URL_HEADER + EMAIL_UNSATISFACTORY_RECOG + "\">"
			+ getString(R.string.here) + "</a>" + getString(R.string.stop_charater) + "</p>";
       String strRecogExprsOutput = "";
       if (strRecogErr == null || strRecogErr.length() == 0) {
       	if (strRecogResult == null || strRecogResult.length() == 0) {
       		// output is empty
       		strRecogExprsOutput = "<p>" + getString(R.string.no_valid_expr_recognized) + "</p>\n";
       	} else {
       		// output is not empty
               strRecogExprsOutput = "<p>" + getString(R.string.recognized_result) + "</p>"; 
       		String[] strarrayExprs = txtInput.getText().toString().split("\n");
       		String strRecognizedExprColor = "color:#008000;", strInvalidExprColor = "color:#800000;";
       		for (int idx = 0; idx < strarrayExprs.length; idx ++)	{
       			/* show the expression(s) */
       			CurPos curpos = new CurPos();
       			curpos.m_nPos = 0;
       			AbstractExpr aexpr = new AEInvalid();
                   try {
       				aexpr = ExprAnalyzer.analyseExpression(strarrayExprs[idx], curpos);
       				strRecogExprsOutput += "<p><a href=\"" + AbstractExprConverter.convtPlainStr2QuotedUrl(strarrayExprs[idx])
       							+ "\" style=\"text-decoration: none;" + strRecognizedExprColor + "\">$"
       							+ AbstractExprConverter.convtAExpr2JQMath(aexpr) + "$</a></p>\n";
                   } catch (Exception e)	{
       				strRecogExprsOutput += "<p><a href=\"" + AbstractExprConverter.convtPlainStr2QuotedUrl(strarrayExprs[idx])
       						+ "\" style=\"text-decoration: none;" + strInvalidExprColor + "\">$"
       						+ AbstractExprConverter.convtPlainStr2JQMathNoException(strarrayExprs[idx]) + "$</a></p>\n";
       				strRecogExprsOutput += "<p>&nbsp;<big>&rArr;</big>&nbsp" + getString(R.string.invalid_expr_to_analyse) + " ";
       				strRecogExprsOutput += getString(R.string.please_modify_the_input_expression) + "</p><p>"
       						+ TextUtils.htmlEncode(strarrayExprs[idx]) + "</p>\n"; 
                   }
       		}
       	}
       } else {
       	// recognition error.
       	strRecogExprsOutput = "<p>" + strRecogErr + "</p>\n";
       }
	mstrarrayTaskAndOutput[0] = "recognize";
	mstrarrayTaskAndOutput[1] = strRecogExprsOutput;	// save it to mstrOutput so that it can be reloaded after rotation.
	mshistoricalRecMgr.addRecord(strRecogResult, mstrarrayTaskAndOutput[0], mstrarrayTaskAndOutput[1], "", ActivitySettings.msnNumberofRecords);
	WebView wvOutput = (WebView) findViewById(R.id.webviewSmartMathOutput);
	wvOutput.loadDataWithBaseURL("file:///android_asset/mathscribe/index.html",
				OUTPUT_HEAD_STRING + mstrFontSize + OUTPUT_SIZE_UNIT_STRING + strConfirm + strRecogExprsOutput + OUTPUT_TAIL_STRING,
				"text/html", "utf-8", "");
	
      	// hide the soft keyboard and inputpad so that recognizing result can be shown.   		
	if (mnSoftKeyState == ENABLE_SHOW_SOFTKEY)	{
           setSoftKeyState(txtInput, ENABLE_HIDE_SOFTKEY);
	} else if (mnSoftKeyState == ENABLE_SHOW_INPUTPAD)	{
           setSoftKeyState(txtInput, ENABLE_HIDE_INPUTPAD);
	}
}