Methods Summary |
---|
public java.lang.CharSequence | addSmileySpans(java.lang.CharSequence text)Adds ImageSpans to a CharSequence that replace textual emoticons such
as :-) with a graphical version.
SpannableStringBuilder builder = new SpannableStringBuilder(text);
Matcher matcher = mPattern.matcher(text);
while (matcher.find()) {
int resId = mSmileyToRes.get(matcher.group());
builder.setSpan(new ImageSpan(mContext, resId),
matcher.start(), matcher.end(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return builder;
|
private java.util.regex.Pattern | buildPattern()Builds the regular expression we use to find smileys in {@link #addSmileySpans}.
// Set the StringBuilder capacity with the assumption that the average
// smiley is 3 characters long.
StringBuilder patternString = new StringBuilder(mSmileyTexts.length * 3);
// Build a regex that looks like (:-)|:-(|...), but escaping the smilies
// properly so they will be interpreted literally by the regex matcher.
patternString.append('(");
for (String s : mSmileyTexts) {
patternString.append(Pattern.quote(s));
patternString.append('|");
}
// Replace the extra '|' with a ')'
patternString.replace(patternString.length() - 1, patternString.length(), ")");
return Pattern.compile(patternString.toString());
|
private java.util.HashMap | buildSmileyToRes()Builds the hashtable we use for mapping the string version
of a smiley (e.g. ":-)") to a resource ID for the icon version.
if (DEFAULT_SMILEY_RES_IDS.length != mSmileyTexts.length) {
// Throw an exception if someone updated DEFAULT_SMILEY_RES_IDS
// and failed to update arrays.xml
throw new IllegalStateException("Smiley resource ID/text mismatch");
}
HashMap<String, Integer> smileyToRes =
new HashMap<String, Integer>(mSmileyTexts.length);
for (int i = 0; i < mSmileyTexts.length; i++) {
smileyToRes.put(mSmileyTexts[i], DEFAULT_SMILEY_RES_IDS[i]);
}
return smileyToRes;
|
public static com.android.mms.util.SmileyParser | getInstance() return sInstance;
|
public static void | init(android.content.Context context)
sInstance = new SmileyParser(context);
|