use of com.easemob.chat.TextMessageBody in project wechat by motianhuo.
the class MessageAdapter method handleTextMessage.
/**
* 文本消息
*
* @param message
* @param holder
* @param position
*/
private void handleTextMessage(EMMessage message, ViewHolder holder, final int position) {
TextMessageBody txtBody = (TextMessageBody) message.getBody();
Spannable span = SmileUtils.getSmiledText(context, txtBody.getMessage());
// 设置内容
holder.tv.setText(span, BufferType.SPANNABLE);
// 设置长按事件监听
holder.tv.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
activity.startActivityForResult((new Intent(activity, ContextMenu.class)).putExtra("position", position).putExtra("type", EMMessage.Type.TXT.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
return true;
}
});
if (message.direct == EMMessage.Direct.SEND) {
switch(message.status) {
case // 发送成功
SUCCESS:
holder.pb.setVisibility(View.GONE);
holder.staus_iv.setVisibility(View.GONE);
break;
case // 发送失败
FAIL:
holder.pb.setVisibility(View.GONE);
holder.staus_iv.setVisibility(View.VISIBLE);
break;
case // 发送中
INPROGRESS:
holder.pb.setVisibility(View.VISIBLE);
holder.staus_iv.setVisibility(View.GONE);
break;
default:
// 发送消息
sendMsgInBackground(message, holder);
}
}
}
use of com.easemob.chat.TextMessageBody in project wechat by motianhuo.
the class CommonUtils method getMessageDigest.
/**
* 根据消息内容和消息类型获取消息内容提示
*
* @param message
* @param context
* @return
*/
public static String getMessageDigest(EMMessage message, Context context) {
String digest = "";
switch(message.getType()) {
case // 位置消息
LOCATION:
if (message.direct == EMMessage.Direct.RECEIVE) {
// 从sdk中提到了ui中,使用更简单不犯错的获取string方法
// digest = EasyUtils.getAppResourceString(context,
// "location_recv");
digest = getStrng(context, R.string.location_recv);
digest = String.format(digest, message.getFrom());
return digest;
} else {
// digest = EasyUtils.getAppResourceString(context,
// "location_prefix");
digest = getStrng(context, R.string.location_prefix);
}
break;
case // 图片消息
IMAGE:
digest = getStrng(context, R.string.picture);
break;
case // 语音消息
VOICE:
digest = getStrng(context, R.string.voice);
break;
case // 视频消息
VIDEO:
digest = getStrng(context, R.string.video);
break;
case // 文本消息
TXT:
if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) {
TextMessageBody txtBody = (TextMessageBody) message.getBody();
digest = txtBody.getMessage();
} else {
TextMessageBody txtBody = (TextMessageBody) message.getBody();
digest = getStrng(context, R.string.voice_call) + txtBody.getMessage();
}
break;
case // 普通文件消息
FILE:
digest = getStrng(context, R.string.file);
break;
default:
System.err.println("error, unknow type");
return "";
}
return digest;
}
Aggregations