FileDocCategorySizeDatePackage
SmileyParser.javaAPI DocAndroid 1.5 API2625Wed May 06 22:41:56 BST 2009com.google.android.util

SmileyParser

public class SmileyParser extends AbstractMessageParser
Parses a text message typed by the user looking for smileys.

Fields Summary
private SmileyResources
mRes
Constructors Summary
public SmileyParser(String text, SmileyResources res)

        super(text,
                true,   // smilies
                false,  // acronyms
                false,  // formatting
                false,  // urls
                false,  // music
                false   // me text
        );
        mRes = res;
    
Methods Summary
protected ResourcesgetResources()

        return mRes;
    
public java.lang.CharSequencegetSpannableString(android.content.Context context)
Retrieves the parsed text as a spannable string object.

param
context the context for fetching smiley resources.
return
the spannable string as CharSequence.

        SpannableStringBuilder builder = new SpannableStringBuilder();

        if (getPartCount() == 0) {
            return "";
        }

        // should have only one part since we parse smiley only
        Part part = getPart(0);
        ArrayList<Token> tokens = part.getTokens();
        int len = tokens.size();
        for (int i = 0; i < len; i++) {
            Token token = tokens.get(i);
            int start = builder.length();
            builder.append(token.getRawText());
            if (token.getType() == AbstractMessageParser.Token.Type.SMILEY) {
                int resid = mRes.getSmileyRes(token.getRawText());
                if (resid != -1) {
                    builder.setSpan(new ImageSpan(context, resid),
                            start,
                            builder.length(),
                            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }
        return builder;