--- a/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/MessageLog.java Tue Jan 21 22:38:13 2014 +0100
+++ b/project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/MessageLog.java Tue Jan 21 22:43:06 2014 +0100
@@ -44,126 +44,126 @@
import android.util.Log;
public class MessageLog {
- private static final int BACKLOG_LINES = 200;
-
- private static final int INFO_COLOR = Color.GRAY;
- private static final int PLAYERINFO_COLOR = Color.GREEN;
- private static final int CHAT_COLOR = Color.GREEN;
- private static final int MECHAT_COLOR = Color.CYAN;
- private static final int WARN_COLOR = Color.RED;
- private static final int ERROR_COLOR = Color.RED;
-
- private final Context context;
- private List<Listener> observers = new LinkedList<Listener>();
- private List<CharSequence> log = new LinkedList<CharSequence>();
-
- public MessageLog(Context context) {
- this.context = context;
- }
-
- private Spanned makeLogTime() {
- String time = DateFormat.getTimeFormat(context).format(new Date());
- return withColor("[" + time + "] ", INFO_COLOR);
- }
-
- private static Spanned span(CharSequence s, Object o) {
- Spannable spannable = new SpannableString(s);
- spannable.setSpan(o, 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- return spannable;
- }
-
- private static Spanned withColor(CharSequence s, int color) {
- return span(s, new ForegroundColorSpan(color));
- }
-
- private static Spanned bold(CharSequence s) {
- return span(s, new StyleSpan(Typeface.BOLD));
- }
-
- private void append(CharSequence msg) {
- SpannableStringBuilder ssb = new SpannableStringBuilder();
- ssb.append(makeLogTime()).append(msg);
- appendRaw(ssb);
- }
-
- private void appendRaw(CharSequence msg) {
- if(log.size() > BACKLOG_LINES) {
- log.remove(0);
- for(Listener o : observers) {
- o.lineRemoved();
- }
- }
- log.add(msg);
- for(Listener o : observers) {
- o.lineAdded(msg);
- }
- }
-
- void appendPlayerJoin(String playername) {
- append(withColor("***" + context.getResources().getString(R.string.log_player_join, playername), INFO_COLOR));
- }
-
- void appendPlayerLeave(String playername, String partMsg) {
- String msg = "***";
- if(partMsg != null) {
- msg += context.getResources().getString(R.string.log_player_leave_with_msg, playername, partMsg);
- } else {
- msg += context.getResources().getString(R.string.log_player_leave, playername);
- }
- append(withColor(msg, INFO_COLOR));
- }
-
- void appendChat(String playerName, String msg) {
- if(msg.startsWith("/me ")) {
- append(withColor("*"+playerName+" "+msg.substring(4), MECHAT_COLOR));
- } else {
- Spanned name = bold(playerName+": ");
- Spanned fullMessage = withColor(TextUtils.concat(name, msg), CHAT_COLOR);
- append(fullMessage);
- }
- }
-
- void appendMessage(int type, String msg) {
- switch(type) {
- case Frontlib.NETCONN_MSG_TYPE_ERROR:
- append(withColor("***"+msg, ERROR_COLOR));
- break;
- case Frontlib.NETCONN_MSG_TYPE_WARNING:
- append(withColor("***"+msg, WARN_COLOR));
- break;
- case Frontlib.NETCONN_MSG_TYPE_PLAYERINFO:
- append(withColor(msg.replace("\n", " "), PLAYERINFO_COLOR));
- break;
- case Frontlib.NETCONN_MSG_TYPE_SERVERMESSAGE:
- appendRaw(span(TextUtils.concat("\n", Html.fromHtml(msg), "\n"), new RelativeSizeSpan(1.5f)));
- break;
- default:
- Log.e("MessageLog", "Unknown messagetype "+type);
- }
- }
-
- void clear() {
- for(Listener o : observers) {
- o.clear();
- }
- log.clear();
- }
-
- public void addListener(Listener o) {
- observers.add(o);
- }
-
- public void removeListener(Listener o) {
- observers.remove(o);
- }
-
- public static interface Listener {
- void lineAdded(CharSequence text);
- void lineRemoved();
- void clear();
- }
+ private static final int BACKLOG_LINES = 200;
+
+ private static final int INFO_COLOR = Color.GRAY;
+ private static final int PLAYERINFO_COLOR = Color.GREEN;
+ private static final int CHAT_COLOR = Color.GREEN;
+ private static final int MECHAT_COLOR = Color.CYAN;
+ private static final int WARN_COLOR = Color.RED;
+ private static final int ERROR_COLOR = Color.RED;
+
+ private final Context context;
+ private List<Listener> observers = new LinkedList<Listener>();
+ private List<CharSequence> log = new LinkedList<CharSequence>();
+
+ public MessageLog(Context context) {
+ this.context = context;
+ }
+
+ private Spanned makeLogTime() {
+ String time = DateFormat.getTimeFormat(context).format(new Date());
+ return withColor("[" + time + "] ", INFO_COLOR);
+ }
+
+ private static Spanned span(CharSequence s, Object o) {
+ Spannable spannable = new SpannableString(s);
+ spannable.setSpan(o, 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ return spannable;
+ }
+
+ private static Spanned withColor(CharSequence s, int color) {
+ return span(s, new ForegroundColorSpan(color));
+ }
+
+ private static Spanned bold(CharSequence s) {
+ return span(s, new StyleSpan(Typeface.BOLD));
+ }
+
+ private void append(CharSequence msg) {
+ SpannableStringBuilder ssb = new SpannableStringBuilder();
+ ssb.append(makeLogTime()).append(msg);
+ appendRaw(ssb);
+ }
+
+ private void appendRaw(CharSequence msg) {
+ if(log.size() > BACKLOG_LINES) {
+ log.remove(0);
+ for(Listener o : observers) {
+ o.lineRemoved();
+ }
+ }
+ log.add(msg);
+ for(Listener o : observers) {
+ o.lineAdded(msg);
+ }
+ }
+
+ void appendPlayerJoin(String playername) {
+ append(withColor("***" + context.getResources().getString(R.string.log_player_join, playername), INFO_COLOR));
+ }
- public Collection<CharSequence> getLog() {
- return Collections.unmodifiableList(log);
- }
+ void appendPlayerLeave(String playername, String partMsg) {
+ String msg = "***";
+ if(partMsg != null) {
+ msg += context.getResources().getString(R.string.log_player_leave_with_msg, playername, partMsg);
+ } else {
+ msg += context.getResources().getString(R.string.log_player_leave, playername);
+ }
+ append(withColor(msg, INFO_COLOR));
+ }
+
+ void appendChat(String playerName, String msg) {
+ if(msg.startsWith("/me ")) {
+ append(withColor("*"+playerName+" "+msg.substring(4), MECHAT_COLOR));
+ } else {
+ Spanned name = bold(playerName+": ");
+ Spanned fullMessage = withColor(TextUtils.concat(name, msg), CHAT_COLOR);
+ append(fullMessage);
+ }
+ }
+
+ void appendMessage(int type, String msg) {
+ switch(type) {
+ case Frontlib.NETCONN_MSG_TYPE_ERROR:
+ append(withColor("***"+msg, ERROR_COLOR));
+ break;
+ case Frontlib.NETCONN_MSG_TYPE_WARNING:
+ append(withColor("***"+msg, WARN_COLOR));
+ break;
+ case Frontlib.NETCONN_MSG_TYPE_PLAYERINFO:
+ append(withColor(msg.replace("\n", " "), PLAYERINFO_COLOR));
+ break;
+ case Frontlib.NETCONN_MSG_TYPE_SERVERMESSAGE:
+ appendRaw(span(TextUtils.concat("\n", Html.fromHtml(msg), "\n"), new RelativeSizeSpan(1.5f)));
+ break;
+ default:
+ Log.e("MessageLog", "Unknown messagetype "+type);
+ }
+ }
+
+ void clear() {
+ for(Listener o : observers) {
+ o.clear();
+ }
+ log.clear();
+ }
+
+ public void addListener(Listener o) {
+ observers.add(o);
+ }
+
+ public void removeListener(Listener o) {
+ observers.remove(o);
+ }
+
+ public static interface Listener {
+ void lineAdded(CharSequence text);
+ void lineRemoved();
+ void clear();
+ }
+
+ public Collection<CharSequence> getLog() {
+ return Collections.unmodifiableList(log);
+ }
}