基于socket实现了一个简单的聊天功能,服务器就是java上写的。
插入表情是用html实现的实现的就是这样的 CharSequence cs = Html.fromHtml("<img src='" + m.get("face")
+ "'/>", imageGetter, null);
int cursor = etMsg.getSelectionStart();
etMsg.getText().insert(cursor, cs);
那怎么能比较好的判断我收到的信息是否包含表情,然后怎么再将图片替换上去。说明一下,客户端都有一样的表情图片,id也是一样的。
不知道我说明白了没有,哪儿不清楚可以再提出来,我再补充。
插入表情是用html实现的实现的就是这样的 CharSequence cs = Html.fromHtml("<img src='" + m.get("face")
+ "'/>", imageGetter, null);
int cursor = etMsg.getSelectionStart();
etMsg.getText().insert(cursor, cs);
那怎么能比较好的判断我收到的信息是否包含表情,然后怎么再将图片替换上去。说明一下,客户端都有一样的表情图片,id也是一样的。
不知道我说明白了没有,哪儿不清楚可以再提出来,我再补充。
其次这样我发送的时候需要用一个map来存储每一个表情对应的字符串和id,这样我才能把一个图片的id变为一个特定字符串发送出去,当我接收的时候,我还需要一个map存储key(图片id)value(对应字符串),这样我才能知道要用哪个图片去代替它
还有就是我用什么方法去检索,我这一句话里有没有表情图片,一句话里可能插入多个图片。
不知道是不是我想多了,但这样我觉得这样很麻烦,不容易实现。
@Override
public void setText(CharSequence text, BufferType type) {
this.text = text;
if(text == null) {
super.setText(text);
return;
}
String face = BaseStringUtil.parseFaceString(text.toString());
Spanned span = Html.fromHtml(face, new Html.ImageGetter() {
@Override
public Drawable getDrawable(String source) {
Drawable drawable = null;
String sourceName = getContext().getPackageName() + ":drawable/"
+ source;
int id = getResources().getIdentifier(sourceName, null, null);
if (id != 0) {
drawable = getResources().getDrawable(id);
if (drawable != null) {
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
}
}
return drawable;
}
}, null);
super.setText(span, type);
}
重写的setText方法