Java代碼
- public static List<Map<String,Object>> getStartAndEndIndex(String sourceStr,Pattern pattern){
List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
Matcher matcher = pattern.matcher(sourceStr);
boolean isFind = matcher.find();
while (isFind) {
Map<String,Object> map = new HashMap<String, Object>();
String faceName = matcher.group().substring(1,matcher.group().length());//表情名稱
map.put("startIndex",matcher.start());
map.put("endIndex",matcher.end());
map.put("faceName",faceName);
list.add(map);
isFind = matcher.find((Integer)map.get("endIndex")-1);
}
return list;
}
復(fù)制代碼 Java代碼
- public static SpannableString decorateVipInStr(SpannableString spannable,List<Map<String,Object>> list,Resources resources){
int size = list.size();
Drawable drawable = null;
if(list!=null&&list.size()>0){
for(int i=0;i<size;i++){
Map<String,Object> map = list.get(i);
drawable = resources.getDrawable(R.drawable.vip);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
ImageSpan span = new ImageSpan(drawable,ImageSpan.ALIGN_BASELINE);
spannable.setSpan(span, (Integer)map.get("startIndex"), (Integer)map.get("endIndex"), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return spannable;
}
public static SpannableString decorateTopicInStr(SpannableString spannable,List<Map<String,Object>> list,Resources resources){
int size = list.size();
Drawable drawable = null;
CharacterStyle foregroundColorSpan=new ForegroundColorSpan(Color.argb(255, 33, 92, 110));
if(list!=null&&list.size()>0){
for(int i=0;i<size;i++){
Map<String,Object> map = list.get(i);
spannable.setSpan(foregroundColorSpan, (Integer)map.get("startIndex"), (Integer)map.get("endIndex"), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return spannable;
}
復(fù)制代碼
|