Android Open Source - nodechat-android Chat Utils






From Project

Back to project page nodechat-android.

License

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.

Java Source Code

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));
  }
}




Java Source Code List

org.vt.ece4564.AsyncHttpTask.java
org.vt.ece4564.ChatActivity.java
org.vt.ece4564.ChatClient.java
org.vt.ece4564.ChatListAdapter.java
org.vt.ece4564.ChatUtils.java
org.vt.ece4564.HttpCallback.java
org.vt.ece4564.HttpRequestInfo.java
org.vt.ece4564.HttpUtils.java
org.vt.ece4564.JoinActivity.java
org.vt.ece4564.Options.java