From cc1b4c803a632525443b6af43e59ccfb0558772c Mon Sep 17 00:00:00 2001 From: Morgan Gangwere Date: Tue, 11 Feb 2014 05:14:25 -0700 Subject: [PATCH] Added rudimentary theme support Theme support is NOW! Woo! The documentation is nonexistent, and some of the details are sketchy, but IT WORKS! Included is the Base16 Monokai theme. Later to come might include Zenburn and others! Yay! This required some massive restructuring of how Messages are handled, and how their colors are managed. In this case, a new Sub-Enum is created, the Message.MessageColor enum, which defines a bunch of possible values. Later on, I need to document all these. --- application/res/values/arrays.xml | 9 ++ application/res/values/settings.xml | 5 +- application/res/xml/preferences.xml | 9 ++ application/res/xml/theme_default.xml | 28 ++++ application/res/xml/theme_monokai.xml | 30 ++++ application/src/indrora/atomic/Atomic.java | 1 + .../atomic/activity/ConversationActivity.java | 10 +- .../atomic/adapter/MessageListAdapter.java | 2 +- .../indrora/atomic/command/CommandParser.java | 2 +- .../atomic/command/handler/DCCHandler.java | 2 +- .../atomic/command/handler/HelpHandler.java | 4 +- .../atomic/command/handler/NamesHandler.java | 2 +- .../src/indrora/atomic/irc/IRCConnection.java | 82 +++++----- .../src/indrora/atomic/irc/IRCService.java | 2 +- .../src/indrora/atomic/model/ColorScheme.java | 152 ++++++++++++++++++ .../src/indrora/atomic/model/Message.java | 102 +++++++++--- .../src/indrora/atomic/model/Settings.java | 5 + .../src/indrora/atomic/utils/MircColors.java | 17 +- .../indrora/atomic/view/MessageListView.java | 11 +- 19 files changed, 400 insertions(+), 75 deletions(-) create mode 100644 application/res/xml/theme_default.xml create mode 100644 application/res/xml/theme_monokai.xml create mode 100644 application/src/indrora/atomic/model/ColorScheme.java diff --git a/application/res/values/arrays.xml b/application/res/values/arrays.xml index 931b81b..c8d5b8f 100644 --- a/application/res/values/arrays.xml +++ b/application/res/values/arrays.xml @@ -46,4 +46,13 @@ 20 30 + + + Default + Monokai + + + default + monokai + diff --git a/application/res/values/settings.xml b/application/res/values/settings.xml index b2ecf17..8545cc4 100644 --- a/application/res/values/settings.xml +++ b/application/res/values/settings.xml @@ -56,7 +56,10 @@ mirc_colors true - + + colorscheme + default + graphical_smilies true diff --git a/application/res/xml/preferences.xml b/application/res/xml/preferences.xml index c44551e..4c1f91b 100644 --- a/application/res/xml/preferences.xml +++ b/application/res/xml/preferences.xml @@ -54,6 +54,15 @@ along with Yaaic. If not, see . android:entryValues="@array/fontsize_values" android:key="@string/key_fontsize" android:defaultValue="@string/default_fontsize" /> + + + #ffffffff + #ff000000 + #ff458509 + #ffcc0000 + #ff729fcf + #ffbe9b01 + #ffaaaaaa + #ffcc0000 + #FF00007F + #FFFFFFFF + #FF000000 + #FF00007F + #FF009300 + #FFFC0000 + #FF7F0000 + #FF9C009C + #FFFC7F00 + #FFFFFF00 + #FF00FC00 + #FF008080 + #FF00FFFF + #FF0000FF + #FFFF00FF + #FF7F7F7F + #FFD2D2D2 + \ No newline at end of file diff --git a/application/res/xml/theme_monokai.xml b/application/res/xml/theme_monokai.xml new file mode 100644 index 0000000..72dc174 --- /dev/null +++ b/application/res/xml/theme_monokai.xml @@ -0,0 +1,30 @@ + + + + #fff9f8f5 + + #ff141414 + #ffa1efe4 + #fff92672 + #ff66d9ef + #ffa6e22e + #fffd971f + #ffae81ff + #fff4bf75 + #ff272822 + #ff383830 + #ff49483e + #ff75715e + #ffa59f85 + #fff8f8f2 + #fff5f4f1 + #fff9f8f5 + #fff92672 + #fffd971f + #fff4bf75 + #ffa6e22e + #ffa1efe4 + #ff66d9ef + #ffae81ff + #ffcc6633 + \ No newline at end of file diff --git a/application/src/indrora/atomic/Atomic.java b/application/src/indrora/atomic/Atomic.java index 61bbc4a..8495eda 100644 --- a/application/src/indrora/atomic/Atomic.java +++ b/application/src/indrora/atomic/Atomic.java @@ -28,6 +28,7 @@ import java.util.Set; +import android.app.Application; import android.content.Context; /** diff --git a/application/src/indrora/atomic/activity/ConversationActivity.java b/application/src/indrora/atomic/activity/ConversationActivity.java index 4331380..e514d13 100644 --- a/application/src/indrora/atomic/activity/ConversationActivity.java +++ b/application/src/indrora/atomic/activity/ConversationActivity.java @@ -33,6 +33,7 @@ import indrora.atomic.listener.ServerListener; import indrora.atomic.listener.SpeechClickListener; import indrora.atomic.model.Broadcast; +import indrora.atomic.model.ColorScheme; import indrora.atomic.model.Conversation; import indrora.atomic.model.Extra; import indrora.atomic.model.Message; @@ -98,6 +99,9 @@ public class ConversationActivity extends SherlockActivity implements ServiceCon private static final int REQUEST_CODE_USER = 3; private static final int REQUEST_CODE_NICK_COMPLETION= 4; + private static ColorScheme _scheme; + public static ColorScheme getScheme() { return _scheme; } + private int serverId; private Server server; private IRCBinder binder; @@ -183,6 +187,8 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + _scheme = new ColorScheme(this); + serverId = getIntent().getExtras().getInt("serverId"); server = Atomic.getInstance().getServerById(serverId); Settings settings = new Settings(this); @@ -764,7 +770,7 @@ private void sendMessage(String text) { if (!server.isConnected()) { Message message = new Message(getString(R.string.message_not_connected)); - message.setColor(Message.COLOR_RED); + message.setColor(Message.MessageColor.ERROR); message.setIcon(R.drawable.error); server.getConversation(server.getSelectedConversation()).addMessage(message); onConversationMessage(server.getSelectedConversation()); @@ -783,7 +789,7 @@ private void sendMessage(String text) { binder.getService().getConnection(serverId).sendMessage(conversation.getName(), text); } else { Message message = new Message(getString(R.string.chat_only_form_channel)); - message.setColor(Message.COLOR_YELLOW); + message.setColor(Message.MessageColor.TOPIC); message.setIcon(R.drawable.warning); conversation.addMessage(message); } diff --git a/application/src/indrora/atomic/adapter/MessageListAdapter.java b/application/src/indrora/atomic/adapter/MessageListAdapter.java index 6853b6c..2377c23 100644 --- a/application/src/indrora/atomic/adapter/MessageListAdapter.java +++ b/application/src/indrora/atomic/adapter/MessageListAdapter.java @@ -57,7 +57,7 @@ public MessageListAdapter(Conversation conversation, Context context) // Render channel name as first message in channel if (conversation.getType() != Conversation.TYPE_SERVER) { Message header = new Message(conversation.getName()); - header.setColor(Message.COLOR_RED); + header.setColor(Message.MessageColor.ERROR); messages.add(header.renderTextView(context)); } diff --git a/application/src/indrora/atomic/command/CommandParser.java b/application/src/indrora/atomic/command/CommandParser.java index 041460a..c7befca 100644 --- a/application/src/indrora/atomic/command/CommandParser.java +++ b/application/src/indrora/atomic/command/CommandParser.java @@ -183,7 +183,7 @@ public void handleClientCommand(String type, String[] params, Server server, Con // Command could not be executed if (conversation != null) { Message errorMessage = new Message(type + ": " + e.getMessage()); - errorMessage.setColor(Message.COLOR_RED); + errorMessage.setColor(Message.MessageColor.ERROR); conversation.addMessage(errorMessage); // XXX:I18N - How to get a context here? (command_syntax) diff --git a/application/src/indrora/atomic/command/handler/DCCHandler.java b/application/src/indrora/atomic/command/handler/DCCHandler.java index 03c9302..e873c95 100644 --- a/application/src/indrora/atomic/command/handler/DCCHandler.java +++ b/application/src/indrora/atomic/command/handler/DCCHandler.java @@ -61,7 +61,7 @@ public void execute(String[] params, Server server, Conversation conversation, I service.getConnection(server.getId()).dccSendFile(file, params[2], 60000); Message message = new Message(service.getString(R.string.dcc_waiting_accept, params[2])); - message.setColor(Message.COLOR_GREY); + message.setColor(Message.MessageColor.SERVER_EVENT); conversation.addMessage(message); service.sendBroadcast( diff --git a/application/src/indrora/atomic/command/handler/HelpHandler.java b/application/src/indrora/atomic/command/handler/HelpHandler.java index 8e3d907..6d195ce 100644 --- a/application/src/indrora/atomic/command/handler/HelpHandler.java +++ b/application/src/indrora/atomic/command/handler/HelpHandler.java @@ -92,7 +92,7 @@ private void showAllCommands(IRCService service, Server server, Conversation con } Message message = new Message(commandList.toString()); - message.setColor(Message.COLOR_YELLOW); + message.setColor(Message.MessageColor.TOPIC); conversation.addMessage(message); Intent intent = Broadcast.createConversationIntent( @@ -121,7 +121,7 @@ private void showCommandDetails(IRCService service, Server server, Conversation if (commands.containsKey(command)) { // XXX:I18N - String building salad :) Message message = new Message("Help of /" + command + "\n" + commands.get(command).getUsage() + "\n" + commands.get(command).getDescription(service) + "\n"); - message.setColor(Message.COLOR_YELLOW); + message.setColor(Message.MessageColor.TOPIC); conversation.addMessage(message); Intent intent = Broadcast.createConversationIntent( diff --git a/application/src/indrora/atomic/command/handler/NamesHandler.java b/application/src/indrora/atomic/command/handler/NamesHandler.java index 8731878..f82718f 100644 --- a/application/src/indrora/atomic/command/handler/NamesHandler.java +++ b/application/src/indrora/atomic/command/handler/NamesHandler.java @@ -63,7 +63,7 @@ public void execute(String[] params, Server server, Conversation conversation, I } Message message = new Message(userList.toString()); - message.setColor(Message.COLOR_YELLOW); + message.setColor(Message.MessageColor.TOPIC); conversation.addMessage(message); Intent intent = Broadcast.createConversationIntent( diff --git a/application/src/indrora/atomic/irc/IRCConnection.java b/application/src/indrora/atomic/irc/IRCConnection.java index 228dedb..14e3174 100644 --- a/application/src/indrora/atomic/irc/IRCConnection.java +++ b/application/src/indrora/atomic/irc/IRCConnection.java @@ -177,11 +177,11 @@ public void onConnect() service.notifyConnected(server.getTitle()); Message message = new Message(service.getString(R.string.message_connected, server.getTitle())); - message.setColor(Message.COLOR_GREEN); + message.setColor(Message.MessageColor.USER_EVENT); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message); Message infoMessage = new Message(service.getString(R.string.message_now_login)); - infoMessage.setColor(Message.COLOR_GREY); + infoMessage.setColor(Message.MessageColor.SERVER_EVENT); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(infoMessage); Intent intent = Broadcast.createConversationIntent( @@ -238,7 +238,7 @@ public void onRegister() } Message infoMessage = new Message(service.getString(R.string.message_login_done)); - infoMessage.setColor(Message.COLOR_GREY); + infoMessage.setColor(Message.MessageColor.SERVER_EVENT); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(infoMessage); Intent intent = Broadcast.createConversationIntent( @@ -312,7 +312,7 @@ protected void onAction(String sender, String login, String hostname, String tar if (mentioned) { // highlight - message.setColor(Message.COLOR_RED); + message.setColor(Message.MessageColor.ERROR); conversation.setStatus(Conversation.STATUS_HIGHLIGHT); } } @@ -333,7 +333,7 @@ protected void onDeop(String target, String sourceNick, String sourceLogin, Stri { Message message = new Message(service.getString(R.string.message_deop, sourceNick, recipient)); message.setIcon(R.drawable.op); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); Intent intent = Broadcast.createConversationIntent( @@ -352,7 +352,7 @@ protected void onDeop(String target, String sourceNick, String sourceLogin, Stri protected void onDeVoice(String target, String sourceNick, String sourceLogin, String sourceHostname, String recipient) { Message message = new Message(service.getString(R.string.message_devoice, sourceNick, recipient)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); message.setIcon(R.drawable.voice); server.getConversation(target).addMessage(message); @@ -421,7 +421,7 @@ protected void onJoin(String target, String sender, String login, String hostnam ); message.setIcon(R.drawable.join); - message.setColor(Message.COLOR_GREEN); + message.setColor(Message.MessageColor.USER_EVENT); server.getConversation(target).addMessage(message); Intent intent = Broadcast.createConversationIntent( @@ -452,7 +452,7 @@ protected void onKick(String target, String kickerNick, String kickerLogin, Stri service.sendBroadcast(intent); } else { Message message = new Message(service.getString(R.string.message_kick, kickerNick, recipientNick)); - message.setColor(Message.COLOR_GREEN); + message.setColor(Message.MessageColor.USER_EVENT); server.getConversation(target).addMessage(message); Intent intent = Broadcast.createConversationIntent( @@ -475,7 +475,7 @@ protected void onMessage(String target, String sender, String login, String host if (isMentioned(text)) { // highlight - message.setColor(Message.COLOR_RED); + message.setColor(Message.MessageColor.ERROR); if (conversation.getStatus() != Conversation.STATUS_SELECTED || !server.getIsForeground()) { service.addNewMention( server.getId(), @@ -530,7 +530,7 @@ protected void onNickChange(String oldNick, String login, String hostname, Strin // Send message about own change to server info window Message message = new Message(service.getString(R.string.message_self_rename, newNick)); - message.setColor(Message.COLOR_GREEN); + message.setColor(Message.MessageColor.USER_EVENT); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message); Intent intent = Broadcast.createConversationIntent( @@ -546,7 +546,7 @@ protected void onNickChange(String oldNick, String login, String hostname, Strin for (String target : channels) { Message message = new Message(service.getString(R.string.message_rename, oldNick, newNick)); - message.setColor(Message.COLOR_GREEN); + message.setColor(Message.MessageColor.USER_EVENT); server.getConversation(target).addMessage(message); Intent intent = Broadcast.createConversationIntent( @@ -597,7 +597,7 @@ protected void onNotice(String sourceNick, String sourceLogin, String sourceHost protected void onOp(String target, String sourceNick, String sourceLogin, String sourceHostname, String recipient) { Message message = new Message(service.getString(R.string.message_op, sourceNick, recipient)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); message.setIcon(R.drawable.op); server.getConversation(target).addMessage(message); @@ -632,7 +632,7 @@ protected void onPart(String target, String sender, String login, String hostnam Message.TYPE_MISC ); - message.setColor(Message.COLOR_GREEN); + message.setColor(Message.MessageColor.USER_EVENT); message.setIcon(R.drawable.part); server.getConversation(target).addMessage(message); @@ -700,7 +700,7 @@ protected void onPrivateMessage(String sender, String login, String hostname, St } if (isMentioned(text)) { - message.setColor(Message.COLOR_RED); + message.setColor(Message.MessageColor.ERROR); conversation.setStatus(Conversation.STATUS_HIGHLIGHT); } } @@ -724,7 +724,7 @@ protected void onQuit(String sourceNick, String sourceLogin, String sourceHostna Message.TYPE_MISC ); - message.setColor(Message.COLOR_GREEN); + message.setColor(Message.MessageColor.USER_EVENT); message.setIcon(R.drawable.quit); server.getConversation(target).addMessage(message); @@ -745,7 +745,7 @@ protected void onQuit(String sourceNick, String sourceLogin, String sourceHostna Message.TYPE_MISC ); - message.setColor(Message.COLOR_GREEN); + message.setColor(Message.MessageColor.USER_EVENT); message.setIcon(R.drawable.quit); conversation.addMessage(message); @@ -767,11 +767,11 @@ public void onTopic(String target, String topic, String setBy, long date, boolea { if (changed) { Message message = new Message(service.getString(R.string.message_topic_set, setBy, topic)); - message.setColor(Message.COLOR_YELLOW); + message.setColor(Message.MessageColor.TOPIC); server.getConversation(target).addMessage(message); } else { Message message = new Message(service.getString(R.string.message_topic, topic)); - message.setColor(Message.COLOR_YELLOW); + message.setColor(Message.MessageColor.TOPIC); server.getConversation(target).addMessage(message); } @@ -811,7 +811,7 @@ protected void onVoice(String target, String sourceNick, String sourceLogin, Str { Message message = new Message(service.getString(R.string.message_voice, sourceNick, recipient)); message.setIcon(R.drawable.voice); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); Intent intent = Broadcast.createConversationIntent( @@ -829,7 +829,7 @@ protected void onVoice(String target, String sourceNick, String sourceLogin, Str protected void onRemoveChannelKey(String target, String sourceNick, String sourceLogin, String sourceHostname, String key) { Message message = new Message(service.getString(R.string.message_remove_channel_key, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -844,7 +844,7 @@ protected void onRemoveChannelKey(String target, String sourceNick, String sourc protected void onSetChannelKey(String target, String sourceNick, String sourceLogin, String sourceHostname, String key) { Message message = new Message(service.getString(R.string.message_set_channel_key, sourceNick, key)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -859,7 +859,7 @@ protected void onSetChannelKey(String target, String sourceNick, String sourceLo protected void onSetSecret(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_set_channel_secret, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -874,7 +874,7 @@ protected void onSetSecret(String target, String sourceNick, String sourceLogin, protected void onRemoveSecret(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_set_channel_public, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -889,7 +889,7 @@ protected void onRemoveSecret(String target, String sourceNick, String sourceLog protected void onSetChannelLimit(String target, String sourceNick, String sourceLogin, String sourceHostname, int limit) { Message message = new Message(service.getString(R.string.message_set_channel_limit, sourceNick, limit)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -904,7 +904,7 @@ protected void onSetChannelLimit(String target, String sourceNick, String source protected void onRemoveChannelLimit(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_remove_channel_limit, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -919,7 +919,7 @@ protected void onRemoveChannelLimit(String target, String sourceNick, String sou protected void onSetChannelBan(String target, String sourceNick, String sourceLogin, String sourceHostname, String hostmask) { Message message = new Message(service.getString(R.string.message_set_ban, sourceNick, hostmask)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -934,7 +934,7 @@ protected void onSetChannelBan(String target, String sourceNick, String sourceLo protected void onRemoveChannelBan(String target, String sourceNick, String sourceLogin, String sourceHostname, String hostmask) { Message message = new Message(service.getString(R.string.message_remove_ban, sourceNick, hostmask)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -949,7 +949,7 @@ protected void onRemoveChannelBan(String target, String sourceNick, String sourc protected void onSetTopicProtection(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_set_topic_protection, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -964,7 +964,7 @@ protected void onSetTopicProtection(String target, String sourceNick, String sou protected void onRemoveTopicProtection(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_remove_topic_protection, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -979,7 +979,7 @@ protected void onRemoveTopicProtection(String target, String sourceNick, String protected void onSetNoExternalMessages(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_disable_external, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -994,7 +994,7 @@ protected void onSetNoExternalMessages(String target, String sourceNick, String protected void onRemoveNoExternalMessages(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_enable_external, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -1009,7 +1009,7 @@ protected void onRemoveNoExternalMessages(String target, String sourceNick, Stri protected void onSetInviteOnly(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_set_invite_only, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -1024,7 +1024,7 @@ protected void onSetInviteOnly(String target, String sourceNick, String sourceLo protected void onRemoveInviteOnly(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_remove_invite_only, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -1039,7 +1039,7 @@ protected void onRemoveInviteOnly(String target, String sourceNick, String sourc protected void onSetModerated(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_set_moderated, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -1054,7 +1054,7 @@ protected void onSetModerated(String target, String sourceNick, String sourceLog protected void onRemoveModerated(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_remove_moderated, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -1069,7 +1069,7 @@ protected void onRemoveModerated(String target, String sourceNick, String source protected void onSetPrivate(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_set_channel_private, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -1084,7 +1084,7 @@ protected void onSetPrivate(String target, String sourceNick, String sourceLogin protected void onRemovePrivate(String target, String sourceNick, String sourceLogin, String sourceHostname) { Message message = new Message(service.getString(R.string.message_set_channel_public, sourceNick)); - message.setColor(Message.COLOR_BLUE); + message.setColor(Message.MessageColor.CHANNEL_EVENT); server.getConversation(target).addMessage(message); service.sendBroadcast( @@ -1100,7 +1100,7 @@ protected void onUnknown(String line) { Message message = new Message(line); message.setIcon(R.drawable.action); - message.setColor(Message.COLOR_GREY); + message.setColor(Message.MessageColor.SERVER_EVENT); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message); Intent intent = Broadcast.createConversationIntent( @@ -1127,7 +1127,7 @@ protected void onServerResponse(int code, String response) } if (code == 376 && ignoreMOTD) { Message motdMessage = new Message(service.getString(R.string.message_motd_suppressed)); - motdMessage.setColor(Message.COLOR_GREY); + motdMessage.setColor(Message.MessageColor.SERVER_EVENT); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(motdMessage); ignoreMOTD = false; return; @@ -1149,7 +1149,7 @@ protected void onServerResponse(int code, String response) // Currently disabled... to much text Message message = new Message(response); - message.setColor(Message.COLOR_GREY); + message.setColor(Message.MessageColor.SERVER_EVENT); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message); Intent intent = Broadcast.createConversationIntent( @@ -1188,7 +1188,7 @@ public void onDisconnect() for (Conversation conversation : conversations) { Message message = new Message(service.getString(R.string.message_disconnected)); message.setIcon(R.drawable.error); - message.setColor(Message.COLOR_RED); + message.setColor(Message.MessageColor.ERROR); server.getConversation(conversation.getName()).addMessage(message); Intent cIntent = Broadcast.createConversationIntent( diff --git a/application/src/indrora/atomic/irc/IRCService.java b/application/src/indrora/atomic/irc/IRCService.java index efc28db..5a3713c 100644 --- a/application/src/indrora/atomic/irc/IRCService.java +++ b/application/src/indrora/atomic/irc/IRCService.java @@ -514,7 +514,7 @@ public void run() { } } - message.setColor(Message.COLOR_RED); + message.setColor(Message.MessageColor.ERROR); message.setIcon(R.drawable.error); server.getConversation(ServerInfo.DEFAULT_NAME).addMessage(message); diff --git a/application/src/indrora/atomic/model/ColorScheme.java b/application/src/indrora/atomic/model/ColorScheme.java new file mode 100644 index 0000000..ccaefca --- /dev/null +++ b/application/src/indrora/atomic/model/ColorScheme.java @@ -0,0 +1,152 @@ +package indrora.atomic.model; + +import indrora.atomic.R; +import indrora.atomic.R.xml; + +import java.lang.reflect.Field; + +import org.xmlpull.v1.XmlPullParser; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.content.res.XmlResourceParser; +import android.graphics.Color; +import android.preference.PreferenceManager; +import android.util.Log; +import android.widget.Toast; + + +public class ColorScheme implements OnSharedPreferenceChangeListener { + + static Context _context; + static Settings _settings; + + private int foreground; + private int background; + + /* + * + * public static final int COLOR_USER_EVENT = 0xDEADBEEF; + public static final int COLOR_ERROR = 0xDEADCAFE; + public static final int COLOR_CHANNEL_EVENT = 0xBEEFBEEF; + public static final int COLOR_TOPIC = 0xCAFEBEEF; + public static final int COLOR_SERVER_EVENT = 0xBEEFCAFE; + + * + */ + + + + private int user_event; + private int error; + private int channel_event; + private int topic; + private int server_event; + private int highlight; + + private int url; + + private int[] colors = new int[16]; + + + public ColorScheme(Context ctx) + { + // initialize ourselves. + if(ctx != null) {_context = ctx; } + + if(_settings == null) _settings = new Settings(_context); + refreshColorScheme(); + + PreferenceManager.getDefaultSharedPreferences(_context).registerOnSharedPreferenceChangeListener(this); + + } + + + + private synchronized void refreshColorScheme() + { + + + // things! + int id = 0; + String scheme = _settings.getColorScheme(); + Class xml_res = R.xml.class; + try { + Field scheme_field = xml_res.getField("theme_"+scheme); + id = scheme_field.getInt(null); + } catch (Throwable e) { + id = R.xml.theme_default; + } + int color_idx = 0; + XmlResourceParser xml_parser = _context.getResources().getXml(id); + try { + + while(xml_parser.getEventType() != XmlPullParser.END_DOCUMENT) + { + if(xml_parser.getEventType() == XmlPullParser.START_TAG) + { + String TagName = xml_parser.getName(); + if(TagName.equals("colorscheme")) { /* Do do dooo */} + // Foreground and background + else if(TagName.equals("foreground")) {foreground = Color.parseColor(xml_parser.nextText());} + else if(TagName.equals("background")){background = Color.parseColor(xml_parser.nextText());} + // Events that can happen + else if(TagName.equals("userevent")){user_event = Color.parseColor(xml_parser.nextText());} + else if(TagName.equals("channelevent")){channel_event = Color.parseColor(xml_parser.nextText());} + else if(TagName.equals("serverevent")){server_event = Color.parseColor(xml_parser.nextText());} + else if(TagName.equals("error")) {error = Color.parseColor(xml_parser.nextText());} + else if(TagName.equals("topic")){topic = Color.parseColor(xml_parser.nextText());} + else if(TagName.equals("highlight")){highlight = Color.parseColor(xml_parser.nextText());} + // URLs. + else if(TagName.equals("url")){url=Color.parseColor(xml_parser.nextText());} + // The 16 standard colors. + else if(TagName.equals("color")){ + colors[color_idx] = Color.parseColor(xml_parser.nextText()); + color_idx++; + + } + } + xml_parser.next(); + } + xml_parser.close(); + } catch (Throwable e) { + Toast.makeText(_context, "So, a bad thing happened.",Toast.LENGTH_LONG).show(); + Log.e("ColorScheme", e.toString()); + e.printStackTrace(); + } + + } + + public int getColor(int idx) + { + return colors[idx % colors.length]; + } + + public int getForeground() + { + return foreground; + } + public int getBackground() + { + return background; + } + + public int getError() { return error; } + public int getTopic() {return topic; } + public int getChannelEvent() {return channel_event; } + public int getUserEvent() { return user_event; } + public int getServerEvent() {return server_event; } + public int getHighlight() { return highlight; } + public int getUrl() {return url; } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, + String key) { + if(key == "colorscheme") + refreshColorScheme(); + + } + + +} diff --git a/application/src/indrora/atomic/model/Message.java b/application/src/indrora/atomic/model/Message.java index 77ae95e..f439c75 100644 --- a/application/src/indrora/atomic/model/Message.java +++ b/application/src/indrora/atomic/model/Message.java @@ -20,6 +20,7 @@ */ package indrora.atomic.model; +import indrora.atomic.activity.ConversationActivity; import indrora.atomic.utils.MircColors; import indrora.atomic.utils.Smilies; @@ -37,6 +38,7 @@ import android.text.style.ForegroundColorSpan; import android.text.style.ImageSpan; import android.text.util.Linkify; +import android.util.Log; import android.widget.TextView; /** @@ -46,12 +48,28 @@ */ public class Message { - public static final int COLOR_GREEN = 0xFF458509; - public static final int COLOR_RED = 0xFFcc0000; - public static final int COLOR_BLUE = 0xFF729fcf; - public static final int COLOR_YELLOW = 0xFFbe9b01; - public static final int COLOR_GREY = 0xFFaaaaaa; - public static final int COLOR_DEFAULT = 0xFFeeeeee; + public enum MessageColor + { + USER_EVENT, + CHANNEL_EVENT, + SERVER_EVENT, + TOPIC, + HIGHLIGHT, + ERROR, + DEFAULT, + NO_COLOR + } + /* + public static final int COLOR_USER_EVENT = 0xDEADBEEF; + public static final int COLOR_ERROR = 0xFACEBEEF; + public static final int COLOR_CHANNEL_EVENT = 0xBEEFBEEF; + public static final int COLOR_TOPIC = 0xCAFEBEEF; + public static final int COLOR_SERVER_EVENT = 0xBEEFCAFE; + public static final int COLOR_HIGHLIGHT = 0xBEEFBABE; + public static final int COLOR_DEFAULT = 0xFEEDBEEF; + */ + + ColorScheme _scheme; /* normal message, this is the default */ public static final int TYPE_MESSAGE = 0; @@ -89,7 +107,7 @@ public class Message private SpannableString canvas; private long timestamp; - private int color = NO_COLOR; + private MessageColor color = MessageColor.DEFAULT; private int type = NO_ICON; private int icon = NO_TYPE; @@ -182,11 +200,37 @@ public int getType() /** * Set the color of this message */ - public void setColor(int color) - { - this.color = color; + public void setColor(MessageColor color) { + this.color = color; + //this.color = color; } + private int translateColor(MessageColor c) + { + assert (_scheme != null); + Log.d("Message", "Assertion PASS: _scheme is not null."); + Log.d("Message", "Message color is:"+color); + switch(c) + { + case CHANNEL_EVENT: + return _scheme.getChannelEvent(); + case DEFAULT: return _scheme.getForeground(); + case ERROR: + return _scheme.getError(); + case HIGHLIGHT: + return _scheme.getHighlight(); + case SERVER_EVENT: + return _scheme.getServerEvent(); + case TOPIC: + return _scheme.getTopic(); + case USER_EVENT: + return _scheme.getUserEvent(); + default: + return _scheme.getForeground(); + } + + } + /** * Set the timestamp of the message * @@ -206,7 +250,7 @@ private int getSenderColor() { /* It might be worth to use some hash table here */ if (sender == null) { - return COLOR_DEFAULT; + return _scheme.getForeground(); } int color = 0; @@ -216,9 +260,10 @@ private int getSenderColor() } /* we dont want color[colors.length-1] which is black */ - color = color % (colors.length - 1); + //color = color % (colors.length - 1); - return colors[color]; + + return _scheme.getColor(color % 16); //colors[color]; } /** @@ -229,7 +274,14 @@ private int getSenderColor() public SpannableString render(Context context) { Settings settings = new Settings(context); - + if(_scheme == null) + { + _scheme = ConversationActivity.getScheme(); + } + + + MircColors.setColorScheme(_scheme); + if (canvas == null) { String prefix = hasIcon() && settings.showIcons() ? " " : ""; String nick = hasSender() ? "<" + sender + "> " : ""; @@ -238,6 +290,7 @@ public SpannableString render(Context context) canvas = new SpannableString(prefix + timestamp + nick); SpannableString renderedText; + if (settings.showMircColors()) { renderedText = MircColors.toSpannable(text); } else { @@ -273,11 +326,11 @@ public SpannableString render(Context context) int start = 0; for (int i = 0; i < spans.length; i++) { - canvas.setSpan(new ForegroundColorSpan(color), start, canvas.getSpanStart(spans[i]), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + canvas.setSpan(new ForegroundColorSpan( translateColor(color)), start, canvas.getSpanStart(spans[i]), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); start = canvas.getSpanEnd(spans[i]); } - canvas.setSpan(new ForegroundColorSpan(color), start, canvas.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + canvas.setSpan(new ForegroundColorSpan(translateColor(color)), start, canvas.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } @@ -301,7 +354,7 @@ private boolean hasSender() */ private boolean hasColor() { - return color != NO_COLOR; + return color != MessageColor.NO_COLOR; } /** @@ -325,16 +378,27 @@ public TextView renderTextView(Context context) // XXX: We should not read settings here ALWAYS for EVERY textview Settings settings = new Settings(context); + if(_scheme == null) + { + _scheme = new ColorScheme(context); + } + + TextView canvas = new TextView(context); canvas.setAutoLinkMask(Linkify.ALL); canvas.setLinksClickable(true); - canvas.setLinkTextColor(COLOR_BLUE); + canvas.setLinkTextColor(_scheme.getUrl()); canvas.setText(this.render(context)); canvas.setTextSize(settings.getFontSize()); canvas.setTypeface(Typeface.MONOSPACE); - canvas.setTextColor(COLOR_DEFAULT); + canvas.setTextColor(_scheme.getForeground()); + + + assert(_scheme.getForeground() != _scheme.getBackground()); + + //canvas.setBackgroundColor(_scheme.getBackground()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setupViewForHoneycombAndLater(canvas); diff --git a/application/src/indrora/atomic/model/Settings.java b/application/src/indrora/atomic/model/Settings.java index 96689e9..5023acf 100644 --- a/application/src/indrora/atomic/model/Settings.java +++ b/application/src/indrora/atomic/model/Settings.java @@ -317,6 +317,11 @@ public boolean showGraphicalSmilies() Boolean.parseBoolean(resources.getString(R.string.default_graphical_smilies)) ); } + + public String getColorScheme() + { + return preferences.getString("colorscheme", "default"); + } /** * Whether message text should be autocorrected. diff --git a/application/src/indrora/atomic/utils/MircColors.java b/application/src/indrora/atomic/utils/MircColors.java index 6514009..abfbd99 100644 --- a/application/src/indrora/atomic/utils/MircColors.java +++ b/application/src/indrora/atomic/utils/MircColors.java @@ -20,6 +20,8 @@ */ package indrora.atomic.utils; +import indrora.atomic.model.ColorScheme; + import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -70,6 +72,13 @@ public abstract class MircColors private static final Pattern colorPattern = Pattern.compile("\\x03(\\d{1,2})(?:,(\\d{1,2}))?([^\\x03\\x0F]*)(\\x03|\\x0F)?"); private static final Pattern cleanupPattern = Pattern.compile("(?:\\x02|\\x1F|\\x1D|\\x0F|\\x16|\\x03(?:(?:\\d{1,2})(?:,\\d{1,2})?)?)"); + private static ColorScheme _cScheme; + + public static void setColorScheme(ColorScheme scheme) + { + _cScheme = scheme; + } + /** * Converts a string with mIRC style and color codes to a SpannableString with * all the style and color codes applied. @@ -89,10 +98,10 @@ public static SpannableString toSpannable(SpannableString text) * We apply the background color first and then apply the foreground color * to all the parts where BackgroundColorSpans are found. */ - replaceControlCodes(inversePattern.matcher(ssb), ssb, new BackgroundColorSpan(colors[0] | 0xFF000000)); + replaceControlCodes(inversePattern.matcher(ssb), ssb, new BackgroundColorSpan(_cScheme.getBackground())); BackgroundColorSpan[] inverseSpans = ssb.getSpans(0, ssb.length(), BackgroundColorSpan.class); for (int i = 0; i < inverseSpans.length; i++) { - ssb.setSpan(new ForegroundColorSpan(colors[1] | 0xFF000000), ssb.getSpanStart(inverseSpans[i]),ssb.getSpanEnd(inverseSpans[i]), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + ssb.setSpan(new ForegroundColorSpan( _cScheme.getForeground() /*colors[1] | 0xFF000000*/), ssb.getSpanStart(inverseSpans[i]),ssb.getSpanEnd(inverseSpans[i]), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } Matcher m = colorPattern.matcher(ssb); @@ -105,13 +114,13 @@ public static SpannableString toSpannable(SpannableString text) int codelength = m.group(1).length()+1; if (color <= 15 && color >= 0) { - ssb.setSpan(new ForegroundColorSpan(colors[color] | 0xFF000000), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + ssb.setSpan(new ForegroundColorSpan(_cScheme.getColor(color)), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (m.group(2) != null) { color = Integer.parseInt(m.group(2)); if (color <= 15 && color >= 0) { - ssb.setSpan(new BackgroundColorSpan(colors[color] | 0xFF000000), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + ssb.setSpan(new BackgroundColorSpan(_cScheme.getColor(color)), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } codelength = codelength + m.group(2).length() + 1; } diff --git a/application/src/indrora/atomic/view/MessageListView.java b/application/src/indrora/atomic/view/MessageListView.java index ee03b5f..9fe8a82 100644 --- a/application/src/indrora/atomic/view/MessageListView.java +++ b/application/src/indrora/atomic/view/MessageListView.java @@ -20,8 +20,10 @@ */ package indrora.atomic.view; +import indrora.atomic.activity.ConversationActivity; import indrora.atomic.adapter.MessageListAdapter; import indrora.atomic.listener.MessageClickListener; +import indrora.atomic.model.ColorScheme; import indrora.atomic.R; @@ -35,6 +37,9 @@ */ public class MessageListView extends ListView { + + ColorScheme _scheme; + /** * Create a new MessageListView * @@ -44,15 +49,19 @@ public MessageListView(Context context) { super(context); + _scheme = ConversationActivity.getScheme(); + setOnItemClickListener(MessageClickListener.getInstance()); setDivider(null); setCacheColorHint(0x000000); setVerticalFadingEdgeEnabled(false); - setBackgroundResource(R.drawable.conversation_background); + //setBackgroundResource(R.drawable.conversation_background); setScrollBarStyle(SCROLLBARS_OUTSIDE_INSET); + setBackgroundColor(_scheme.getBackground()); + // Scale padding by screen density float density = context.getResources().getDisplayMetrics().density; int padding = (int) (5 * density);