List of usage examples for android.text Html escapeHtml
public static String escapeHtml(CharSequence text)
From source file:com.github.dfa.diaspora_android.web.WebHelper.java
public static String escapeHtmlText(String text) { text = Html.escapeHtml(text); text = text.replace("\n", " "); return text;//from www . j a v a 2s .c o m }
From source file:org.c99.wear_imessage.GCMIntentService.java
public static void notify(Context context, int notification_id, JSONArray msgs, Intent intent, boolean updateOnly) throws JSONException { String lastMsg = intent.getStringExtra("msg"); Spanned msg;//from w w w .j a va 2 s .com String name = intent.getStringExtra("name"); if (name.contains(" ")) name = name.substring(0, name.indexOf(" ")); StringBuilder sb = new StringBuilder(); for (int i = 0; i < msgs.length(); i++) { if (sb.length() > 0) sb.append("<br/><br/>"); String body; String from = name; try { JSONObject o = msgs.getJSONObject(i); body = o.getString("msg"); if (o.has("type")) { if (o.getString("type").equals("file") || o.getString("type").equals("sent_file")) body = "[File: " + o.getString("msg") + "]"; if (o.getString("type").equals("sent") || o.getString("type").equals("sent_file")) from = "Me"; else lastMsg = body; } else { from = name; lastMsg = body; } } catch (JSONException e1) { from = name; body = msgs.getString(i); lastMsg = body; } sb.append("<b>").append(Html.escapeHtml(from)).append(":</b> ").append(Html.escapeHtml(body)); } msg = Html.fromHtml(sb.toString()); int msg_count = msgs.length(); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setAutoCancel(true); if (name.length() > 0) { builder.setSmallIcon(R.drawable.ic_notification).setContentTitle(intent.getStringExtra("name")) .setContentText(lastMsg).setNumber(msg_count); } if (updateOnly) { builder.setVibrate(null); } else { builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setTicker(Html.fromHtml("<b>" + Html.escapeHtml(intent.getStringExtra("name")) + ":</b> " + Html.escapeHtml(intent.getStringExtra("msg")))).setDefaults(Notification.DEFAULT_ALL); } NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(); style.bigText(lastMsg); builder.setStyle(style); NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender(); if (ENABLE_REPLIES) { Intent replyIntent = new Intent(RemoteInputService.ACTION_REPLY); replyIntent .setComponent(new ComponentName(context.getPackageName(), RemoteInputService.class.getName())); replyIntent.putExtras(intent.getExtras()); replyIntent.putExtra("notification_id", notification_id); PendingIntent replyPendingIntent = PendingIntent.getService(context, notification_id + 1, replyIntent, PendingIntent.FLAG_CANCEL_CURRENT); extender.addAction( new NotificationCompat.Action.Builder(R.drawable.ic_reply, "Reply", replyPendingIntent) .addRemoteInput(new RemoteInput.Builder("extra_reply").setLabel("Reply").build()) .build()); Intent launchIntent = new Intent(context, QuickReplyActivity.class); launchIntent.putExtras(intent.getExtras()); launchIntent.putExtra("notification_id", notification_id); builder.setContentIntent(PendingIntent.getActivity(context, notification_id + 2, launchIntent, PendingIntent.FLAG_CANCEL_CURRENT)); builder.addAction(R.drawable.ic_action_reply, "Reply", PendingIntent.getActivity(context, notification_id + 3, launchIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT)); } if (msg_count > 1) extender.addPage(new NotificationCompat.Builder(context).setContentText(msg) .extend(new NotificationCompat.WearableExtender().setStartScrollBottom(true)).build()); Cursor c = null; if (intent.getStringExtra("handle").contains("@")) c = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data.CONTACT_ID }, ContactsContract.CommonDataKinds.Email.ADDRESS + "=?" + " AND " + ContactsContract.Data.MIMETYPE + "=?", new String[] { intent.getStringExtra("handle"), ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE }, null); if (c != null && c.moveToFirst()) { long contactId = c.getLong(0); c.close(); Bitmap b = BitmapFactory.decodeStream( ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId), true)); if (b != null) { builder.setLargeIcon(b); extender.setBackground(b); } } NotificationManagerCompat m = NotificationManagerCompat.from(context); m.notify(notification_id, builder.extend(extender).build()); }
From source file:com.amanmehara.programming.android.adapters.DetailAdapter.java
private String generateHtml(String content) { return "<html>" + "<link href='file:///android_asset/prism.css' rel='stylesheet'/>" + "<script src='file:///android_asset/prism.js'></script>" + "<body style='margin:0px; padding:0px;'>" + "<pre class='line-numbers'><code class='language-" + reverseMapLanguageName(languageName) + "'>" + Html.escapeHtml(content) + "</code></pre>" + "</body>" + "</html>"; }
From source file:com.lloydtorres.stately.report.ReportActivity.java
private void sendReport() { if (isInProgress) { SparkleHelper.makeSnackbar(view, getString(R.string.multiple_request_error)); return;/*from w ww . j a v a 2 s .c o m*/ } isInProgress = true; String typeHeader; String reasonHeader; switch (type) { case REPORT_TYPE_RMB: typeHeader = getString(R.string.report_header_rmb_post); reasonHeader = getString(R.string.report_header_reason); break; case REPORT_TYPE_TELEGRAM: typeHeader = getString(R.string.report_header_telegram); reasonHeader = getString(R.string.report_header_reason); break; case REPORT_TYPE_TASK: typeHeader = getString(R.string.report_header_task); reasonHeader = getString(R.string.report_header_response); break; default: typeHeader = ""; reasonHeader = ""; break; } final String commentHeader = String.format(Locale.US, getString(R.string.report_header_comment_template), typeHeader, targetId, reasonHeader, reportContent.getText().toString()); final int problemHeader; if (type == REPORT_TYPE_TASK) { problemHeader = HEADER_GHR_MODREPLY; } else { switch (reportCategorySelect.getCheckedRadioButtonId()) { case R.id.report_inappropriate: problemHeader = HEADER_GHR_INAPPROPRIATE; break; case R.id.report_spam: problemHeader = HEADER_GHR_SPAMMER; break; default: problemHeader = HEADER_GHR_OTHER; break; } } NSStringRequest stringRequest = new NSStringRequest(getApplicationContext(), Request.Method.POST, REPORT_URL, new Response.Listener<String>() { @Override public void onResponse(String response) { isInProgress = false; mSwipeRefreshLayout.setRefreshing(false); finish(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { SparkleHelper.logError(error.toString()); mSwipeRefreshLayout.setRefreshing(false); isInProgress = false; if (error instanceof TimeoutError || error instanceof NoConnectionError || error instanceof NetworkError) { SparkleHelper.makeSnackbar(view, getString(R.string.login_error_no_internet)); } else { SparkleHelper.makeSnackbar(view, getString(R.string.login_error_generic)); } } }); Map<String, String> params = new HashMap<String, String>(); params.put("problem", Integer.toString(problemHeader)); params.put("comment", Html.escapeHtml(commentHeader)); params.put("submit", "1"); stringRequest.setParams(params); if (!DashHelper.getInstance(this).addRequest(stringRequest)) { mSwipeRefreshLayout.setRefreshing(false); isInProgress = false; SparkleHelper.makeSnackbar(view, getString(R.string.rate_limit_error)); } }
From source file:com.lloydtorres.stately.telegrams.TelegramComposeActivity.java
private void sendTelegram(final List<String> recipients, final String chk) { NSStringRequest stringRequest = new NSStringRequest(getApplicationContext(), Request.Method.POST, Telegram.SEND_TELEGRAM, new Response.Listener<String>() { @Override//from w w w . j av a2 s . c om public void onResponse(String response) { mSwipeRefreshLayout.setRefreshing(false); isInProgress = false; String textResponse = Jsoup.parse(response, SparkleHelper.BASE_URI).text(); if (textResponse.contains(SENT_CONFIRM_1) || textResponse.contains(SENT_CONFIRM_2)) { finish(); } else { SparkleHelper.makeSnackbar(mView, getString(R.string.telegrams_fail)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { SparkleHelper.logError(error.toString()); mSwipeRefreshLayout.setRefreshing(false); isInProgress = false; if (error instanceof TimeoutError || error instanceof NoConnectionError || error instanceof NetworkError) { SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_no_internet)); } else { SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_generic)); } } }); Map<String, String> params = new HashMap<String, String>(); params.put("chk", chk); params.put("tgto", SparkleHelper.joinStringList(recipients, ", ")); if (replyId == NO_REPLY_ID) { params.put("recruitregion", "region"); params.put("recruitregionrealname", PinkaHelper.getRegionSessionData(getApplicationContext())); params.put("send", "1"); } else { params.put("in_reply_to", String.valueOf(replyId)); if (recipients.size() > 1) { params.put("send_to_all", "1"); } else { params.put("send", "1"); } } params.put("message", Html.escapeHtml(content.getText().toString())); stringRequest.setParams(params); if (!DashHelper.getInstance(this).addRequest(stringRequest)) { mSwipeRefreshLayout.setRefreshing(false); isInProgress = false; SparkleHelper.makeSnackbar(mView, getString(R.string.rate_limit_error)); } }