com.hyphenate.chat.EMMessage Java Examples

The following examples show how to use com.hyphenate.chat.EMMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EaseNotifier.java    From Social with Apache License 2.0 6 votes vote down vote up
public synchronized void onNewMesg(List<EMMessage> messages) {
    if(EMClient.getInstance().chatManager().isSlientMessage(messages.get(messages.size()-1))){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(null)){
        return;
    }
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(messages, false);
    } else {
        sendNotification(messages, true);
    }
    viberateAndPlayTone(messages.get(messages.size()-1));
}
 
Example #2
Source File: VoiceMessageBaseItemView.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v)
{
    if (mPresenter.getCurPlayVoicePosition() == mPosition)
    {
        mPresenter.stopPlayVoiceMessage();
        return;
    }

    mPresenter.stopPlayVoiceMessage();
    mMessage.setListened(true);
    mPresenter.setCurVoicePlayPosition(mPosition);
    if (mMessage.direct() == EMMessage.Direct.SEND)
        mImageView.start(mAnimRight, true, ANIM_DURATION);
    else
        mImageView.start(mAnimLeft, true, ANIM_DURATION);

    String localUrl = mBody.getLocalUrl();
    if (StringUtil.isNotEmpty(localUrl) && new File(localUrl).exists())
        mPresenter.clickVoiceMessage(localUrl);
    else
        mPresenter.clickVoiceMessage(mBody.getRemoteUrl());
}
 
Example #3
Source File: EaseChatRowVoicePlayClickListener.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public void stopPlayVoice() {
	voiceAnimation.stop();
	if (message.direct() == EMMessage.Direct.RECEIVE) {
		voiceIconView.setImageResource(R.drawable.ease_chatfrom_voice_playing);
	} else {
		voiceIconView.setImageResource(R.drawable.ease_chatto_voice_playing);
	}
	// stop play voice
	if (mediaPlayer != null) {
		mediaPlayer.stop();
		mediaPlayer.release();
	}
	isPlaying = false;
	playMsgId = null;
	adapter.notifyDataSetChanged();
}
 
Example #4
Source File: MyEaseChatFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
protected void sendMessage(EMMessage message){
    if (message == null) {
        return;
    }
    if(chatFragmentListener != null){
        //设置扩展属性
        chatFragmentListener.onSetMessageAttributes(message);
    }
    // 如果是群聊,设置chattype,默认是单聊
    if (chatType == EaseConstant.CHATTYPE_GROUP){
        message.setChatType(EMMessage.ChatType.GroupChat);
    }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){
        message.setChatType(EMMessage.ChatType.ChatRoom);
    }
    //发送消息
    EMClient.getInstance().chatManager().sendMessage(message);
    //刷新ui
    if(isMessageListInited) {
        messageList.refreshSelectLast();
    }
}
 
Example #5
Source File: EaseChatRow.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
protected void updateView() {
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (message.status() == EMMessage.Status.FAIL) {

                if (message.getError() == EMError.MESSAGE_INCLUDE_ILLEGAL_CONTENT) {
                    Toast.makeText(activity,activity.getString(R.string.send_fail) + activity.getString(R.string.error_send_invalid_content), 0).show();
                } else if (message.getError() == EMError.GROUP_NOT_JOINED) {
                    Toast.makeText(activity,activity.getString(R.string.send_fail) + activity.getString(R.string.error_send_not_in_the_group), 0).show();
                } else {
                    Toast.makeText(activity,activity.getString(R.string.send_fail) + activity.getString(R.string.connect_failuer_toast), 0).show();
                }
            }

            onUpdateView();
        }
    });

}
 
Example #6
Source File: HxImageDetailPresenter.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
public void savePic(Context context, EMMessage message)
{
    if (message == null)
        return;

    mViewImpl.showDownloadDialog();
    EMImageMessageBody messageBody = (EMImageMessageBody) message.getBody();
    String remoteUrl = messageBody.getRemoteUrl();
    CommonUtils.getInstance().getImageDisplayer().downloadBitmap(context, remoteUrl, new OnBitmapDownloadListener()
    {
        @Override
        public void onDownload(Bitmap bitmap)
        {
            saveBitmap(bitmap);
        }
    });
}
 
Example #7
Source File: EaseChatRowImage.java    From Social with Apache License 2.0 6 votes vote down vote up
@Override
protected void onBubbleClick() {
    Intent intent = new Intent(context, EaseShowBigImageActivity.class);
    File file = new File(imgBody.getLocalUrl());
    if (file.exists()) {
        Uri uri = Uri.fromFile(file);
        intent.putExtra("uri", uri);
    } else {
        // The local full size pic does not exist yet.
        // ShowBigImage needs to download it from the server
        // first
        intent.putExtra("secret", imgBody.getSecret());
        intent.putExtra("remotepath", imgBody.getRemoteUrl());
        intent.putExtra("localUrl", imgBody.getLocalUrl());
    }
    if (message != null && message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked()
            && message.getChatType() == ChatType.Chat) {
        try {
            EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    context.startActivity(intent);
}
 
Example #8
Source File: EaseChatFragment.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onMessageReceived(List<EMMessage> messages) {

    for (EMMessage message : messages) {
              String username = null;
              // 群组消息
              if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) {
                  username = message.getTo();
              } else {
                  // 单聊消息
                  username = message.getFrom();
              }
  
              // 如果是当前会话的消息,刷新聊天页面
              if (username.equals(toChatUsername)) {
                  messageList.refreshSelectLast();
                  // 声音和震动提示有新消息
                  EaseUI.getInstance().getNotifier().viberateAndPlayTone(message);
              } else {
                  // 如果消息不是和当前聊天ID的消息
                  EaseUI.getInstance().getNotifier().onNewMsg(message);
              }
    }
}
 
Example #9
Source File: EaseChatRowFile.java    From Social with Apache License 2.0 6 votes vote down vote up
@Override
protected void onSetUpView() {
    fileMessageBody = (EMNormalFileMessageBody) message.getBody();
       String filePath = fileMessageBody.getLocalUrl();
       fileNameView.setText(fileMessageBody.getFileName());
       fileSizeView.setText(TextFormater.getDataSize(fileMessageBody.getFileSize()));
       if (message.direct() == EMMessage.Direct.RECEIVE) { // 接收的消息
           File file = new File(filePath);
           if (file != null && file.exists()) {
               fileStateView.setText(R.string.Have_downloaded);
           } else {
               fileStateView.setText(R.string.Did_not_download);
           }
           return;
       }

       // until here, deal with send voice msg
       handleSendMessage();
}
 
Example #10
Source File: EaseChatRowVoicePlayClickListener.java    From Social with Apache License 2.0 6 votes vote down vote up
public void stopPlayVoice() {
	voiceAnimation.stop();
	if (message.direct() == EMMessage.Direct.RECEIVE) {
		voiceIconView.setImageResource(R.drawable.ease_chatfrom_voice_playing);
	} else {
		voiceIconView.setImageResource(R.drawable.ease_chatto_voice_playing);
	}
	// stop play voice
	if (mediaPlayer != null) {
		mediaPlayer.stop();
		mediaPlayer.release();
	}
	isPlaying = false;
	playMsgId = null;
	adapter.notifyDataSetChanged();
}
 
Example #11
Source File: EaseChatRowVideo.java    From Social with Apache License 2.0 6 votes vote down vote up
@Override
protected void onBubbleClick() {
    EMVideoMessageBody videoBody = (EMVideoMessageBody) message.getBody();
       EMLog.d(TAG, "video view is on click");
       Intent intent = new Intent(context, EaseShowVideoActivity.class);
       intent.putExtra("localpath", videoBody.getLocalUrl());
       intent.putExtra("secret", videoBody.getSecret());
       intent.putExtra("remotepath", videoBody.getRemoteUrl());
       if (message != null && message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked()
               && message.getChatType() == ChatType.Chat) {
           try {
               EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
       activity.startActivity(intent);
}
 
Example #12
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
protected void sendTextMessage(String content) {
    if(EaseAtMessageHelper.get().containsAtUsername(content)){
        sendAtMessage(content);
    }else{
        EMMessage message = EMMessage.createTxtSendMessage(content, toChatUsername);
        sendMessage(message);
    }
}
 
Example #13
Source File: EaseChatRowVoicePlayClickListener.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
private void showAnimation() {
	// play voice, and start animation
	if (message.direct() == EMMessage.Direct.RECEIVE) {
		voiceIconView.setImageResource(R.anim.voice_from_icon);
	} else {
		voiceIconView.setImageResource(R.anim.voice_to_icon);
	}
	voiceAnimation = (AnimationDrawable) voiceIconView.getDrawable();
	voiceAnimation.start();
}
 
Example #14
Source File: NewCallRecordEventBean.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
public NewCallRecordEventBean(EMMessage message)
{
    this.message = message;
    if (message.direct() == EMMessage.Direct.SEND)
        this.conId = message.getTo();
    else
        this.conId = message.getFrom();
}
 
Example #15
Source File: EaseMessageAdapter.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void refreshList() {
	// you should not call getAllMessages() in UI thread
	// otherwise there is problem when refreshing UI and there is new message arrive
	java.util.List<EMMessage> var = conversation.getAllMessages();
	messages = var.toArray(new EMMessage[var.size()]);
	conversation.markAllMessagesAsRead();
	notifyDataSetChanged();
}
 
Example #16
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * forward message
 * 
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id);
    EMMessage.Type type = forward_msg.getType();
    switch (type) {
    case TXT:
        if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
            sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(),
                    forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null));
        }else{
            // get the content and send it
            String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage();
            sendTextMessage(content);
        }
        break;
    case IMAGE:
        // send image
        String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl();
        if (filePath != null) {
            File file = new File(filePath);
            if (!file.exists()) {
                // send thumb nail if original image does not exist
                filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath();
            }
            sendImageMessage(filePath);
        }
        break;
    default:
        break;
    }
    
    if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example #17
Source File: EaseNotifier.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 发送通知栏提示
 * This can be override by subclass to provide customer implementation
 * @param messages
 * @param isForeground
 */
protected void sendNotification (List<EMMessage> messages, boolean isForeground){
    for(EMMessage message : messages){
        if(!isForeground){
            notificationNum++;
            fromUsers.add(message.getFrom());
        }
    }
    sendNotification(messages.get(messages.size() - 1), isForeground, false);
}
 
Example #18
Source File: ChatListFragment.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onMessageReceived(List<EMMessage> messages) {
    // 提示新消息
    for (EMMessage message : messages) {
        HuanXinHelper.getInstance().getNotifier().onNewMsg(message);
    }
    refreshUIWithMessage();
}
 
Example #19
Source File: EaseChatRow.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public EaseChatRow(Context context, EMMessage message, int position, BaseAdapter adapter) {
    super(context);
    this.context = context;
    this.activity = (Activity) context;
    this.message = message;
    this.position = position;
    this.adapter = adapter;
    inflater = LayoutInflater.from(context);

    initView();
}
 
Example #20
Source File: RightImageMessageItemView.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isForViewType(EMMessage item, int position)
{
    if (item.direct() == EMMessage.Direct.SEND && item.getType() == EMMessage.Type.IMAGE)
        return true;
    else
        return false;
}
 
Example #21
Source File: HxChatBaseItemView.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
protected void setUserData(RcvHolder holder, EMMessage emMessage, final int position)
{
    if (emMessage.direct() == EMMessage.Direct.RECEIVE)
    {
        //设置头像
        if (mUserBean != null && StringUtil.isNotEmpty(mUserBean.getLocalHead()))
            CommonUtils.getInstance()
                    .getImageDisplayer()
                    .display(mContext, (ImageView) holder.findView(R.id.img_chat_listitem_head),
                            mUserBean.getLocalHead(), 150, 150, R.drawable.default_avatar, R.drawable.default_avatar);
        else
            holder.setImgResource(R.id.img_chat_listitem_head, R.drawable.default_avatar);
        //设置名字
        //单聊不显示名字
        if (emMessage.getChatType() == EMMessage.ChatType.Chat)
        {
            holder.setVisibility(R.id.tv_chat_listitem_name, View.GONE);
        } else
        {
            holder.setVisibility(R.id.tv_chat_listitem_name, View.VISIBLE);
            if (mUserBean != null)
                holder.setTvText(R.id.tv_chat_listitem_name, mUserBean.getDisplayName());
            else
                holder.setTvText(R.id.tv_chat_listitem_name, emMessage.getUserName());
        }
    } else
    {
        //本方头像为默认头像
        holder.setImgResource(R.id.img_chat_listitem_head, R.drawable.default_avatar);
        //不显示名字
        holder.setVisibility(R.id.tv_chat_listitem_name, View.GONE);
    }
}
 
Example #22
Source File: EaseMessageAdapter.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
private void refreshList() {
	// UI线程不能直接使用conversation.getAllMessages()
	// 否则在UI刷新过程中,如果收到新的消息,会导致并发问题
	messages = (EMMessage[]) conversation.getAllMessages().toArray(new EMMessage[0]);
	conversation.markAllMessagesAsRead();
	notifyDataSetChanged();
}
 
Example #23
Source File: EaseCommonUtils.java    From Social with Apache License 2.0 5 votes vote down vote up
public static EMMessage createExpressionMessage(String toChatUsername, String expressioName, String identityCode){
    EMMessage message = EMMessage.createTxtSendMessage("["+expressioName+"]", toChatUsername);
       if(identityCode != null){
           message.setAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, identityCode);
       }
       message.setAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, true);
       return message;
}
 
Example #24
Source File: HxImageDetailActivity.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
@Override
public void onScanDataSuccess(List<EMMessage> list, int startPosition)
{
    mAdapter.setData(list);
    mViewPager.setCurrentItem(startPosition, false);
    refreshActionBar(startPosition);
}
 
Example #25
Source File: EaseChatRow.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 根据当前message和position设置控件属性等
 * 
 * @param message
 * @param position
 */
public void setUpView(EMMessage message, int position,
        EaseChatMessageList.MessageListItemClickListener itemClickListener) {
    this.message = message;
    this.position = position;
    this.itemClickListener = itemClickListener;

    setUpBaseView();
    onSetUpView();
    setClickListener();
}
 
Example #26
Source File: HxChatPresenter.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 发送图片消息
 */
public void sendImageMessage(EMConversation.EMConversationType conType, String conId, String filePath, boolean sendOriginFile)
{
    EMMessage emMessage = HxChatHelper.getInstance().createImageMessage(getChatTypeFromConType(conType), conId, filePath, sendOriginFile);
    emMessage.setMessageStatusCallback(new MessageStatusCallBack(emMessage));
    mViewImpl.addNewMessage(emMessage, true);
    HxChatHelper.getInstance().sendMessage(emMessage);
}
 
Example #27
Source File: EaseChatRowVoicePlayClickListener.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void showAnimation() {
	// play voice, and start animation
	if (message.direct() == EMMessage.Direct.RECEIVE) {
		voiceIconView.setImageResource(R.anim.voice_from_icon);
	} else {
		voiceIconView.setImageResource(R.anim.voice_to_icon);
	}
	voiceAnimation = (AnimationDrawable) voiceIconView.getDrawable();
	voiceAnimation.start();
}
 
Example #28
Source File: EaseChatFragment.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 转发消息
 * 
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id);
    EMMessage.Type type = forward_msg.getType();
    switch (type) {
    case TXT:
        if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
            sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(),
                    forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null));
        }else{
            // 获取消息内容,发送消息
            String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage();
            sendTextMessage(content);
        }
        break;
    case IMAGE:
        // 发送图片
        String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl();
        if (filePath != null) {
            File file = new File(filePath);
            if (!file.exists()) {
                // 不存在大图发送缩略图
                filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath();
            }
            sendImageMessage(filePath);
        }
        break;
    default:
        break;
    }
    
    if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example #29
Source File: HxMessageListener.java    From FamilyChat with Apache License 2.0 4 votes vote down vote up
@Override
public void onCmdMessageReceived(List<EMMessage> list)
{
    KLog.i("HxMessageListener onCmdMessageReceived : " + list);
}
 
Example #30
Source File: LeftVideoMessageItemView.java    From FamilyChat with Apache License 2.0 4 votes vote down vote up
@Override
public void setMessage(RcvHolder holder, EMMessage emMessage, int position)
{

}