Back to project page nodechat-android.
The source code is released under:
Apache License
If you think the Android project nodechat-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.vt.ece4564; // w w w . j a va 2 s. co m import java.util.Date; import org.json.JSONException; import org.json.JSONObject; public class ChatUtils { public static StringBuilder getServerUrl() { StringBuilder url = new StringBuilder(); url.append(Options.Chat.SERVER_URL); if(Options.Chat.SERVER_URL.endsWith("/") == false){ url.append("/"); } return url; } public static String formatMessage(JSONObject json) throws JSONException { StringBuilder msg = new StringBuilder(); String msgType = json.getString("type"); if (msgType.equals("msg")) { msg.append(formatTimestamp(json.getLong("timestamp"))); msg.append(" <b>"); msg.append(json.getString("nick")); msg.append("</b>: "); msg.append(json.getString("text")); } else if (msgType.equals("join")) { msg.append(formatTimestamp(json.getLong("timestamp"))); msg.append(" <b>"); msg.append(json.getString("nick")); msg.append("</b> joined"); } else if (msgType.equals("part")) { msg.append(formatTimestamp(json.getLong("timestamp"))); msg.append(" <b>"); msg.append(json.getString("nick")); msg.append("</b> left"); } return msg.toString(); } protected static String formatTimestamp(long time) { return new java.text.SimpleDateFormat("HH:mm") .format(new java.util.Date(time)); } }