]> Pileus Git - ~andy/spades/commitdiff
Initial text formatting
authorAndy Spencer <andy753421@gmail.com>
Sat, 13 Apr 2013 10:08:11 +0000 (10:08 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 13 Apr 2013 10:08:11 +0000 (10:08 +0000)
src/org/pileus/spades/Client.java
src/org/pileus/spades/Main.java
src/org/pileus/spades/Message.java

index b2d6561c45630896ba949662248bd14b8069239a..3e9e3400b3480daeab2dcac0bdb1b0f05e7bcb8f 100644 (file)
@@ -18,6 +18,7 @@ public class Client
 
        /* Public data */
        public  boolean        ready    = false;
+       public  String         name     = "";
 
                /* Connection data */
        private Socket         socket;
@@ -50,6 +51,7 @@ public class Client
        {
                this.nickname = nickname;
                this.channel  = channel;
+               this.name     = nickname;
        }
 
        public boolean connect()
@@ -68,8 +70,8 @@ public class Client
                Os.debug("Client: connected");
                if (this.usesasl)
                        this.raw("CAP REQ :sasl");
-               this.raw("USER "+this.username+" "+this.hostname+" "+this.server+" :"+this.nickname);
-               this.raw("NICK "+this.nickname);
+               this.raw("USER "+this.username+" "+this.hostname+" "+this.server+" :"+this.name);
+               this.raw("NICK "+this.name);
 
                return true;
        }
@@ -100,7 +102,7 @@ public class Client
 
        public Message send(String txt)
        {
-               Message msg  = new Message(this.channel, this.nickname, txt);
+               Message msg = new Message(this.channel, this.name, txt);
                this.raw(msg.line);
                return msg;
        }
@@ -112,7 +114,7 @@ public class Client
                        if (line == null)
                                return null;
                        Os.debug("> " + line);
-                       Message msg = new Message(line);
+                       Message msg = new Message(line, this.name);
                        this.process(msg);
                        if (this.usesasl)
                                this.dosasl(msg);
@@ -136,8 +138,9 @@ public class Client
                        this.ready = true;
                }
                if (msg.cmd.equals("433")) {
-                       this.raw("NICK "+this.nickname+this.mangle);
-                       this.mangle++;
+                       this.name   = this.nickname + this.mangle;
+                       this.mangle = this.mangle + 11;
+                       this.raw("NICK "  + this.name);
                }
                if (msg.cmd.equals("PING")) {
                        this.raw("PING " + msg.msg);
index f5118c13f1793f860428616dec2d59cc49390f14..bc9828518b28251c885f22a8a1c032ecb71f8ac1 100644 (file)
@@ -5,7 +5,9 @@ import android.content.Intent;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Messenger;
+import android.text.Html;
 import android.text.method.ScrollingMovementMethod;
+import android.text.format.DateFormat;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -19,15 +21,11 @@ import android.widget.TabWidget;
 import android.widget.TextView;
 import android.widget.Toast;
 
-import android.preference.PreferenceActivity;
-
 public class Main extends Activity
 {
-       /* Static data */
+       /* Private data */
        private Handler      handler;
        private Messenger    messenger;
-
-       /* Private data */
        private Task         task;
        private Toast        toast;
        private boolean      ready;
@@ -50,7 +48,67 @@ public class Main extends Activity
        /* Private helper methods */
        private void notice(String text)
        {
-               this.log.append("*** " + text + "\n");
+               this.log.append(Html.fromHtml("<b>*** " + text + "</b><br />"));
+       }
+
+       private void display(Message msg)
+       {
+               String when = DateFormat.format("hh:mm:ss", msg.time).toString();
+               String from = String.format("<font color=\"#ff88ff\">%s</font>", msg.from);
+               String text = msg.msg;
+               String fmt  = null;
+               Os.debug("msg: " + Os.base64(msg.msg));
+
+               // Do IRC Colors
+               //   - This doesn't actually work
+               String fg   = "<font color=\"<$1>\">";
+               String bg   = "<font bgcolor=\"<$2>\">";
+               text = text
+                       .replaceAll("&", "&amp;")
+                       .replaceAll("<", "&lt;")
+                       .replaceAll(">", "&gt;");
+               text = text
+                       .replaceAll("\\002", "<b>")  // bold
+                       .replaceAll("\\011", "<i>")  // italic
+                       .replaceAll("\\025", "<u>")  // underline
+                       .replaceAll("\\022", "<b>"); // reverse
+               text = text
+                       .replaceAll("\\003(\\d+),(\\d+)", fg + bg) // color
+                       .replaceAll("\\013(\\d+),(\\d+)", fg + bg) // color
+                       .replaceAll("\\003(\\d+)", fg)             // color
+                       .replaceAll("\\013(\\d+)", fg);            // color
+               text = text
+                       .replaceAll("<0?0>", "#000000")  // White
+                       .replaceAll("<0?1>", "#000000")  // Black
+                       .replaceAll("<0?2>", "#000080")  // Navy Blue
+                       .replaceAll("<0?3>", "#008000")  // Green
+                       .replaceAll("<0?4>", "#FF0000")  // Red
+                       .replaceAll("<0?5>", "#804040")  // Brown
+                       .replaceAll("<0?6>", "#8000FF")  // Purple
+                       .replaceAll("<0?7>", "#808000")  // Olive
+                       .replaceAll("<0?8>", "#FFFF00")  // Yellow
+                       .replaceAll("<0?9>", "#00FF00")  // Lime Green
+                       .replaceAll("<10>",  "#008080")  // Teal
+                       .replaceAll("<11>",  "#00FFFF")  // Aqua Light
+                       .replaceAll("<12>",  "#0000FF")  // Royal Blue
+                       .replaceAll("<13>",  "#FF00FF")  // Hot Pink
+                       .replaceAll("<14>",  "#808080")  // Dark Gray
+                       .replaceAll("<15>",  "#C0C0C0"); // Light Gray
+
+               // Message formatting
+               switch (msg.how) {
+                       case DIRECT:
+                       case MENTION:
+                       case PRIVMSG:
+                               fmt  = "<b>(%s) %s: %s</b>";
+                               break;
+                       default:
+                               fmt  = "(%s) %s: %s";
+                               break;
+               }
+
+               String html = String.format(fmt, when, from, text);
+               this.log.append(Html.fromHtml(html + "<br />"));
        }
 
        /* Private handler methods */
@@ -71,7 +129,7 @@ public class Main extends Activity
                // Chat
                switch (msg.type) {
                        case PRIVMSG:
-                               this.log.append(msg.from + ": " + msg.msg + "\n");
+                               this.display(msg);
                                break;
                        case TOPIC:
                                if (!msg.txt.equals(this.topic))
index 1f52ebe133443e167c216c0e0e82ea0108e8daef..ad71c2d5b2dbdee779b4ca3241d3575f9971844f 100644 (file)
@@ -1,5 +1,6 @@
 package org.pileus.spades;
 
+import java.util.Date;
 import java.util.regex.Pattern;
 import java.util.regex.Matcher;
 
@@ -7,18 +8,26 @@ public class Message
 {
        /* Enumerations */
        enum Type {
-               OTHER,
-               PRIVMSG,
-               TOPIC,
-               NAMES,
-               ERROR,
-               CAP,
-               AUTH,
-               AUTHOK,
-               AUTHFAIL,
+               OTHER,    // Unknown message type
+               PRIVMSG,  // Private message
+               TOPIC,    // Display current topic
+               NAMES,    // Display user names
+               ERROR,    // Error message from server
+               CAP,      // Server capabilities
+               AUTH,     // Authentication message
+               AUTHOK,   // Authentication succeeded
+               AUTHFAIL, // Authentication failed
        };
 
-       /* Constnats */
+       enum How {
+               OTHER,    // Unknown message type
+               CHANNEL,  // Normal message to a channel
+               MENTION,  // User was mentioned in message text
+               DIRECT,   // Message directed towards user
+               PRIVMSG   // Private message to user only
+       };
+
+       /* Constants */
        private final  String  reMsg  = "(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+)[= ]+)?(([^: ]+) *)?(:(.*))?";
        private final  String  reFrom = "([^! ]+)!.*";
        private final  String  reTo   = "(([^ :,]*)[:,] *)?(.*)";
@@ -28,6 +37,8 @@ public class Message
        private static Pattern ptTo   = null;
 
        /* Public data */
+       public Date    time = null;
+
        public String  line = "";
 
        public String  src  = "";
@@ -37,6 +48,7 @@ public class Message
        public String  msg  = "";
 
        public Type    type = Type.OTHER;
+       public How     how  = How.OTHER;
        public String  from = "";
        public String  to   = "";
        public String  txt  = "";
@@ -57,17 +69,19 @@ public class Message
                this.line = this.cmd + " " + this.dst + " :" + this.msg;
        }
 
-       public Message(String line)
+       public Message(String line, String name)
        {
                // Initialize regexes
                if (ptMsg  == null) ptMsg  = Pattern.compile(reMsg);
                if (ptFrom == null) ptFrom = Pattern.compile(reFrom);
                if (ptTo   == null) ptTo   = Pattern.compile(reTo);
 
+               // Set time stamp
+               this.time = new Date();
+
                // Cleanup line
                line = line.replaceAll("\\s+",       " ");
                line = line.replaceAll("^ | $",      "");
-               line = line.replaceAll("\003[0-9]*", "");
                this.line = line;
 
                // Split line into parts
@@ -106,6 +120,12 @@ public class Message
                else if (this.cmd.equals("905"))           this.type = Type.AUTHFAIL;
                else if (this.cmd.equals("906"))           this.type = Type.AUTHFAIL;
                else if (this.cmd.equals("907"))           this.type = Type.AUTHFAIL;
+
+               // Set directed
+               if      (this.dst.equals(name))            this.how  = How.PRIVMSG;
+               else if (this.to.equals(name))             this.how  = How.DIRECT;
+               else if (this.msg.contains(name))          this.how  = How.MENTION;
+               else if (this.type == Type.PRIVMSG)        this.how  = How.CHANNEL;
        }
 
        public void debug()