use of com.easemob.chat.TextMessageBody in project wechat by motianhuo.
the class CallActivity method saveCallRecord.
/**
* 保存通话消息记录
*
* @param type
* 0:音频,1:视频
*/
protected void saveCallRecord(int type) {
EMMessage message = null;
TextMessageBody txtBody = null;
if (!isInComingCall) {
// 打出去的通话
message = EMMessage.createSendMessage(EMMessage.Type.TXT);
message.setReceipt(username);
} else {
message = EMMessage.createReceiveMessage(EMMessage.Type.TXT);
message.setFrom(username);
}
String st1 = getResources().getString(R.string.call_duration);
String st2 = getResources().getString(R.string.Refused);
String st3 = getResources().getString(R.string.The_other_party_has_refused_to);
String st4 = getResources().getString(R.string.The_other_is_not_online);
String st5 = getResources().getString(R.string.The_other_is_on_the_phone);
String st6 = getResources().getString(R.string.The_other_party_did_not_answer);
String st7 = getResources().getString(R.string.did_not_answer);
String st8 = getResources().getString(R.string.Has_been_cancelled);
switch(callingState) {
case NORMAL:
txtBody = new TextMessageBody(st1 + callDruationText);
break;
case REFUESD:
txtBody = new TextMessageBody(st2);
break;
case BEREFUESD:
txtBody = new TextMessageBody(st3);
break;
case OFFLINE:
txtBody = new TextMessageBody(st4);
break;
case BUSY:
txtBody = new TextMessageBody(st5);
break;
case NORESPONSE:
txtBody = new TextMessageBody(st6);
break;
case UNANSWERED:
txtBody = new TextMessageBody(st7);
break;
default:
txtBody = new TextMessageBody(st8);
break;
}
// 设置扩展属性
if (type == 0)
message.setAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, true);
else
message.setAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, true);
// 设置消息body
message.addBody(txtBody);
message.setMsgId(msgid);
// 保存
EMChatManager.getInstance().saveMessage(message, false);
}
use of com.easemob.chat.TextMessageBody in project wechat by motianhuo.
the class ChatActivity method sendText.
/**
* 发送文本消息
*
* @param content
* message content
* @param isResend
* boolean resend
*/
private void sendText(String content) {
if (content.length() > 0) {
EMMessage message = EMMessage.createSendMessage(EMMessage.Type.TXT);
// 如果是群聊,设置chattype,默认是单聊
if (chatType == CHATTYPE_GROUP)
message.setChatType(ChatType.GroupChat);
TextMessageBody txtBody = new TextMessageBody(content);
// 设置消息body
message.addBody(txtBody);
// 设置要发给谁,用户username或者群聊groupid
message.setReceipt(toChatUsername);
// 把messgage加到conversation中
conversation.addMessage(message);
// 通知adapter有消息变动,adapter会根据加入的这条message显示消息和调用sdk的发送方法
adapter.refresh();
listView.setSelection(listView.getCount() - 1);
mEditTextContent.setText("");
setResult(RESULT_OK);
}
}
use of com.easemob.chat.TextMessageBody in project wechat by motianhuo.
the class ChatActivity method forwardMessage.
/**
* 转发消息
*
* @param forward_msg_id
*/
protected void forwardMessage(String forward_msg_id) {
EMMessage forward_msg = EMChatManager.getInstance().getMessage(forward_msg_id);
EMMessage.Type type = forward_msg.getType();
switch(type) {
case TXT:
// 获取消息内容,发送消息
String content = ((TextMessageBody) forward_msg.getBody()).getMessage();
sendText(content);
break;
case IMAGE:
// 发送图片
String filePath = ((ImageMessageBody) forward_msg.getBody()).getLocalUrl();
if (filePath != null) {
File file = new File(filePath);
if (!file.exists()) {
// 不存在大图发送缩略图
filePath = ImageUtils.getThumbnailImagePath(filePath);
}
sendPicture(filePath);
}
break;
default:
break;
}
}
use of com.easemob.chat.TextMessageBody in project wechat by motianhuo.
the class NewMsgAdpter method getMessageDigest.
/**
* 根据消息内容和消息类型获取消息内容提示
*
* @param message
* @param context
* @return
*/
private String getMessageDigest(EMMessage message, Context context) {
String digest = "";
switch(message.getType()) {
case // 位置消息
LOCATION:
if (message.direct == EMMessage.Direct.RECEIVE) {
digest = getStrng(context, R.string.location_recv);
String name = message.getFrom();
if (GloableParams.UserInfos != null) {
User user = GloableParams.Users.get(message.getFrom());
if (user != null && null != user.getUserName())
name = user.getUserName();
}
digest = String.format(digest, name);
return digest;
} else {
digest = getStrng(context, R.string.location_prefix);
}
break;
case // 图片消息
IMAGE:
ImageMessageBody imageBody = (ImageMessageBody) message.getBody();
digest = getStrng(context, R.string.picture) + imageBody.getFileName();
break;
case // 语音消息
VOICE:
digest = getStrng(context, R.string.voice_msg);
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;
}
use of com.easemob.chat.TextMessageBody in project wechat by motianhuo.
the class MessageAdapter method handleCallMessage.
/**
* 音视频通话记录
*
* @param message
* @param holder
* @param position
*/
private void handleCallMessage(EMMessage message, ViewHolder holder, final int position) {
TextMessageBody txtBody = (TextMessageBody) message.getBody();
holder.tv.setText(txtBody.getMessage());
}
Aggregations