Parse text data returned by HTML that contains emoticons

Source: Internet
Author: User

/**
* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.