1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2025-02-16 15:00:14 -05:00

Adding nickname colors

This commit is contained in:
chantra 2010-09-09 20:41:55 +02:00
parent 6691b9ad1b
commit 30dc021129
6 changed files with 93 additions and 9 deletions

View File

@ -7,7 +7,7 @@
<string name="default_show_icons">true</string>
<string name="key_show_colors">show_colors</string>
<string name="default_show_colors">true</string>
<string name="default_show_colors">true</string><string name="key_show_colors_nick">show_colors_nick</string><string name="default_show_colors_nick">true</string>
<string name="key_24h_format">24h_format</string>
<string name="default_24h_format">true</string>
@ -23,4 +23,9 @@
<string name="key_voice_recognition">voice_recognition</string>
<string name="default_voice_recognition">true</string>
</resources>

View File

@ -156,7 +156,7 @@
<string name="settings_icons_title">Show icons</string>
<string name="settings_icons_desc">Show icons to highlight special events</string>
<string name="settings_colors_title">Show colors</string>
<string name="settings_colors_desc">Show colors to highlight special events</string>
<string name="settings_colors_desc">Show colors to highlight special events</string><string name="settings_colors_nick_title">Colorize nicknames</string><string name="settings_colors_nick_desc">Show nicknames in different colors</string>
<string name="settings_timestamp_title">Show timestamp</string>
<string name="settings_timestamp_desc">Prefix all messages with a timestamp</string>
<string name="settings_24h_title">24 hour format</string>
@ -171,4 +171,9 @@
<string name="settings_fontsize_dialog_title">Font size</string>
<string name="settings_voice_recognition_title">Voice recognition</string>
<string name="settings_voice_recognition_desc">Show button for voice recognition</string>
</resources>

View File

@ -47,8 +47,11 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
<CheckBoxPreference
android:title="@string/settings_colors_title"
android:summary="@string/settings_colors_desc"
android:key="@string/key_show_colors"
android:defaultValue="@string/default_show_colors" />
android:key="@string/key_show_colors" android:defaultValue="@string/default_show_colors"/>
<CheckBoxPreference
android:title="@string/settings_colors_nick_title"
android:key="@string/key_show_colors_nick"
android:summary="@string/settings_colors_nick_desc" android:defaultValue="@string/default_show_colors_nick"/>
<CheckBoxPreference
android:title="@string/settings_timestamp_title"
android:summary="@string/settings_timestamp_desc"
@ -60,7 +63,8 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
android:key="@string/key_24h_format"
android:defaultValue="@string/default_24h_format"
android:dependency="@string/key_show_timestamp" />
</PreferenceCategory>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/settings_misc">
<CheckBoxPreference

View File

@ -385,7 +385,7 @@ public class IRCConnection extends PircBot
// Strip mIRC colors and formatting
text = Colors.removeFormattingAndColors(text);
Message message = new Message("<" + sender + "> " + text);
Message message = new Message(text, sender);
if (text.contains(getNick())) {
// highlight

View File

@ -42,9 +42,30 @@ public class Message {
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 static final int[] colors = {
0xFFffffff, //White
0xFFffff00, //Yellow
0xFFff00ff, //Fuchsia
0xFFff0000, //Red
0xFFc0c0c0, //Silver
0xFF808080, //Gray
0xFF808000, //Olive
0xFF800080, //Purple
0xFF800000, //Maroon
0xFF00ffff, //Agua
0xFF00ff00, //Lime
0xFF008080, //Teal
0xFF008000, //Green
0xFF0000FF, //Blue
0xFF000080, //Navy
0xFF000000, //Black
};
private int icon = -1;
private String text;
private String sender;
private SpannableString canvas;
private int color = -1;
private long timestamp;
@ -55,8 +76,19 @@ public class Message {
* @param text
*/
public Message(String text)
{
this(text, null);
}
/**
* Create a new message sent by a user without an icon
*
* @param text
* @param sender
*/
public Message(String text, String sender)
{
this.text = text;
this.sender = sender;
this.timestamp = new Date().getTime();
}
@ -95,7 +127,23 @@ public class Message {
{
this.color = color;
}
/**
* Associate a color with a sender name
*
* @return a color hexa
*/
private int getSenderColor()
{
/* It might be worth to use some hash table here */
if (sender == null) return COLOR_DEFAULT;
int color = 0;
for(int i = 0; i < sender.length(); i++){
color += sender.charAt(i);
}
/* we dont want color[colors.length-1] which is black */
color = color % (colors.length - 1);
return colors[color];
}
/**
* Render message as spannable string
*
@ -107,10 +155,19 @@ public class Message {
if (canvas == null) {
String prefix = icon != -1 && settings.showIcons() ? " " : "";
String nick = sender != null ? "<" + sender + "> " : "";
String timestamp = settings.showTimestamp() ? Message.generateTimestamp(this.timestamp, settings.use24hFormat()) : "";
canvas = new SpannableString(prefix + timestamp + text);
canvas = new SpannableString(prefix + timestamp + nick + text);
if (sender != null) {
int start = (prefix + timestamp).length() + 1;
int end = start + sender.length();
if (settings.showColorsNick()) {
canvas.setSpan(new ForegroundColorSpan(getSenderColor()), start, end , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
if (icon != -1 && settings.showIcons()) {
Drawable drawable = context.getResources().getDrawable(icon);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
@ -140,7 +197,7 @@ public class Message {
canvas.setText(this.render(context));
canvas.setTextSize(settings.getFontSize());
canvas.setTypeface(Typeface.MONOSPACE);
canvas.setTextColor(0xffeeeeee);
canvas.setTextColor(COLOR_DEFAULT);
return canvas;
}

View File

@ -92,6 +92,19 @@ public class Settings
);
}
/**
* Show colors to highlight nicknames?
*
* @return
*/
public boolean showColorsNick()
{
return preferences.getBoolean(
resources.getString(R.string.key_show_colors_nick),
Boolean.parseBoolean(resources.getString(R.string.default_show_colors_nick))
);
}
/**
* Use 24 hour format for timestamps?
*