List of usage examples for android.text TextUtils htmlEncode
public static String htmlEncode(String s)
From source file:com.microsoft.windowsazure.messaging.e2etestapp.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_settings: startActivity(new Intent(this, NotificationHubsPreferenceActivity.class)); return true; case R.id.menu_run_tests: if (ApplicationContext.getNotificationHubEndpoint().trim().equals("") || ApplicationContext.getNotificationHubKeyName().trim().equals("") || ApplicationContext.getNotificationHubKeyValue().trim().equals("") || ApplicationContext.getNotificationHubName().trim().equals("")) { startActivity(new Intent(this, NotificationHubsPreferenceActivity.class)); } else {/*from w w w.ja va 2 s . 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); } }
From source file:com.irccloud.android.GCMIntentService.java
@Override protected void onHandleIntent(Intent intent) { if (intent != null) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); if (extras != null && !extras.isEmpty()) { if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //Log.d("IRCCloud", "Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //Log.d("IRCCloud", "Deleted messages on server: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { if (!IRCCloudApplication.getInstance().getApplicationContext().getSharedPreferences("prefs", 0) .getBoolean("gcm_registered", false)) { String regId = IRCCloudApplication.getInstance().getApplicationContext() .getSharedPreferences("prefs", 0).getString("gcm_reg_id", ""); if (regId.length() > 0) { scheduleUnregisterTimer(100, regId, false); }//from w ww.j a v a 2s .c o m } else { //Log.d("IRCCloud", "GCM K/V pairs: " + intent.getExtras().toString()); try { String type = intent.getStringExtra("type"); if (type.equalsIgnoreCase("heartbeat_echo")) { NetworkConnection conn = NetworkConnection.getInstance(); ObjectMapper mapper = new ObjectMapper(); JsonParser parser = mapper.getFactory() .createParser(intent.getStringExtra("seenEids")); JsonNode seenEids = mapper.readTree(parser); Iterator<Map.Entry<String, JsonNode>> iterator = seenEids.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); JsonNode eids = entry.getValue(); Iterator<Map.Entry<String, JsonNode>> j = eids.fields(); while (j.hasNext()) { Map.Entry<String, JsonNode> eidentry = j.next(); String bid = eidentry.getKey(); long eid = eidentry.getValue().asLong(); if (conn.ready && conn.getState() != NetworkConnection.STATE_CONNECTED) BuffersDataSource.getInstance().updateLastSeenEid(Integer.valueOf(bid), eid); Notifications.getInstance().deleteOldNotifications(Integer.valueOf(bid), eid); Notifications.getInstance().updateLastSeenEid(Integer.valueOf(bid), eid); } } parser.close(); } else { int cid = Integer.valueOf(intent.getStringExtra("cid")); int bid = Integer.valueOf(intent.getStringExtra("bid")); long eid = Long.valueOf(intent.getStringExtra("eid")); if (Notifications.getInstance().getNotification(eid) != null) { Log.e("IRCCloud", "GCM got EID that already exists"); return; } String from = intent.getStringExtra("from_nick"); String msg = intent.getStringExtra("msg"); if (msg != null) msg = ColorFormatter .html_to_spanned(ColorFormatter.irc_to_html(TextUtils.htmlEncode(msg))) .toString(); String chan = intent.getStringExtra("chan"); if (chan == null) chan = ""; String buffer_type = intent.getStringExtra("buffer_type"); String server_name = intent.getStringExtra("server_name"); if (server_name == null || server_name.length() == 0) server_name = intent.getStringExtra("server_hostname"); String network = Notifications.getInstance().getNetwork(cid); if (network == null) Notifications.getInstance().addNetwork(cid, server_name); Notifications.getInstance().addNotification(cid, bid, eid, from, msg, chan, buffer_type, type); if (from == null || from.length() == 0) Notifications.getInstance().showNotifications(server_name + ": " + msg); else if (buffer_type.equals("channel")) { if (type.equals("buffer_me_msg")) Notifications.getInstance() .showNotifications(chan + ": " + from + " " + msg); else Notifications.getInstance() .showNotifications(chan + ": <" + from + "> " + msg); } else { if (type.equals("buffer_me_msg")) Notifications.getInstance().showNotifications(" " + from + " " + msg); else Notifications.getInstance().showNotifications(from + ": " + msg); } } } catch (Exception e) { e.printStackTrace(); Log.w("IRCCloud", "Unable to parse GCM message"); } } } } GCMBroadcastReceiver.completeWakefulIntent(intent); } }
From source file:org.akop.crosswords.activity.CrosswordActivity.java
private CharSequence getHintText(Crossword.Word word, Crossword crossword, boolean linkReferences) { String hint = word.getHint(); if (linkReferences) { List<ReferenceScanner.WordReference> refs = ReferenceScanner.findReferences(word, crossword); if (refs.size() > 0) { StringBuilder sb = new StringBuilder(); int start = 0; for (ReferenceScanner.WordReference ref : refs) { int refStart = ref.getStart(); int refEnd = ref.getEnd(); sb.append(hint, start, refStart); sb.append("<a href=\""); sb.append(WordReferenceMovementMethod.createReferenceLink(ref)); sb.append("\">"); sb.append(TextUtils.htmlEncode(hint.substring(refStart, refEnd))); sb.append("</a>"); start = refEnd;// ww w. j av a 2 s .c o m } sb.append(hint, start, hint.length()); hint = sb.toString(); } } String directionLabel = ""; if (word.getDirection() == Crossword.Word.DIR_ACROSS) { directionLabel = getString(R.string.across); } else if (word.getDirection() == Crossword.Word.DIR_DOWN) { directionLabel = getString(R.string.down); } return Html.fromHtml(getString(R.string.hint_format_f, word.getNumber(), directionLabel, hint)); }
From source file:de.dreier.mytargets.features.scoreboard.HtmlUtils.java
private static String getComments(List<Round> rounds) { String comments = "<table class=\"myTable\" style=\"margin-top:5px;\"><tr class=\"align_center\">" + "<th>" + get(R.string.round) + "</th>" + "<th>" + get(R.string.passe) + "</th>" + "<th>" + get(R.string.points) + "</th>" + "<th>" + get(R.string.comment) + "</th></tr>"; int commentsCount = 0; int j = 0;//from w ww.j a v a 2 s . c o m for (Round round : rounds) { int i = 1; List<End> ends = round.getEnds(); for (End end : ends) { for (int s = 0; s < end.getShots().size(); s++) { Shot shot = end.getShots().get(s); if (!TextUtils.isEmpty(shot.comment)) { comments += "<tr class=\"align_center\"><td>" + j + "</td>" + "<td>" + i + "</td>" + "<td>" + round.getTarget().zoneToString(shot.scoringRing, s) + "</td>" + "<td>" + TextUtils.htmlEncode(shot.comment).replace("\n", "<br />") + "</td></tr>"; commentsCount++; } } i++; } j++; } // If a minimum of one comment is present show comments table String html = ""; if (commentsCount > 0) { html = comments + "</table>"; } return html; }
From source file:com.akhbulatov.wordkeeper.ui.fragment.CategoryListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragment_category, menu); MenuItem searchItem = menu.findItem(R.id.menu_search_category); SearchView searchView = (SearchView) searchItem.getActionView(); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(/*from www. j av a 2 s. com*/ searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class))); searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { final Cursor cursor = mCategoryDbAdapter.getAll(); final int column = cursor.getColumnIndex(CategoryEntry.COLUMN_NAME); if (newText.length() > 0) { mCategoryAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column)); if (mCategoryAdapter.getItemCount() == 0) { String escapedNewText = TextUtils.htmlEncode(newText); String formattedNoResults = String.format(getString(R.string.no_results_category), escapedNewText); CharSequence styledNoResults = Html.fromHtml(formattedNoResults); mTextNoResultsCategory.setText(styledNoResults); mTextNoResultsCategory.setVisibility(View.VISIBLE); } else { mTextNoResultsCategory.setVisibility(View.GONE); } } else { mCategoryAdapter.swapCursor(cursor); mTextNoResultsCategory.setVisibility(View.GONE); } return true; } @Override public boolean onQueryTextSubmit(String query) { return false; } }); }
From source file:com.akhbulatov.wordkeeper.ui.fragment.WordListFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.fragment_word, menu); MenuItem searchItem = menu.findItem(R.id.menu_search_word); SearchView searchView = (SearchView) searchItem.getActionView(); SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); searchView.setSearchableInfo(/*ww w .j a va 2 s. co m*/ searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class))); searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; } @Override public boolean onQueryTextChange(String newText) { final Cursor cursor = mWordDbAdapter.getAll(sSortMode); final int column = cursor.getColumnIndex(WordEntry.COLUMN_NAME); if (newText.length() > 0) { mWordAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column)); mTextEmptyWordList.setVisibility(View.GONE); if (mWordAdapter.getItemCount() == 0) { String escapedNewText = TextUtils.htmlEncode(newText); String formattedNoResults = String.format(getString(R.string.no_results_word), escapedNewText); CharSequence styledNoResults = Html.fromHtml(formattedNoResults); mTextNoResultsWord.setText(styledNoResults); mTextNoResultsWord.setVisibility(View.VISIBLE); } else { mTextNoResultsWord.setVisibility(View.GONE); } } else { mWordAdapter.swapCursor(cursor); mTextNoResultsWord.setVisibility(View.GONE); if (mWordAdapter.getItemCount() == 0) { mTextEmptyWordList.setVisibility(View.VISIBLE); } } return true; } }); }
From source file:com.gh4a.activities.DiffViewerActivity.java
protected void showDiff() { StringBuilder content = new StringBuilder(); boolean authorized = Gh4Application.get().isAuthorized(); content.append("<html><head><title></title>"); writeCssInclude(content, "text"); writeScriptInclude(content, "codeutils"); content.append("</head><body"); if (mInitialLine > 0) { content.append(" onload='scrollToElement(\"line"); content.append(mInitialLine).append("\")' onresize='scrollToHighlight();'"); }/*w ww . j a v a 2 s .c om*/ content.append("><pre>"); String encoded = TextUtils.htmlEncode(mDiff); mDiffLines = encoded.split("\n"); for (int i = 0; i < mDiffLines.length; i++) { String line = mDiffLines[i]; String cssClass = null; if (line.startsWith("@@")) { cssClass = "change"; } else if (line.startsWith("+")) { cssClass = "add"; } else if (line.startsWith("-")) { cssClass = "remove"; } content.append("<div id=\"line").append(i).append("\""); if (cssClass != null) { content.append("class=\"").append(cssClass).append("\""); } if (authorized) { content.append(" onclick=\"javascript:location.href='comment://add"); content.append("?position=").append(i).append("'\""); } content.append(">").append(line).append("</div>"); List<CommitComment> comments = mCommitCommentsByPos.get(i); if (comments != null) { for (CommitComment comment : comments) { mCommitComments.put(comment.getId(), comment); content.append("<div class=\"comment\""); if (authorized) { content.append(" onclick=\"javascript:location.href='comment://edit"); content.append("?position=").append(i); content.append("&id=").append(comment.getId()).append("'\""); } content.append("><div class=\"change\">"); content.append(getString(R.string.commit_comment_header, "<b>" + ApiHelpers.getUserLogin(this, comment.getUser()) + "</b>", StringUtils.formatRelativeTime(DiffViewerActivity.this, comment.getCreatedAt(), true))); content.append("</div>").append(comment.getBodyHtml()).append("</div>"); } } } content.append("</pre></body></html>"); loadThemedHtml(content.toString()); }
From source file:org.adblockplus.android.Preferences.java
private void showNotificationDialog(final String title, String message, String url) { url = TextUtils.htmlEncode(url); message = TextUtils.htmlEncode(message).replaceAll("<a>(.*?)</a>", "<a href=\"" + url + "\">$1</a>"); final TextView messageView = new TextView(this); messageView.setText(Html.fromHtml(message)); messageView.setMovementMethod(LinkMovementMethod.getInstance()); final int padding = 10; messageView.setPadding(padding, padding, padding, padding); new AlertDialog.Builder(this).setTitle(title).setView(messageView) .setIcon(android.R.drawable.ic_dialog_info).setPositiveButton(R.string.ok, null).create().show(); }
From source file:com.irccloud.android.fragment.WhoisFragment.java
public void onResume() { super.onResume(); if (event != null) { String nick = event.getString("user_nick"); String extratxt = ""; if (event.has("op_nick")) { extratxt += nick + " " + event.getString("op_msg") + "\n\n"; }/*from w w w. j a v a2s . c o m*/ if (event.has("opername")) { extratxt += nick + " " + event.getString("opername_msg") + " " + event.getString("opername") + "\n\n"; } if (event.has("stats_dline")) { extratxt += nick + " " + event.getString("stats_dline") + "\n\n"; } if (event.has("userip")) { extratxt += nick + " " + event.getString("userip") + "\n\n"; } if (event.has("host")) { extratxt += nick + " " + event.getString("host") + "\n\n"; } if (event.has("bot_msg")) { extratxt += nick + " " + event.getString("bot_msg") + "\n\n"; } if (event.has("cgi")) { extratxt += nick + " " + event.getString("cgi") + "\n\n"; } if (event.has("help")) { extratxt += nick + " " + event.getString("help") + "\n\n"; } if (event.has("vworld")) { extratxt += nick + " " + event.getString("vworld") + "\n\n"; } if (event.has("modes")) { extratxt += nick + " " + event.getString("modes") + "\n\n"; } if (event.has("client_cert")) { extratxt += nick + " " + event.getString("client_cert") + "\n\n"; } if (event.has("secure")) { extratxt += nick + " " + event.getString("secure") + "\n\n"; } if (extratxt.length() > 0) { extra.setVisibility(View.VISIBLE); extra.setText(extratxt.substring(0, extratxt.length() - 2)); } else { extra.setVisibility(View.GONE); } if (event.has("user_realname")) { String nametxt = event.getString("user_realname"); if (event.has("user_logged_in_as") && event.getString("user_logged_in_as").length() > 0) { nametxt += "\u000F (authed as " + event.getString("user_logged_in_as") + ")"; } name.setText(ColorFormatter.html_to_spanned( ColorFormatter.emojify(ColorFormatter.irc_to_html(TextUtils.htmlEncode(nametxt))))); } else { name.setText(""); } mask.setText(ColorFormatter.html_to_spanned( ColorFormatter.irc_to_html(TextUtils.htmlEncode(event.getString("user_username"))) + "@" + ColorFormatter.irc_to_html(TextUtils.htmlEncode(event.getString("user_host"))))); if (event.has("actual_host")) mask.setText(mask.getText() + "/" + event.getString("actual_host")); String s = event.getString("server_addr"); if (event.has("server_extra") && event.getString("server_extra").length() > 0) s += " (" + event.getString("server_extra") + ")"; server.setText(s); if (event.has("signon_time")) { String timetxt = format_duration( (System.currentTimeMillis() / 1000L) - event.getLong("signon_time")); if (event.has("idle_secs") && event.getLong("idle_secs") > 0) timetxt += " (idle for " + format_duration(event.getLong("idle_secs")) + ")"; time.setText(timetxt); timeTitle.setVisibility(View.VISIBLE); time.setVisibility(View.VISIBLE); } else { timeTitle.setVisibility(View.GONE); time.setVisibility(View.GONE); } if (event.has("away") && event.getString("away").length() > 0) { away.setText(ColorFormatter.html_to_spanned(ColorFormatter .emojify(ColorFormatter.irc_to_html(TextUtils.htmlEncode(event.getString("away")))))); awayTitle.setVisibility(View.VISIBLE); away.setVisibility(View.VISIBLE); } else { awayTitle.setVisibility(View.GONE); away.setVisibility(View.GONE); } buildChannelList("channels_oper", operTitle, operChannels); buildChannelList("channels_owner", ownerTitle, ownerChannels); buildChannelList("channels_admin", adminTitle, adminChannels); buildChannelList("channels_op", opTitle, opChannels); buildChannelList("channels_halfop", halfopTitle, halfopChannels); buildChannelList("channels_voiced", voicedTitle, voicedChannels); buildChannelList("channels_member", channelsTitle, channels); } }
From source file:com.irccloud.android.data.collection.NotificationsList.java
public synchronized void addNotification(int cid, int bid, long eid, String from, String message, String chan, String buffer_type, String message_type, String network) { long last_eid = getLastSeenEid(bid); if (eid <= last_eid) { Crashlytics.log("Refusing to add notification for seen eid: " + eid); return;/*from w w w . j a va2 s . c om*/ } Notification n = new Notification(); n.bid = bid; n.cid = cid; n.eid = eid; n.nick = from; n.message = TextUtils.htmlEncode(ColorFormatter.strip(message).toString()); n.chan = chan; n.buffer_type = buffer_type; n.message_type = message_type; n.network = network; synchronized (dbLock) { n.save(); } if (notificationAddedListener != null) notificationAddedListener.onNotificationAdded(n); }