List of usage examples for android.text TextUtils htmlEncode
public static String htmlEncode(String s)
From source file:Main.java
public static String encodeHtml(String to_encode) { return TextUtils.htmlEncode(to_encode); }
From source file:Main.java
@NonNull public static String htmlEncode(@NonNull String s) { return TextUtils.htmlEncode(s); }
From source file:com.microsoft.activitytracker.Classes.Utils.java
/** * * @param fetchBody the fetch xml you want to include in this network call * @return the xml string that is used as the body for network calls to CRM *///from w ww . ja va 2 s . c o m public static String getRequestBodyforFetchXML(String fetchBody) { return String.format("<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>" + "<s:Body>" + "<RetrieveMultiple xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>" + "<query i:type='a:FetchExpression' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'>" + "<a:Query>%s</a:Query>" + "</query>" + "</RetrieveMultiple>" + "</s:Body>" + "</s:Envelope>", TextUtils.htmlEncode(fetchBody)); }
From source file:info.zamojski.soft.towercollector.parsers.changelog.ChangelogFeedParser.java
public ChangelogInfo parse(String content) throws ChangelogFeedParseException { try {//from w w w . jav a 2 s . c om 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) { Log.w("parse(): Error while parsing JSON content"); throw new ChangelogFeedParseException( "Cannot parse changelog feed: `" + TextUtils.htmlEncode(content) + "`", ex); } }
From source file:info.zamojski.soft.towercollector.parsers.update.UpdateFeedParser.java
public UpdateInfo parse(String content) throws UpdateFeedParseException { try {//ww w .j a v a2s . c o m 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) { Log.w("parse(): Error while parsing JSON response"); throw new UpdateFeedParseException("Cannot parse update feed: `" + TextUtils.htmlEncode(content) + "`", ex); } }
From source file:com.waz.zclient.pages.main.profile.preferences.dialogs.VerifyEmailPreferenceFragment.java
@Nullable @Override/*from w w w . ja v a 2s . com*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final String email = TextUtils.htmlEncode(getArguments().getString(ARG_EMAIL, "")); final View view = inflater.inflate(R.layout.fragment_preference_email_verification, container, false); final View backButton = ViewUtils.getView(view, R.id.tv__back_button); backButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dismiss(); } }); final TextView changeNumberButton = ViewUtils.getView(view, R.id.tv__change_email_button); changeNumberButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getContainer() == null) { return; } dismiss(); getContainer().changeEmail(email); } }); final TextView resendButton = ViewUtils.getView(view, R.id.tv__resend_button); resendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getStoreFactory() == null || getStoreFactory().isTornDown()) { return; } getStoreFactory().getProfileStore().resendVerificationEmail(email); } }); final String resendHtml = getString(R.string.pref__account_action__email_verification__resend, email); resendButton.setText(Html.fromHtml(resendHtml)); return view; }
From source file:com.android.emailcommon.internet.Rfc822Output.java
/** * Returns an HTML encoded message alternate *///from w w w . j av a2 s .c o m /*package*/ static String getHtmlAlternate(Body body, boolean useSmartReply) { if (body.mHtmlReply == null) { return null; } StringBuffer altMessage = new StringBuffer(); String htmlContent = TextUtils.htmlEncode(body.mTextContent); // Escape HTML reserved chars htmlContent = NEWLINE_PATTERN.matcher(htmlContent).replaceAll(NEWLINE_HTML); altMessage.append(htmlContent); if (body.mIntroText != null) { String htmlIntro = TextUtils.htmlEncode(body.mIntroText); htmlIntro = NEWLINE_PATTERN.matcher(htmlIntro).replaceAll(NEWLINE_HTML); altMessage.append(htmlIntro); } if (!useSmartReply) { String htmlBody = getHtmlBody(body.mHtmlReply); altMessage.append(htmlBody); } return altMessage.toString(); }
From source file:net.idlesoft.android.apps.github.activities.CommitChangeViewer.java
@Override public void onCreate(final Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.commit_view); mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0); mEditor = mPrefs.edit();/*from ww w .j a v a2 s.co m*/ mUsername = mPrefs.getString("username", ""); mPassword = mPrefs.getString("password", ""); mGapi.authenticate(mUsername, mPassword); ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() { public void onClick(final View v) { startActivity(new Intent(CommitChangeViewer.this, Search.class)); } }); final TextView title = (TextView) findViewById(R.id.tv_page_title); title.setText("Commit Diff"); final Bundle extras = getIntent().getExtras(); if (extras != null) { mRepositoryName = extras.getString("repo_name"); mRepositoryOwner = extras.getString("repo_owner"); try { mJson = new JSONObject(extras.getString("json")); /* * This new method of displaying file diffs was inspired by * iOctocat's approach. Thanks to Dennis Bloete (dbloete on * GitHub) for creating iOctocat and making me realize Android * needed some GitHub love too. ;-) */ final WebView webView = (WebView) findViewById(R.id.wv_commitView_diff); /* * Prepare CSS for diff: Added lines are green, removed lines * are red, and the special lines that specify how many lines * were affected in the chunk are a light blue. */ String content = "<style type=\"text/css\">" + "div {" + "margin-right: 100%25;" + "font-family: monospace;" + "white-space: nowrap;" + "display: inline-block;" + "}" + ".lines {" + "background-color: #EAF2F5;" + "}" + ".added {" + "background-color: #DDFFDD;" + "}" + ".removed {" + "background-color: #FFDDDD;" + "}" + "</style>"; final String[] splitDiff = mJson.getString("diff").split("\n"); for (int i = 0; i < splitDiff.length; i++) { // HTML encode any elements, else any diff containing // "<div>" or any HTML element will be interpreted as one by // the browser splitDiff[i] = TextUtils.htmlEncode(splitDiff[i]); // Replace all tabs with four non-breaking spaces (most // browsers truncate "\t+" to " "). splitDiff[i] = splitDiff[i].replaceAll("\t", " "); // Replace any sequence of two or more spaces with  s // (most browsers truncate " +" to " "). splitDiff[i] = splitDiff[i].replaceAll("(?<= ) ", " "); if (splitDiff[i].startsWith("@@")) { splitDiff[i] = "<div class=\"lines\">".concat(splitDiff[i].concat("</div>")); } else if (splitDiff[i].startsWith("+")) { splitDiff[i] = "<div class=\"added\">".concat(splitDiff[i].concat("</div>")); } else if (splitDiff[i].startsWith("-")) { splitDiff[i] = "<div class=\"removed\">".concat(splitDiff[i].concat("</div>")); } else { // Add an extra space before lines not beginning with // "+" or "-" to make them line up properly if (splitDiff[i].length() > 0) { splitDiff[i] = "<div> ".concat(splitDiff[i].substring(1).concat("</div>")); } } content += splitDiff[i]; } webView.loadData(content, "text/html", "UTF-8"); } catch (final JSONException e) { e.printStackTrace(); } } }
From source file:com.pixate.freestyle.viewdemo.ViewDetailFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override/* www.j a v a 2 s. co m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_view_detail, container, false); if (mItem != null) { // set the views ViewSample viewSample = mItem.getViewSample(); final ViewGroup viewsHolder = (ViewGroup) rootView.findViewById(R.id.holder); viewSample.createViews(getActivity(), viewsHolder); // load the CSS styling for the sample String css = ViewsData.getCSS(getActivity(), mItem); // Set up syntax highlighting WebView cssView = (WebView) rootView.findViewById(R.id.css_style); WebSettings s = cssView.getSettings(); s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); s.setUseWideViewPort(false); s.setAllowFileAccess(true); s.setBuiltInZoomControls(true); s.setSupportZoom(true); s.setSupportMultipleWindows(false); s.setJavaScriptEnabled(true); StringBuilder contentString = new StringBuilder(); contentString.append("<html><head>"); contentString.append( "<link href='file:///android_asset/prettify/prettify.css' rel='stylesheet' type='text/css'/> "); contentString.append( "<script src='file:///android_asset/prettify/prettify.js' type='text/javascript'></script> "); contentString.append( "<script src='file:///android_asset/prettify/lang-css.js' type='text/javascript'></script> "); contentString.append("</head><body onload='prettyPrint()'><code class='prettyprint lang-css'>"); contentString.append(TextUtils.htmlEncode(css).replaceAll("\n", "<br>").replaceAll(" ", " ") .replaceAll("\t", " ")); contentString.append("</code> </html> "); cssView.getSettings().setUseWideViewPort(true); cssView.loadDataWithBaseURL("file:///android_asset/prettify/", contentString.toString(), "text/html", StringUtil.EMPTY, StringUtil.EMPTY); // to aid in styling the css text shows in the textview, set its // ID. Eventually will not be needed. if (!"css-style".equals(PixateFreestyle.getStyleId(cssView))) { PixateFreestyle.setStyleId(cssView, "css-style", true); } // Style viewSample.style(css); } return rootView; }
From source file:microsoft.aspnet.signalr.client.test.integration.android.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_settings: startActivity(new Intent(this, SignalRPreferenceActivity.class)); return true; case R.id.menu_run_tests: if (ApplicationContext.getServerUrl().trim().equals("")) { startActivity(new Intent(this, SignalRPreferenceActivity.class)); } else {//w w w . j a v a 2s. c om runTests(); } return true; case R.id.menu_check_all: changeCheckAllTests(true); return true; case R.id.menu_uncheck_all: changeCheckAllTests(false); return true; case R.id.menu_reset: refreshTestGroupsAndLog(); return true; case R.id.menu_view_log: AlertDialog.Builder logDialogBuilder = new AlertDialog.Builder(this); logDialogBuilder.setTitle("Log"); final WebView webView = new WebView(this); String logContent = TextUtils.htmlEncode(mLog.toString()).replace("\n", "<br />"); String logHtml = "<html><body><pre>" + logContent + "</pre></body></html>"; webView.loadData(logHtml, "text/html", "utf-8"); logDialogBuilder.setPositiveButton("Copy", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboardManager.setText(mLog.toString()); } }); final String postContent = mLog.toString(); logDialogBuilder.setNeutralButton("Post data", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { String url = ApplicationContext.getLogPostURL(); if (url != null && url.trim() != "") { url = url + "?platform=android"; HttpPost post = new HttpPost(); post.setEntity(new StringEntity(postContent, "utf-8")); post.setURI(new URI(url)); new DefaultHttpClient().execute(post); } } catch (Exception e) { // Wasn't able to post the data. Do nothing } return null; } }.execute(); } }); logDialogBuilder.setView(webView); logDialogBuilder.create().show(); return true; default: return super.onOptionsItemSelected(item); } }