/**
* Analytic expression
* @param Giftextview
* @param content
* @return
*/
Private Spannablestringbuilder Handler (final TextView giftextview,string content) {
Spannablestringbuilder sb = new Spannablestringbuilder (content);
String regex = "(\\#\\[face/png/f_static_) \\d{3} (. png\\]\\#)";
Pattern p = pattern.compile (regex);
Matcher m = p.matcher (content);
while (M.find ()) {
String Temptext = M.group ();
try {
String num = temptext.substring ("#[face/png/f_static_". Length (), Temptext.length ()-". png]#". Length ());
String gif = "face/gif/f" + num + ". gif";
/**
* If open here does not throw an exception indicating the existence of GIF, then the corresponding GIF is displayed
* Otherwise the GIF cannot be found, the PNG is displayed
* */
InputStream is = Mcontext.getassets (). open (GIF);
Sb.setspan (New Animatedimagespan (New animatedgifdrawable) (Is,new Animatedgifdrawable.updatelistener () {
@Override
public void Update () {
Giftextview.postinvalidate ();
}
})), M.start (), M.end (),
spannable.span_exclusive_exclusive);
Is.close ();
} catch (Exception e) {
String png = temptext.substring ("#[". Length (), Temptext.length ()-"]#". Length ());
try {
Sb.setspan (New Imagespan (Mcontext, Bitmapfactory.decodestream (Mcontext.getassets (). Open (PNG)), M.start (), M.end () , spannable.span_exclusive_exclusive);
} catch (IOException E1) {
TODO auto-generated Catch block
E1.printstacktrace ();
}
E.printstacktrace ();
}
}
return SB;
}
Parse text data returned by HTML that contains emoticons