作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嘿,我有一些问题要找到那个笑脸代码的确切 Imotion(Facebook)..我放了我的 Snippat 代码:
private static final HashMap<String, Integer> smilyRegexMap = new HashMap<String, Integer>();
static{
smilyRegexMap.put( ":-)" , R.drawable.fb_smile);
smilyRegexMap.put( ":)",R.drawable.fb_smile);
smilyRegexMap.put( ":-]" , R.drawable.fb_smile);
smilyRegexMap.put( ":-(", R.drawable.fb_frown);
smilyRegexMap.put( ":(" , R.drawable.fb_frown);
smilyRegexMap.put( ":-[" , R.drawable.fb_frown);
smilyRegexMap.put( ":-P" , R.drawable.fb_tounge);
smilyRegexMap.put( ":p", R.drawable.fb_tounge);
smilyRegexMap.put( ":-D" , R.drawable.fb_grin);
smilyRegexMap.put( ":D" , R.drawable.fb_grin);
smilyRegexMap.put( ":-O" , R.drawable.fb_gasp);
smilyRegexMap.put( ":*" , R.drawable.fb_gasp);
smilyRegexMap.put( ";-)" , R.drawable.fb_wink);
smilyRegexMap.put( ";)" , R.drawable.fb_wink);
smilyRegexMap.put( ":putnam:" , R.drawable.fb_putnam);
}
//=========================================== ============
public static CharSequence addSmileySpans(Context ch, CharSequence your_recieved_message)
{
//smilyRegexMap = new HashMap<Integer, String>();
System.out.println("==In Spannable Function..........");
SpannableStringBuilder builder = new SpannableStringBuilder(your_recieved_message);
System.out.println("==================Size of Smily : "+ smilyRegexMap.size());
@SuppressWarnings("rawtypes")
Iterator it = smilyRegexMap.entrySet().iterator();
while (it.hasNext()) {
@SuppressWarnings("rawtypes")
Map.Entry pairs = (Map.Entry) it.next();
Pattern mPattern = Pattern.compile((String) pairs.getKey(),Pattern.CASE_INSENSITIVE);
Matcher matcher = mPattern.matcher(your_recieved_message);
while (matcher.find()) {
Bitmap smiley = BitmapFactory.decodeResource(ch.getResources(), ((Integer) pairs.getValue()));
builder.setSpan(new ImageSpan(smiley), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return builder;
}
我已经调用了这个函数:
addSmileySpans(this,"Hi i m Happy :-) ;-) :p :putnam: ");
===>> 我的问题是,当我输入 :putnam: 时,结果如下
嗨,我很高兴
//===========================================
Ookeyyy...现在我使用此代码:::
Bitmap smiley = BitmapFactory.decodeResource(ch.getResources(), ((Integer) pairs.getValue()));
Object[] spans = builder.getSpans(matcher.start(), matcher.end(), ImageSpan.class);
if (spans == null || spans.length == 0) {
builder.setSpan(new ImageSpan(smiley), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
但是它给出了一些错误::
当输入 :putnam:它的结果是 乌特南:
最佳答案
Object[] spans = builder.getSpans(matcher.start(), matcher.end(), Object.class);
if (spans == null || spans.length == 0) {
//add new image span here
}
关于java - 如何在聊天应用程序中简单地匹配确切的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11538522/
我是一名优秀的程序员,十分优秀!