diff --git a/application/res/drawable/smiley_cool.png b/application/res/drawable/smiley_cool.png new file mode 100644 index 0000000..99af6c2 Binary files /dev/null and b/application/res/drawable/smiley_cool.png differ diff --git a/application/res/drawable/smiley_cry.png b/application/res/drawable/smiley_cry.png new file mode 100644 index 0000000..67f2b2d Binary files /dev/null and b/application/res/drawable/smiley_cry.png differ diff --git a/application/res/drawable/smiley_embarassed.png b/application/res/drawable/smiley_embarassed.png new file mode 100644 index 0000000..2fe2a87 Binary files /dev/null and b/application/res/drawable/smiley_embarassed.png differ diff --git a/application/res/drawable/smiley_foot_in_mouth.png b/application/res/drawable/smiley_foot_in_mouth.png new file mode 100644 index 0000000..ead363f Binary files /dev/null and b/application/res/drawable/smiley_foot_in_mouth.png differ diff --git a/application/res/drawable/smiley_frown.png b/application/res/drawable/smiley_frown.png new file mode 100644 index 0000000..0c19ffe Binary files /dev/null and b/application/res/drawable/smiley_frown.png differ diff --git a/application/res/drawable/smiley_innocent.png b/application/res/drawable/smiley_innocent.png new file mode 100644 index 0000000..16b96ad Binary files /dev/null and b/application/res/drawable/smiley_innocent.png differ diff --git a/application/res/drawable/smiley_kiss.png b/application/res/drawable/smiley_kiss.png new file mode 100644 index 0000000..48250b5 Binary files /dev/null and b/application/res/drawable/smiley_kiss.png differ diff --git a/application/res/drawable/smiley_laughing.png b/application/res/drawable/smiley_laughing.png new file mode 100644 index 0000000..c2fcafb Binary files /dev/null and b/application/res/drawable/smiley_laughing.png differ diff --git a/application/res/drawable/smiley_money_mouth.png b/application/res/drawable/smiley_money_mouth.png new file mode 100644 index 0000000..183315f Binary files /dev/null and b/application/res/drawable/smiley_money_mouth.png differ diff --git a/application/res/drawable/smiley_sealed.png b/application/res/drawable/smiley_sealed.png new file mode 100644 index 0000000..5cc596a Binary files /dev/null and b/application/res/drawable/smiley_sealed.png differ diff --git a/application/res/drawable/smiley_smile.png b/application/res/drawable/smiley_smile.png new file mode 100644 index 0000000..4fcee23 Binary files /dev/null and b/application/res/drawable/smiley_smile.png differ diff --git a/application/res/drawable/smiley_surprised.png b/application/res/drawable/smiley_surprised.png new file mode 100644 index 0000000..3eae2d9 Binary files /dev/null and b/application/res/drawable/smiley_surprised.png differ diff --git a/application/res/drawable/smiley_tongue_out.png b/application/res/drawable/smiley_tongue_out.png new file mode 100644 index 0000000..1db1367 Binary files /dev/null and b/application/res/drawable/smiley_tongue_out.png differ diff --git a/application/res/drawable/smiley_undecided.png b/application/res/drawable/smiley_undecided.png new file mode 100644 index 0000000..40ccef3 Binary files /dev/null and b/application/res/drawable/smiley_undecided.png differ diff --git a/application/res/drawable/smiley_wink.png b/application/res/drawable/smiley_wink.png new file mode 100644 index 0000000..4007ebc Binary files /dev/null and b/application/res/drawable/smiley_wink.png differ diff --git a/application/res/drawable/smiley_yell.png b/application/res/drawable/smiley_yell.png new file mode 100644 index 0000000..1ffd6fd Binary files /dev/null and b/application/res/drawable/smiley_yell.png differ diff --git a/application/res/values/settings.xml b/application/res/values/settings.xml index c5d0067..bbbd890 100644 --- a/application/res/values/settings.xml +++ b/application/res/values/settings.xml @@ -41,4 +41,7 @@ mirc_colors true + + graphical_smilies + false diff --git a/application/res/values/strings.xml b/application/res/values/strings.xml index d12e3ac..7caf54a 100644 --- a/application/res/values/strings.xml +++ b/application/res/values/strings.xml @@ -198,4 +198,6 @@ Show notices in server window Show message colors Show mIRC colors in messages + Show graphical smilies + Text smilies will be displayed as images in chat diff --git a/application/res/xml/preferences.xml b/application/res/xml/preferences.xml index 9e5c001..e4a1c8f 100644 --- a/application/res/xml/preferences.xml +++ b/application/res/xml/preferences.xml @@ -79,7 +79,12 @@ along with Yaaic. If not, see . android:title="@string/settings_mirc_colors_title" android:summary="@string/settings_mirc_colors_desc" android:key="@string/key_mirc_colors" - android:defaultValue="@string/default_mirc_colors" /> + android:defaultValue="@string/default_mirc_colors" /> + diff --git a/application/src/org/yaaic/model/Message.java b/application/src/org/yaaic/model/Message.java index 29ccfa8..5dfe1c2 100644 --- a/application/src/org/yaaic/model/Message.java +++ b/application/src/org/yaaic/model/Message.java @@ -23,6 +23,7 @@ package org.yaaic.model; import java.util.Date; import org.yaaic.utils.MircColors; +import org.yaaic.utils.Smilies; import android.content.Context; import android.graphics.Typeface; @@ -228,14 +229,15 @@ public class Message String prefix = hasIcon() && settings.showIcons() ? " " : ""; String nick = hasSender() ? "<" + sender + "> " : ""; String timestamp = settings.showTimestamp() ? renderTimeStamp(settings.use24hFormat()) : ""; + canvas = new SpannableString(prefix + timestamp + nick); + SpannableString renderedText = new SpannableString(text); if (settings.showMircColors()) { - canvas = new SpannableString(prefix + timestamp + nick); - canvas = new SpannableString(TextUtils.concat(canvas, MircColors.toSpannable(text))); + renderedText = MircColors.toSpannable(text); } - else { - canvas = new SpannableString(prefix + timestamp + nick + MircColors.removeStyleAndColors(text)); + if (settings.showGraphicalSmilies()) { + renderedText = Smilies.toSpannable(renderedText, context); } - + canvas = new SpannableString(TextUtils.concat(canvas, renderedText)); if (hasSender()) { int start = (prefix + timestamp).length() + 1; int end = start + sender.length(); diff --git a/application/src/org/yaaic/model/Settings.java b/application/src/org/yaaic/model/Settings.java index c5af23d..8a5f74e 100644 --- a/application/src/org/yaaic/model/Settings.java +++ b/application/src/org/yaaic/model/Settings.java @@ -234,4 +234,17 @@ public class Settings Boolean.parseBoolean(resources.getString(R.string.default_mirc_colors)) ); } + + /** + * Render messages with graphical smilies. + * + * @return True if text smilies should be rendered as graphical smilies, false otherwise. + */ + public boolean showGraphicalSmilies() + { + return preferences.getBoolean( + resources.getString(R.string.key_graphical_smilies), + Boolean.parseBoolean(resources.getString(R.string.default_graphical_smilies)) + ); + } } diff --git a/application/src/org/yaaic/utils/MircColors.java b/application/src/org/yaaic/utils/MircColors.java index 4884e0c..af968d5 100644 --- a/application/src/org/yaaic/utils/MircColors.java +++ b/application/src/org/yaaic/utils/MircColors.java @@ -54,7 +54,7 @@ public class MircColors { * @param text A string with mIRC color codes. * @return A SpannableString with all the styles applied. */ - public static SpannableString toSpannable(String text) { + public static SpannableString toSpannable(SpannableString text) { SpannableStringBuilder ssb = new SpannableStringBuilder(text); replaceControlCodes(boldPattern.matcher(ssb), ssb, new StyleSpan(Typeface.BOLD)); replaceControlCodes(underlinePattern.matcher(ssb), ssb, new UnderlineSpan()); @@ -96,6 +96,17 @@ public class MircColors { return new SpannableString(removeStyleAndColors(ssb)); } + /** + * Converts a string with mIRC style and color codes to a SpannableString with + * all the style and color codes applied. + * + * @param text A string with mIRC color codes. + * @return A SpannableString with all the styles applied. + */ + public static SpannableString toSpannable(String text) { + return toSpannable(new SpannableString(text)); + } + private static void replaceControlCodes(Matcher m, SpannableStringBuilder ssb, CharacterStyle style) { ArrayList toremove = new ArrayList(); while (m.find()) { diff --git a/application/src/org/yaaic/utils/Smilies.java b/application/src/org/yaaic/utils/Smilies.java new file mode 100644 index 0000000..9c4ba96 --- /dev/null +++ b/application/src/org/yaaic/utils/Smilies.java @@ -0,0 +1,97 @@ +package org.yaaic.utils; + +import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.yaaic.R; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.style.ImageSpan; +import android.util.Log; + + +public class Smilies { + public static final HashMap mappings = new HashMap(); + private Smilies() {} + + /** + * Converts all smilies in a string to graphical smilies. + * + * @param text A string with smilies. + * @return A SpannableString with graphical smilies. + */ + public static SpannableString toSpannable(SpannableString text, Context context) { + mappings.put(">:o", R.drawable.smiley_yell); + mappings.put(">:-o", R.drawable.smiley_yell); + mappings.put("O:)", R.drawable.smiley_innocent); + mappings.put("O:-)", R.drawable.smiley_innocent); + mappings.put(":)", R.drawable.smiley_smile); + mappings.put(":-)", R.drawable.smiley_smile); + mappings.put(":(", R.drawable.smiley_frown); + mappings.put(":-(", R.drawable.smiley_frown); + mappings.put(";)", R.drawable.smiley_wink); + mappings.put(";-)", R.drawable.smiley_wink); + mappings.put(":p", R.drawable.smiley_tongue_out); + mappings.put(":-p", R.drawable.smiley_tongue_out); + mappings.put(":P", R.drawable.smiley_tongue_out); + mappings.put(":-P", R.drawable.smiley_tongue_out); + mappings.put(":D", R.drawable.smiley_laughing); + mappings.put(":-D", R.drawable.smiley_laughing); + mappings.put(":[", R.drawable.smiley_embarassed); + mappings.put(":-[", R.drawable.smiley_embarassed); + mappings.put(":\\", R.drawable.smiley_undecided); + mappings.put(":-\\", R.drawable.smiley_undecided); + mappings.put(":o", R.drawable.smiley_surprised); + mappings.put(":-o", R.drawable.smiley_surprised); + mappings.put(":O", R.drawable.smiley_surprised); + mappings.put(":-O", R.drawable.smiley_surprised); + mappings.put(":*", R.drawable.smiley_kiss); + mappings.put(":-*", R.drawable.smiley_kiss); + mappings.put("8)", R.drawable.smiley_cool); + mappings.put("8-)", R.drawable.smiley_cool); + mappings.put(":$", R.drawable.smiley_money_mouth); + mappings.put(":-$", R.drawable.smiley_money_mouth); + mappings.put(":!", R.drawable.smiley_foot_in_mouth); + mappings.put(":-!", R.drawable.smiley_foot_in_mouth); + mappings.put(":'(", R.drawable.smiley_cry); + mappings.put(":'-(", R.drawable.smiley_cry); + mappings.put(":´(", R.drawable.smiley_cry); + mappings.put(":´-(", R.drawable.smiley_cry); + mappings.put(":X", R.drawable.smiley_sealed); + mappings.put(":-X", R.drawable.smiley_sealed); + + StringBuilder regex = new StringBuilder("("); + String[] smilies = mappings.keySet().toArray(new String[mappings.size()]); + for (int i = 0; i < smilies.length; i++) { + regex.append(Pattern.quote(smilies[i])); + regex.append("|"); + } + regex.deleteCharAt(regex.length()-1); + regex.append(")"); + Pattern smiliematcher = Pattern.compile(regex.toString()); + Matcher m = smiliematcher.matcher(text); + while (m.find()) { + Log.d("Smilies", "SID: "+mappings.get(m.group(1)).intValue()); + Log.d("Smilies", "OID: "+R.drawable.smiley_smile); + Drawable smilie = context.getResources().getDrawable(mappings.get(m.group(1)).intValue()); + smilie.setBounds(0, 0, smilie.getIntrinsicWidth(), smilie.getIntrinsicHeight()); + ImageSpan span = new ImageSpan(smilie, ImageSpan.ALIGN_BOTTOM); + text.setSpan(span, m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } + return text; + } + + /** + * Converts all smilies in a string to graphical smilies. + * + * @param text A string with smilies. + * @return A SpannableString with graphical smilies. + */ + public static SpannableString toSpannable(String text, Context context) { + return toSpannable(new SpannableString(text), context); + } +} \ No newline at end of file