From ac1a07894f64c72999053efac3c6cf9d7780c9f7 Mon Sep 17 00:00:00 2001 From: liato Date: Fri, 18 Mar 2011 04:08:21 +0100 Subject: [PATCH] Add support for graphical smilies in chat. --- application/res/drawable/smiley_cool.png | Bin 0 -> 799 bytes application/res/drawable/smiley_cry.png | Bin 0 -> 798 bytes .../res/drawable/smiley_embarassed.png | Bin 0 -> 792 bytes .../res/drawable/smiley_foot_in_mouth.png | Bin 0 -> 773 bytes application/res/drawable/smiley_frown.png | Bin 0 -> 762 bytes application/res/drawable/smiley_innocent.png | Bin 0 -> 830 bytes application/res/drawable/smiley_kiss.png | Bin 0 -> 810 bytes application/res/drawable/smiley_laughing.png | Bin 0 -> 813 bytes .../res/drawable/smiley_money_mouth.png | Bin 0 -> 775 bytes application/res/drawable/smiley_sealed.png | Bin 0 -> 792 bytes application/res/drawable/smiley_smile.png | Bin 0 -> 766 bytes application/res/drawable/smiley_surprised.png | Bin 0 -> 754 bytes .../res/drawable/smiley_tongue_out.png | Bin 0 -> 757 bytes application/res/drawable/smiley_undecided.png | Bin 0 -> 744 bytes application/res/drawable/smiley_wink.png | Bin 0 -> 759 bytes application/res/drawable/smiley_yell.png | Bin 0 -> 748 bytes application/res/values/settings.xml | 3 + application/res/values/strings.xml | 2 + application/res/xml/preferences.xml | 7 +- application/src/org/yaaic/model/Message.java | 12 ++- application/src/org/yaaic/model/Settings.java | 13 +++ .../src/org/yaaic/utils/MircColors.java | 13 ++- application/src/org/yaaic/utils/Smilies.java | 97 ++++++++++++++++++ 23 files changed, 140 insertions(+), 7 deletions(-) create mode 100644 application/res/drawable/smiley_cool.png create mode 100644 application/res/drawable/smiley_cry.png create mode 100644 application/res/drawable/smiley_embarassed.png create mode 100644 application/res/drawable/smiley_foot_in_mouth.png create mode 100644 application/res/drawable/smiley_frown.png create mode 100644 application/res/drawable/smiley_innocent.png create mode 100644 application/res/drawable/smiley_kiss.png create mode 100644 application/res/drawable/smiley_laughing.png create mode 100644 application/res/drawable/smiley_money_mouth.png create mode 100644 application/res/drawable/smiley_sealed.png create mode 100644 application/res/drawable/smiley_smile.png create mode 100644 application/res/drawable/smiley_surprised.png create mode 100644 application/res/drawable/smiley_tongue_out.png create mode 100644 application/res/drawable/smiley_undecided.png create mode 100644 application/res/drawable/smiley_wink.png create mode 100644 application/res/drawable/smiley_yell.png create mode 100644 application/src/org/yaaic/utils/Smilies.java diff --git a/application/res/drawable/smiley_cool.png b/application/res/drawable/smiley_cool.png new file mode 100644 index 0000000000000000000000000000000000000000..99af6c2e42bbb1317315bcb5b48e8ae1c6f7309d GIT binary patch literal 799 zcmV+)1K|9LP)xPAi#-v+z?hq3b7bN}_Y;ScJdGp?L0U?0Ig`UM- zoZQ^p-1|F32!a2Ra^9F2iPuQ7G9;@N{mi9303a*sETc}6GxycNaQfhMKRLa@#7O*( ztf*sw)+@e1OQ%+?2LS*@Gmo9M@Al4*Z->mKg9F3qsgnVTL}G$HgbU8+lx#K|&70<@j-cp^v|WO(`%zV;!J{eQjKgwVlr0x!+eNudaj;)R zK5OvxeR(e6_jk%3kEdOg_$^(p_EgvUh$IOR!T~Ta?t)SZhf+8Wh3!zdT)?s%vRf$n z3cGt_#P9d}d|t(DiC$LQV2aUGH*p(7TC<1knbgJmmv*6zsk>FuWF&@W`vsp@Omq-w6Ki28X2V$g)3BaUTsIQXkl|RkGx^v#bC^C zYpkr40HC|o$5U?~q9dYUZgvjI51$e52_p6G5vC`fpet5`smTZ&^J4n_W5mK$ z{N#nT&%gp3H``z+ziGPYWDt@i{i)FiAbwI(%HyM%0v(?rX)68UNbTS3; zcv$$Otb$;%WxHb%KpMu8+>(}fI-5d@+W$^En(%*1=cVk`Lrgd4KR95onWs)$2mc$UFgCjkg zk3Bdq0hF(bUSFy9@2e;`9-7?m{fcM9v5)Lu@0rcc?_2r3Cym!vswrO;>k_rronC)w zqO+@sZ5tNT@m(vYZ%uXK(y1;0c5QskmEvQzt$L2vUz*Tbch&)x?Uq%bI(of^Fu!~O zW-?B%7ej}z^UziRcC35N&q(Q)Og?UwD{n^xryxq5hWV`K8oZ}E8a+feH@07A;Y{o3Rm;GAW<6aU?x c2Kdsv2Rn2sBcOYx4*&oF07*qoM6N<$g5bMziU0rr literal 0 HcmV?d00001 diff --git a/application/res/drawable/smiley_embarassed.png b/application/res/drawable/smiley_embarassed.png new file mode 100644 index 0000000000000000000000000000000000000000..2fe2a87aa0530e44103da759d82a8e0f33684a56 GIT binary patch literal 792 zcmV+z1LypSP)CWiBLLlv#?#Ygj7b`x_UizE&JI{=dS#k z#i!>_^F~1*h{n{%B|st`aSBEGeBeZPQ++7B-T^&9h~Vn*5OC%-bw^~ z0B1TP?LLH>D&g}IIMdkdC=ri1BmfYRLBmfrTSK6U3 z<+1uY1u|{8!#;q(0SE~IT=2KKOs>bh23YSG0nNll!GyDWU+H;zDhqpR2~4-Jys`$V z$W-t3aZLh%Su{t|GYiL?YwBGD0w=<&@g$bj$r9jX=OMT_0|djWrdc-8SSg7_bZ6oF z{Iy_nz~wj^gyK=q-_!w!GDnLxHfmQ;FpBu8PU)6yZ@LhTsjHT0ou3?=+@N|VJYgS% zLqZ6#*=_|a=s`01C2xbSMq}#CPEkHBq`2SEx~C!#3OcKNRbZTBEtA9IkF=TkIHTK^ zeYyX}#Jz1%E`#hAiWuTToU)2$8-ch~|{riHUf6n|p_7(4k2bZ~R*J`?%q5wcC z?I{gcdzFv^O48`>GthU>03~TqlE$M4gLrs<0FYVJT^W9b9B0Z%fl5e=8)O|Kr$jKp^VnciW`(z0Du!}6$C^9t4$#Y z@f*vE8{D?*jfhG%V-%o-2>=`b(B0jbpLi2@bsgV<2@`E@HIH>CJC8WGjcBzB!j ztd(c&L;0Re=4>A2Hou|i=JIy_E`cI30sxwB{+09#2`CS#fgL9I00000NkvXXu0mjf Di&0MJ literal 0 HcmV?d00001 diff --git a/application/res/drawable/smiley_frown.png b/application/res/drawable/smiley_frown.png new file mode 100644 index 0000000000000000000000000000000000000000..0c19ffe1b5a51e2488bec1e62099f6af38f546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}B)_K#Xz(qv40| z=h^ZDrl!VGDh433A(y_sNvplR({}_E0%#>7{P@X>-#q=oiMIlVdT0B4u~d~^NJ&3dKw zzaQu}yDZ;W3Zh>0?!G{=R1R!t-}&vz&2FPw-yfcxUE$)zUl0)h+M6xrE|)uE<^5u* zybPfBNPwB?$yc(^b literal 0 HcmV?d00001 diff --git a/application/res/drawable/smiley_kiss.png b/application/res/drawable/smiley_kiss.png new file mode 100644 index 0000000000000000000000000000000000000000..48250b5e2de7016d5e00b60c8e247ec68efb560f GIT binary patch literal 810 zcmV+_1J(SAP)Xchq4STZVT|@G zU7R?y5&w!BhoY*@04ji@DUCk=0*4e?P9Ix0$+QmWw4T^7X=Y;i7dYav&sz!rQ#Tsi zo)VBk7|V}tW$FI)0JuFRn7UCL2?wME5JH%iWdasp@&3$1 zN`I=1yy#=F>k~esjGp!B7vWRfZ3*+ItAX)@_F-_mi+ zyw2VF)8vNIq=rXPG_^MvicSCw-RMkwiRS>ebR48;u8UgVGFJQ7u(oDB4T~F)s>0r$ z7K%M{NPLNpo4Wa|a0Sb>E+)SY{2ux~5wb-)>PU_y5tS9lC5!p-s~>N`55P$OF#WOb z8Ot==rUq%Vs;QBc+g3T8D odM^JIxE2gWMb&i+p}P!kf(Jto!OPfThk-|7_*RC37^bq}Zia1E5o}A*YN}0|cBYkR(mc=e z-=Pp++8+E}zVPGAhc92g!WhG9mrTS2AnbU`Tg@Zh1tb%(fK>Xp)YhQqEOr`$RF*aF zx$Z5`DW9_Asm!W?WFod(Y3ppLZS$JC=60Vy6hTPEi`+DG>4|b?{9e&@o$u`vw|`v* zNG4)KmhXe#w(k0BO(4>^V%!(AGu*#`ZfY^_wGY3UHA*F6<-c^v-t4Ng6ot!?071p0fdxCL(Pr;{{-wmFaW@lCmFW& zZvbFEpXcjCA0wq8ot`7QrM-IU!PrUQI}M<#^kBHP-q+LiQ6+AFUl@1=z!#slR{lNR zbv&QWSx-mDKLyYLp5ykc3;4KxW*B%~szD)eE4q|cvFn>5T*qliCSsNZ5JI?03)TjM zbRGDKdo_F6@k5faz&^Gexm?k$`+vk=7Xsq}!T{b9K*^E(OrBsQz(RV2rlzL1+OMsx z1q6lcD1q===5u+pr6%ln%9Q|4seC>ADD!GVXN2iH!*oTLy4ctjMM_0SdnaBo&$E9n z(y*zXnaS*;=XrkuNC0EZ&$Cmr&r5|O9RpEjZ=L4Z-{i6!?dTVr*CO0`p_Hho+bqP0z3Afatlw{=Qzc0(B@$r#Pcz#g3=u-}Em7yzl)F1xFyg1+BvM00000NkvXXu0mjfMSh0W literal 0 HcmV?d00001 diff --git a/application/res/drawable/smiley_money_mouth.png b/application/res/drawable/smiley_money_mouth.png new file mode 100644 index 0000000000000000000000000000000000000000..183315fc53eddd720a7925b393e491e74bcb2a39 GIT binary patch literal 775 zcmV+i1Ni)jP)_i(Nvr9`o_Oicj*-AEKQDSrbjQ>!G5_fp22g}vDT0F-+^3CE7Rj(t}* z601c4mZ@E&j1LD79VzwK99GNxK>$EHwT#sK*WB{#Oh!0%hi)WZ@wbnlXmZ=3OW5bQjExuBJIi9Z`#Es4Y z5G4zuWFbTbvDE{(ZN|{p+~T8*4O^xbC;$khy`lO#Z~5MGbVY{1IK^PJqY&~3WMSK)pbg&N(zd)#gJo(8``v|<(uK+uJb8Qx z0Kho~;DYa z00>*em%c5A`})q7`L zTTG`GlKFjsQ3{o*V3dK9!d#GANMdPjG3~l;e*vHyi8bMf_Q~;y_0;zy014p=*kTjH zwexRAa$yCN;}h$`5$(E>SlemJr=_ZlJ`8-Q;*>#A@(lyFaL~DOY+2aivTh{a<}*8e zrqVReb$hwzj1)2q018#6HtfweWwtt?8;Q(z|385Ly;n(-@*U@002ovPDHLk FV1h!fQ#$|v literal 0 HcmV?d00001 diff --git a/application/res/drawable/smiley_sealed.png b/application/res/drawable/smiley_sealed.png new file mode 100644 index 0000000000000000000000000000000000000000..5cc596ac49a80fbb5d479011973ec7010a217f56 GIT binary patch literal 792 zcmV+z1LypSP)JsXKERg%x@HAB*lP#duLO@9Y)ixs(Sw2+U!O(;DT*swOgRZ=+m{nCZP)dqgmQ`>Z1pr8* zgwcVK->Rw_H~?TA`;bnh{kBFsdhdQgTbmEjXdHgO7qQqheBM?>r#5x(nGDub88DtD zPTiVRDF7(4GP;yZi2%@X{3v2m(`adJfgr?jq`4VFG!C!Ni)3;R{jV7olFO2+sN2qH zW*kfSd)lk3oNWNvjG`zS7zGp+U=--R`3l)w0cQ_na~8Vl4u*uq(jxWf%FCYnPPZFP zR@0sxcrvIVonvSaW7jU;8GN*@iCd6!jAQ-v9;dQ_{pIleS77 zX^yXO_4W1TcLBB_R*vWH5k@;@QQE)NlZ2*fZ)Hio9}Ec#rT$%j9WVxf1Ve)SH_so+ WRvw>Qh4UT&0000|5%b1CV{ zo0|qH+}ClosI2(Tfn$eucxpTV0N2g;7$X3{Qv3(T!f#V{);_Hp)}u`V0APl+GYVJk z*0(j3`kMkpl|B!olt?C4Fh3p7&P{z=6}Gsb83)9Bf=MSm;g7c=JW+W*9P)4tL z>g!xpwQf+7!IQ^f3=NKfk_;%xV0h>mMjt%~B^gxuDsZ^Dv4kq@1^`e1V5)l7(@^cC z!~`WKUcH>g*LxbOqy1H`o_jiC0f>b<-i2flhxVRM5j5T2ID4%C4yYFkRE%o@l z4%Z=)yzj&N^Sq2@S@<82-viM|(7|$~hqIMQ)XC-+mk;cgj@mbQ z>ep>IFVEv`?4e?4>WNS|K2#KlMuK%5A=7)>57*Xux2#)iSr!;Eh+du}L;?V2=xTsr zId*TNF@dXHg+Ki(F2~8Z~GP09XJpso9sDnpd(58893R*BL*u&!1v7orXF$hr-xP z2R9t12Di+rhrspQIiwNWvbKltz07FU^%vj*oZ_8 n`s10nNkcbcCN(#HrhmbAD1jI{Ti@mM00000NkvXXu0mjf(Wgy| literal 0 HcmV?d00001 diff --git a/application/res/drawable/smiley_undecided.png b/application/res/drawable/smiley_undecided.png new file mode 100644 index 0000000000000000000000000000000000000000..40ccef308b89dcf77e0649019054fb031f76c251 G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oLELIy08}e8e4HJyF=5Bp^YBe{u{%=fL{=WdrV-hj^)&YU<;Bs?O67J>$nd! p-AHX!mh*pF|NWC}w>;+@zX20tHjTjA8L9vP002ovPDHLkV1gmNQBeQ@ literal 0 HcmV?d00001 diff --git a/application/res/drawable/smiley_yell.png b/application/res/drawable/smiley_yell.png new file mode 100644 index 0000000000000000000000000000000000000000..1ffd6fdb9e7706a9d24161ce9706aa6d97fef12a GIT binary patch literal 748 zcmVP|(U+45>J+ie6BI3K=t*R;2GaPJWKQdGFra!g0`a z7X9Ju&i}{Zf6gINN|aL~79{|n=|7q<&=Z<{{5`-$=FM_+n+;#40 zx{)mlNW`LNC{v!+H60GsH0<++sv`h^<(!4NADM!g9?f&txu)qx|29A(7VS{{{^v*9 zJJel~`W?qzoHa2v_$>b=mUTHxf;6*(C0jbna0KlKz3bfW%uldc>TFT(fotEX3oo%Ww=m!8e zE(eO)axNi+00_X8Ac(X9A&~4Fu!Rso1^|RWNGTw}koTX*jm~rHkWEq;#e?`OgzP>P z);K^Q0Lb+W7#&-%=0S*n58un(4E!Vm09df*K^Yy_bYmUB3+}+o#Pk{@2XoV90nGgh z05B(JY{A7)X$wM#`_`nnnEhn|ZWgt5>Naz@IsmwH$W6~-dgAvIclq5?h{ant#k{Ql zXnV8jDn7)YrI5~K;kp8i4Pjimd<+$eKx**Qieo!xHQgB80w_XGP=&p$-BVi`*}L0c zQBwga36^pTuqI90nlcx;!!KyM@pi+r(=(}rkn4(1InB9f1|;!N`q?cwLsG~dO*fV{ e_iqFIul@qtY9-)P8E#1c0000mirc_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