本文整理汇总了Java中com.easemob.chat.EMMessage.Type类的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于com.easemob.chat.EMMessage包,在下文中一共展示了Type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onApplicationAccept
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
@Override
public void onApplicationAccept(String groupId, String groupName, String accepter) {
//加群申请被同意
EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
msg.setChatType(ChatType.GroupChat);
msg.setFrom(accepter);
msg.setTo(groupId);
msg.setMsgId(UUID.randomUUID().toString());
msg.addBody(new TextMessageBody(accepter + "同意了你的群聊申请"));
// 保存同意消息
EMChatManager.getInstance().saveMessage(msg);
// 提醒新消息
EMNotifier.getInstance(getApplicationContext()).notifyOnNewMsg();
runOnUiThread(new Runnable() {
public void run() {
updateUnreadLabel();
// 刷新ui
if (currentTabIndex == CHATHISTORYFRAGMENT)
chatHistoryFragment.refresh();
if (CommonUtils.getTopActivity(MainActivity_0903.this).equals(GroupsActivity.class.getName())) {
GroupsActivity.instance.onResume();
}
}
});
}
示例2: onApplicationAccept
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
@Override
public void onApplicationAccept(String groupId, String groupName, String accepter) {
//加群申请被同意
EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
msg.setChatType(ChatType.GroupChat);
msg.setFrom(accepter);
msg.setTo(groupId);
msg.setMsgId(UUID.randomUUID().toString());
msg.addBody(new TextMessageBody(accepter + "同意了你的群聊申请"));
// 保存同意消息
EMChatManager.getInstance().saveMessage(msg);
// 提醒新消息
EMNotifier.getInstance(getApplicationContext()).notifyOnNewMsg();
runOnUiThread(new Runnable() {
public void run() {
updateUnreadLabel();
// 刷新ui
if (currentTabIndex == CHATHISTORYFRAGMENT)
chatHistoryFragment.refresh();
if (CommonUtils.getTopActivity(MainActivity.this).equals(GroupsActivity.class.getName())) {
GroupsActivity.instance.onResume();
}
}
});
}
示例3: onApplicationAccept
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
@Override
public void onApplicationAccept(String groupId, String groupName, String accepter) {
String st4 = appContext.getString(R.string.Agreed_to_your_group_chat_application);
// 加群申请被同意
EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
msg.setChatType(ChatType.GroupChat);
msg.setFrom(accepter);
msg.setTo(groupId);
msg.setMsgId(UUID.randomUUID().toString());
msg.addBody(new TextMessageBody(accepter + " " +st4));
// 保存同意消息
EMChatManager.getInstance().saveMessage(msg);
// 提醒新消息
getNotifier().viberateAndPlayTone(msg);
broadcastManager.sendBroadcast(new Intent(Constant.ACTION_GROUP_CHANAGED));
}
示例4: onApplicationAccept
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
@Override
public void onApplicationAccept(String groupId, String groupName, String accepter) {
String st4 = appContext.getString(R.string.Agreed_to_your_group_chat_application);
// 加群申请被同意
EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
msg.setChatType(ChatType.GroupChat);
msg.setFrom(accepter);
msg.setTo(groupId);
msg.setMsgId(UUID.randomUUID().toString());
msg.addBody(new TextMessageBody(accepter + " " + st4));
// 保存同意消息
EMChatManager.getInstance().saveMessage(msg);
// 提醒新消息
getNotifier().viberateAndPlayTone(msg);
broadcastManager.sendBroadcast(new Intent(Constant.ACTION_GROUP_CHANAGED));
}
示例5: getItemViewType
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
public int getItemViewType(int position) {
EMMessage message = conversation.getMessage(position);
//String attr = message.getStringAttribute("attr",null);//获取扩展属性
if (message.getType() == EMMessage.Type.TXT) {
/*if(!CommonUtils.isNullOrEmpty(attr)){//判断扩展属性是否为空
if(attr.equals("card")){//判断扩展属性是否是名片
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_FILE : MESSAGE_TYPE_SENT_FILE;
}
}*/
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_TXT : MESSAGE_TYPE_SENT_TXT;
}
if (message.getType() == EMMessage.Type.IMAGE) {
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_IMAGE : MESSAGE_TYPE_SENT_IMAGE;
}
if (message.getType() == EMMessage.Type.LOCATION) {
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_LOCATION : MESSAGE_TYPE_SENT_LOCATION;
}
if (message.getType() == EMMessage.Type.VOICE) {
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_VOICE : MESSAGE_TYPE_SENT_VOICE;
}
if (message.getType() == EMMessage.Type.VIDEO) {
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_VIDEO : MESSAGE_TYPE_SENT_VIDEO;
}
if (message.getType() == EMMessage.Type.FILE) {
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_FILE : MESSAGE_TYPE_SENT_FILE;
}
return -1;// invalid
}
示例6: handleTextMessage
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
/**
* 文本消息
*
* @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);
break;
default:
sendMsgInBackground(message, holder);
}
}
}
示例7: handleLocationMessage
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
/**
* 处理位置消息
*
* @param message
* @param holder
* @param position
* @param convertView
*/
private void handleLocationMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) {
TextView locationView = ((TextView) convertView.findViewById(R.id.tv_location));
LocationMessageBody locBody = (LocationMessageBody) message.getBody();
locationView.setText(locBody.getAddress());
LatLng loc = new LatLng(locBody.getLatitude(), locBody.getLongitude());
locationView.setOnClickListener(new MapClickListener(loc, locBody.getAddress()));
locationView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
activity.startActivityForResult(
(new Intent(activity, ContextMenu.class)).putExtra("position", position).putExtra("type",
EMMessage.Type.LOCATION.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
return false;
}
});
if (message.direct == EMMessage.Direct.RECEIVE) {
return;
}
// deal with send message
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);
break;
default:
sendMsgInBackground(message, holder);
}
}
示例8: updateSendedView
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
/**
* 更新ui上消息发送状态
*
* @param message
* @param holder
*/
private void updateSendedView(final EMMessage message, final ViewHolder holder) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// send success
if (message.getType() == EMMessage.Type.VIDEO) {
holder.tv.setVisibility(View.GONE);
}
if (message.status == EMMessage.Status.SUCCESS) {
if (message.getType() == EMMessage.Type.FILE) {
holder.pb.setVisibility(View.INVISIBLE);
holder.staus_iv.setVisibility(View.INVISIBLE);
} else {
holder.pb.setVisibility(View.GONE);
holder.staus_iv.setVisibility(View.GONE);
}
} else if (message.status == EMMessage.Status.FAIL) {
if (message.getType() == EMMessage.Type.FILE) {
holder.pb.setVisibility(View.INVISIBLE);
} else {
holder.pb.setVisibility(View.GONE);
}
holder.staus_iv.setVisibility(View.VISIBLE);
Toast.makeText(activity, activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0)
.show();
}
}
});
}
示例9: onInvitationReceived
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
@Override
public void onInvitationReceived(String groupId, String groupName, String inviter, String reason) {
boolean hasGroup = false;
for(EMGroup group : EMGroupManager.getInstance().getAllGroups()){
if(group.getGroupId().equals(groupId)){
hasGroup = true;
break;
}
}
if(!hasGroup)
return;
// 被邀请
EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
msg.setChatType(ChatType.GroupChat);
msg.setFrom(inviter);
msg.setTo(groupId);
msg.setMsgId(UUID.randomUUID().toString());
msg.addBody(new TextMessageBody(inviter + "邀请你加入了群聊"));
// 保存邀请消息
EMChatManager.getInstance().saveMessage(msg);
// 提醒新消息
EMNotifier.getInstance(getApplicationContext()).notifyOnNewMsg();
runOnUiThread(new Runnable() {
public void run() {
updateUnreadLabel();
// 刷新ui
if (currentTabIndex == CHATHISTORYFRAGMENT)
chatHistoryFragment.refresh();
if (CommonUtils.getTopActivity(MainActivity_0903.this).equals(GroupsActivity.class.getName())) {
GroupsActivity.instance.onResume();
}
}
});
}
示例10: onInvitationReceived
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
@Override
public void onInvitationReceived(String groupId, String groupName, String inviter, String reason) {
boolean hasGroup = false;
for(EMGroup group : EMGroupManager.getInstance().getAllGroups()){
if(group.getGroupId().equals(groupId)){
hasGroup = true;
break;
}
}
if(!hasGroup)
return;
// 被邀请
EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
msg.setChatType(ChatType.GroupChat);
msg.setFrom(inviter);
msg.setTo(groupId);
msg.setMsgId(UUID.randomUUID().toString());
msg.addBody(new TextMessageBody(inviter + "邀请你加入了群聊"));
// 保存邀请消息
EMChatManager.getInstance().saveMessage(msg);
// 提醒新消息
EMNotifier.getInstance(getApplicationContext()).notifyOnNewMsg();
runOnUiThread(new Runnable() {
public void run() {
updateUnreadLabel();
// 刷新ui
if (currentTabIndex == CHATHISTORYFRAGMENT)
chatHistoryFragment.refresh();
if (CommonUtils.getTopActivity(MainActivity.this).equals(GroupsActivity.class.getName())) {
GroupsActivity.instance.onResume();
}
}
});
}
示例11: getItemViewType
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
/**
* 获取item类型
*/
public int getItemViewType(int position) {
EMMessage message = getItem(position);
if (message == null) {
return -1;
}
if (message.getType() == EMMessage.Type.TXT) {
if (message.getBooleanAttribute(HXConstant.MESSAGE_ATTR_IS_VOICE_CALL, false))
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_VOICE_CALL : MESSAGE_TYPE_SENT_VOICE_CALL;
else if (message.getBooleanAttribute(HXConstant.MESSAGE_ATTR_IS_VIDEO_CALL, false))
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_VIDEO_CALL : MESSAGE_TYPE_SENT_VIDEO_CALL;
else if(HXUtil.isRobotMenuMessage(message))
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_ROBOT_MENU : MESSAGE_TYPE_SENT_ROBOT_MENU;
else
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_TXT : MESSAGE_TYPE_SENT_TXT;
}
if (message.getType() == EMMessage.Type.IMAGE) {
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_IMAGE : MESSAGE_TYPE_SENT_IMAGE;
}
if (message.getType() == EMMessage.Type.LOCATION) {
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_LOCATION : MESSAGE_TYPE_SENT_LOCATION;
}
if (message.getType() == EMMessage.Type.VOICE) {
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_VOICE : MESSAGE_TYPE_SENT_VOICE;
}
if (message.getType() == EMMessage.Type.VIDEO) {
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_VIDEO : MESSAGE_TYPE_SENT_VIDEO;
}
if (message.getType() == EMMessage.Type.FILE) {
return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_FILE : MESSAGE_TYPE_SENT_FILE;
}
return -1;// invalid
}
示例12: handleTextMessage
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
/**
* 文本消息
*
* @param message
* @param holder
* @param position
*/
private void handleTextMessage(EMMessage message, ViewHolder holder, final int position) {
TextMessageBody txtBody = (TextMessageBody) message.getBody();
Spannable span = HXSmileUtils.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);
}
}
}
示例13: handleLocationMessage
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
/**
* 处理位置消息
*
* @param message
* @param holder
* @param position
* @param convertView
*/
private void handleLocationMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) {
TextView locationView = ((TextView) convertView.findViewById(R.id.tv_location));
LocationMessageBody locBody = (LocationMessageBody) message.getBody();
locationView.setText(locBody.getAddress());
LatLng loc = new LatLng(locBody.getLatitude(), locBody.getLongitude());
// locationView.setOnClickListener(new MapClickListener(loc, locBody.getAddress()));
locationView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
activity.startActivityForResult(
(new Intent(activity, ContextMenu.class)).putExtra("position", position).putExtra("type",
EMMessage.Type.LOCATION.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
return false;
}
});
if (message.direct == EMMessage.Direct.RECEIVE) {
return;
}
// deal with send message
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);
break;
default:
sendMsgInBackground(message, holder);
}
}
示例14: onInvitationReceived
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
@Override
public void onInvitationReceived(String groupId, String groupName, String inviter, String reason) {
boolean hasGroup = false;
for (EMGroup group : EMGroupManager.getInstance().getAllGroups()) {
if (group.getGroupId().equals(groupId)) {
hasGroup = true;
break;
}
}
if (!hasGroup)
return;
// 被邀请
String st3 = appContext.getString(R.string.Invite_you_to_join_a_group_chat);
EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
msg.setChatType(ChatType.GroupChat);
msg.setFrom(inviter);
msg.setTo(groupId);
msg.setMsgId(UUID.randomUUID().toString());
msg.addBody(new TextMessageBody(inviter + " " +st3));
// 保存邀请消息
EMChatManager.getInstance().saveMessage(msg);
// 提醒新消息
getNotifier().viberateAndPlayTone(msg);
//发送local广播
broadcastManager.sendBroadcast(new Intent(Constant.ACTION_GROUP_CHANAGED));
}
示例15: receiveRevokeMessage
import com.easemob.chat.EMMessage.Type; //导入依赖的package包/类
/**
* 收到撤回消息,这里需要和发送方协商定义,通过一个透传,并加上扩展去实现消息的撤回
*
* @param revokeMsg 收到的透传消息,包含需要撤回的消息的 msgId
* @return 返回撤回结果是否成功
*/
public static boolean receiveRevokeMessage(Context context, EMMessage revokeMsg) {
EMConversation conversation = EMChatManager.getInstance().getConversation(revokeMsg.getFrom());
boolean result = false;
// 从cmd扩展中获取要撤回消息的id
String msgId = revokeMsg.getStringAttribute(EaseConstant.EASE_ATTR_REVOKE_MSG_ID, null);
if (msgId == null) {
return result;
}
// 根据得到的msgId 去本地查找这条消息,如果本地已经没有这条消息了,就不用撤回
// 这里为了防止消息没有加载到内存中,使用Conversation的loadMessage方法加载消息
EMMessage message = EMChatManager.getInstance().getMessage(msgId);
if (message == null) {
message = conversation.loadMessage(msgId);
}
// 更改要撤销的消息的内容,替换为消息已经撤销的提示内容
TextMessageBody body = new TextMessageBody(String.format(context.getString(R.string.revoke_message_by_user), message.getFrom()));
message.addBody(body);
// 这里需要把消息类型改为 TXT 类型
message.setType(EMMessage.Type.TXT);
// 设置扩展为撤回消息类型,是为了区分消息的显示
message.setAttribute(EaseConstant.EASE_ATTR_REVOKE, true);
// 返回修改消息结果
result = EMChatManager.getInstance().updateMessageBody(message);
// 因为Android这边没有修改消息未读数的方法,这里只能通过conversation的getMessage方法来实现未读数减一
conversation.getMessage(msgId);
message.isAcked = true;
return result;
}