SmileyParserpublic 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 Resources | getResources()
return mRes;
| public java.lang.CharSequence | getSpannableString(android.content.Context context)Retrieves the parsed text as a spannable string object.
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;
|
|