com.easemob.chat.EMMessage Java Examples

The following examples show how to use com.easemob.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: ChatActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    abortBroadcast();

    String msgid = intent.getStringExtra("msgid");
    String from = intent.getStringExtra("from");
    EMConversation conversation = EMChatManager.getInstance()
            .getConversation(from);
    if (conversation != null) {
        // 把message设为已读
        EMMessage msg = conversation.getMessage(msgid);
        if (msg != null) {
            msg.isDelivered = true;
        }
    }

    adapter.notifyDataSetChanged();
}
 
Example #2
Source File: EaseChatFragment.java    From monolog-android with MIT License 6 votes vote down vote up
protected void onConversationInit(){

        // 获取当前conversation对象
        conversation = EMChatManager.getInstance().getConversation(toChatUsername);

        // 把此会话的未读数置为0
        conversation.markAllMessagesAsRead();

        // 初始化db时,每个conversation加载数目是getChatOptions().getNumberOfMessagesLoaded
        // 这个数目如果比用户期望进入会话界面时显示的个数不一样,就多加载一些
        final List<EMMessage> msgs = conversation.getAllMessages();
        int msgCount = msgs != null ? msgs.size() : 0;
        if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
            String msgId = null;
            if (msgs != null && msgs.size() > 0) {
                msgId = msgs.get(0).getMsgId();
            }
            if (chatType == EaseConstant.CHATTYPE_SINGLE) {
                conversation.loadMoreMsgFromDB(msgId, pagesize - msgCount);
            } else {
                conversation.loadMoreGroupMsgFromDB(msgId, pagesize - msgCount);
            }
        }
        
    }
 
Example #3
Source File: EaseChatFragment.java    From monolog-android with MIT License 6 votes vote down vote up
protected void sendMessage(EMMessage message){
    if(chatFragmentListener != null){
        //设置扩展属性
        chatFragmentListener.onSetMessageAttributes(message);
    }
    // 如果是群聊,设置chattype,默认是单聊
    if (chatType == EaseConstant.CHATTYPE_GROUP){
        message.setChatType(ChatType.GroupChat);
    }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){
        message.setChatType(ChatType.ChatRoom);
    }
    //发送消息
    EMChatManager.getInstance().sendMessage(message, null);
    //刷新ui
    messageList.refreshSelectLast();
}
 
Example #4
Source File: ChatActivity.java    From school_shop with MIT License 6 votes vote down vote up
/**
 * 发送语音
 * 
 * @param filePath
 * @param fileName
 * @param length
 * @param isResend
 */
private void sendVoice(String filePath, String fileName, String length, boolean isResend) {
	if (!(new File(filePath).exists())) {
		return;
	}
	try {
		final EMMessage message = EMMessage.createSendMessage(EMMessage.Type.VOICE);
		// 如果是群聊,设置chattype,默认是单聊
		if (chatType == CHATTYPE_GROUP)
			message.setChatType(ChatType.GroupChat);
		message.setReceipt(toChatUsername);
		int len = Integer.parseInt(length);
		VoiceMessageBody body = new VoiceMessageBody(new File(filePath), len);
		message.addBody(body);

		conversation.addMessage(message);
		adapter.refreshSelectLast();
		setResult(RESULT_OK);
		// send file
		// sendVoiceSub(filePath, fileName, message);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #5
Source File: ChatActivity.java    From school_shop with MIT License 6 votes vote down vote up
/**
 * 转发消息
 * 
 * @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;
	}
}
 
Example #6
Source File: ChatActivity.java    From school_shop with MIT License 6 votes vote down vote up
/**
 * 发送图片
 * 
 * @param filePath
 */
private void sendPicture(final String filePath) {
	String to = toChatUsername;
	// create and add image message in view
	final EMMessage message = EMMessage.createSendMessage(EMMessage.Type.IMAGE);
	// 如果是群聊,设置chattype,默认是单聊
	if (chatType == CHATTYPE_GROUP)
		message.setChatType(ChatType.GroupChat);

	message.setReceipt(to);
	ImageMessageBody body = new ImageMessageBody(new File(filePath));
	// 默认超过100k的图片会压缩后发给对方,可以设置成发送原图
	// body.setSendOriginalImage(true);
	message.addBody(body);
	conversation.addMessage(message);

	listView.setAdapter(adapter);
	adapter.refreshSelectLast();
	setResult(RESULT_OK);
	// more(more);
}
 
Example #7
Source File: DemoHXSDKHelper.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected OnNotificationClickListener getNotificationClickListener() {
    return new OnNotificationClickListener() {

        @Override
        public Intent onNotificationClick(EMMessage message) {
            Intent intent = new Intent(appContext, ChatActivity.class);
            ChatType chatType = message.getChatType();
            if (chatType == ChatType.Chat) { // 单聊信息
                intent.putExtra("userId", message.getFrom());
                intent.putExtra("chatType", ChatActivity.CHATTYPE_SINGLE);
            } else { // 群聊信息
                     // message.getTo()为群聊id
                intent.putExtra("groupId", message.getTo());
                intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP);
            }
            return intent;
        }
    };
}
 
Example #8
Source File: EaseNotifier.java    From monolog-android with MIT License 6 votes vote down vote up
/**
 * 处理新收到的消息,然后发送通知
 * 
 * 开发者可以重载此函数
 * this function can be override
 * 
 * @param message
 */
public synchronized void onNewMsg(EMMessage message) {
    if(EMChatManager.getInstance().isSlientMessage(message)){
        return;
    }
    EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider();
    if(!settingsProvider.isMsgNotifyAllowed(message)){
        return;
    }
    
    // 判断app是否在后台
    if (!EasyUtils.isAppRunningForeground(appContext)) {
        EMLog.d(TAG, "app is running in backgroud");
        sendNotification(message, false);
    } else {
        sendNotification(message, true);

    }
    
    viberateAndPlayTone(message);
}
 
Example #9
Source File: EaseChatRowFile.java    From monolog-android with MIT License 6 votes vote down vote up
@Override
protected void onBubbleClick() {
    String filePath = fileMessageBody.getLocalUrl();
    File file = new File(filePath);
    if (file != null && file.exists()) {
        // 文件存在,直接打开
        FileUtils.openFile(file, (Activity) context);
    } else {
        // 下载
        context.startActivity(new Intent(context, EaseShowNormalFileActivity.class).putExtra("msgbody", message.getBody()));
    }
    if (message.direct == EMMessage.Direct.RECEIVE && !message.isAcked) {
        try {
            EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
            message.isAcked = true;
        } catch (EaseMobException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
}
 
Example #10
Source File: EaseChatRowFile.java    From monolog-android with MIT License 6 votes vote down vote up
@Override
protected void onSetUpView() {
    fileMessageBody = (NormalFileMessageBody) 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 #11
Source File: MessageAdapter.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 发送消息
 * 
 * @param message
 * @param holder
 * @param position
 */
public void sendMsgInBackground(final EMMessage message,
        final ViewHolder holder) {
    holder.staus_iv.setVisibility(View.GONE);
    holder.pb.setVisibility(View.VISIBLE);

    final long start = System.currentTimeMillis();
    // 调用sdk发送异步发送方法
    EMChatManager.getInstance().sendMessage(message, new EMCallBack() {

        @Override
        public void onSuccess() {
            // umeng自定义事件,

            updateSendedView(message, holder);
        }

        @Override
        public void onError(int code, String error) {

            updateSendedView(message, holder);
        }

        @Override
        public void onProgress(int progress, String status) {
        }

    });

}
 
Example #12
Source File: MessageAdapter.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * 发送消息
 * 
 * @param message
 * @param holder
 * @param position
 */
public void sendMsgInBackground(final EMMessage message, final ViewHolder holder) {
	holder.staus_iv.setVisibility(View.GONE);
	holder.pb.setVisibility(View.VISIBLE);

	final long start = System.currentTimeMillis();
	// 调用sdk发送异步发送方法
	EMChatManager.getInstance().sendMessage(message, new EMCallBack() {

		@Override
		public void onSuccess() {
			
			updateSendedView(message, holder);
		}

		@Override
		public void onError(int code, String error) {
			
			updateSendedView(message, holder);
		}

		@Override
		public void onProgress(int progress, String status) {
		}

	});

}
 
Example #13
Source File: ChatActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 发送图片
 * 
 * @param filePath
 */
private void sendPicture(final String filePath, boolean is_share) {
    Log.e("filePath------>>>>", filePath);
    String to = toChatUsername;
    // create and add image message in view
    final EMMessage message = EMMessage
            .createSendMessage(EMMessage.Type.IMAGE);
    // 如果是群聊,设置chattype,默认是单聊
    if (chatType == CHATTYPE_GROUP)
        message.setChatType(ChatType.GroupChat);

    message.setReceipt(to);
    message.setAttribute("toUserNick", toUserNick);
    message.setAttribute("toUserAvatar", toUserAvatar);
    message.setAttribute("useravatar", myUserAvatar);
    message.setAttribute("usernick", myUserNick);
    if (is_share) {
        message.setAttribute("isShare", "yes");
    }
    ImageMessageBody body = new ImageMessageBody(new File(filePath));
    // 默认超过100k的图片会压缩后发给对方,可以设置成发送原图
    // body.setSendOriginalImage(true);
    message.addBody(body);
    conversation.addMessage(message);

    listView.setAdapter(adapter);
    adapter.refresh();
    listView.setSelection(listView.getCount() - 1);
    setResult(RESULT_OK);
    // more(more);
}
 
Example #14
Source File: ChatActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 发送视频消息
 */
private void sendVideo(final String filePath, final String thumbPath,
        final int length) {
    final File videoFile = new File(filePath);
    if (!videoFile.exists()) {
        return;
    }
    try {
        EMMessage message = EMMessage
                .createSendMessage(EMMessage.Type.VIDEO);
        // 如果是群聊,设置chattype,默认是单聊
        if (chatType == CHATTYPE_GROUP)
            message.setChatType(ChatType.GroupChat);
        String to = toChatUsername;
        message.setReceipt(to);
        message.setAttribute("toUserNick", toUserNick);
        message.setAttribute("toUserAvatar", toUserAvatar);
        message.setAttribute("useravatar", myUserAvatar);
        message.setAttribute("usernick", myUserNick);
        VideoMessageBody body = new VideoMessageBody(videoFile, thumbPath,
                length, videoFile.length());
        message.addBody(body);
        conversation.addMessage(message);
        listView.setAdapter(adapter);
        adapter.refresh();
        listView.setSelection(listView.getCount() - 1);
        setResult(RESULT_OK);
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example #15
Source File: ChatActivity.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * 重发消息
 */
private void resendMessage() {
	EMMessage msg = null;
	msg = conversation.getMessage(resendPos);
	// msg.setBackSend(true);
	msg.status = EMMessage.Status.CREATE;

	adapter.refreshSeekTo(resendPos);
}
 
Example #16
Source File: VoicePlayClickListener.java    From FanXin-based-HuanXin with GNU General Public License v2.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 #17
Source File: MessageAdapter.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 更新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();
            }

            notifyDataSetChanged();
        }
    });
}
 
Example #18
Source File: ChatActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 重发消息
 */
private void resendMessage() {
    EMMessage msg = null;
    msg = conversation.getMessage(resendPos);
    // msg.setBackSend(true);
    msg.status = EMMessage.Status.CREATE;

    adapter.refresh();
    listView.setSelection(resendPos);
}
 
Example #19
Source File: MessageAdapter.java    From school_shop with MIT License 5 votes vote down vote up
private View createViewByMessage(EMMessage message, int position) {
		switch (message.getType()) {
//		case LOCATION:
//			return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_location, null) : inflater.inflate(
//					R.layout.row_sent_location, null);
		case IMAGE:
			return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_picture, null) : inflater.inflate(
					R.layout.row_sent_picture, null);

		case VOICE:
			return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_voice, null) : inflater.inflate(
					R.layout.row_sent_voice, null);
//		case VIDEO:
//			return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_video, null) : inflater.inflate(
//					R.layout.row_sent_video, null);
//		case FILE:
//			return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_file, null) : inflater.inflate(
//					R.layout.row_sent_file, null);
		default:
			// 语音通话
//			if (message.getBooleanAttribute(Constants.MESSAGE_ATTR_IS_VOICE_CALL, false))
//				return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_voice_call, null) : inflater
//						.inflate(R.layout.row_sent_voice_call, null);
			// 视频通话
//			else if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false))
//			    return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_video_call, null) : inflater
//                        .inflate(R.layout.row_sent_video_call, null);
			return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_message, null) : inflater.inflate(
					R.layout.row_sent_message, null);
		}
	}
 
Example #20
Source File: EaseMessageAdapter.java    From monolog-android with MIT License 5 votes vote down vote up
protected EaseChatRow createChatRow(Context context, EMMessage message, int position) {
    EaseChatRow chatRow = null;
    if(customRowProvider != null && customRowProvider.getCustomChatRow(message, position, this) != null){
        return customRowProvider.getCustomChatRow(message, position, this);
    }
    switch (message.getType()) {
    case TXT:
        chatRow = new EaseChatRowText(context, message, position, this);
        break;
    case FILE:
        chatRow = new EaseChatRowFile(context, message, position, this);
        break;
    case IMAGE:
        chatRow = new EaseChatRowImage(context, message, position, this);
        break;
    case VOICE:
        chatRow = new EaseChatRowVoice(context, message, position, this);
        break;
    case VIDEO:
        chatRow = new EaseChatRowVideo(context, message, position, this);
        break;
    default:
        break;
    }

    return chatRow;
}
 
Example #21
Source File: MessageAdapter.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * 文本消息
 * 
 * @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);
		}
	}
}
 
Example #22
Source File: EaseChatFragment.java    From monolog-android with MIT License 5 votes vote down vote up
protected void sendTextMessage(String content) {
//        EMMessage cmdMsg = EMMessage.createSendMessage(EMMessage.Type.CMD);
//        String action="action1";//action可以自定义
//        EMCmdMessageBody cmdBody = new EMCmdMessageBody(action);
//        String toUsername = "test1";//发送给某个人
//        cmdMsg.setReceipt(toUsername);
//        cmdMsg.addBody(cmdBody);
//        sendMessage(cmdMsg);

        EMMessage message = EMMessage.createTxtSendMessage(content, toChatUsername);
        sendMessage(message);
    }
 
Example #23
Source File: VoicePlayClickListener.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param message
 * @param v
 * @param iv_read_status
 * @param context
 * @param activity
 * @param user
 * @param chatType
 */
public VoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity activity,
		String username) {
	this.message = message;
	voiceBody = (VoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = activity;
	this.chatType = message.getChatType();
}
 
Example #24
Source File: VoicePlayClickListener.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * 
 * @param message
 * @param v
 * @param iv_read_status
 * @param context
 * @param activity
 * @param user
 * @param chatType
 */
public VoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity activity,
		String username) {
	this.message = message;
	voiceBody = (VoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = activity;
	this.chatType = message.getChatType();
}
 
Example #25
Source File: EaseChatRowVoicePlayClickListener.java    From monolog-android with MIT License 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 #26
Source File: BaseActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 当应用在前台时,如果当前消息不是属于当前会话,在状态栏提示一下 如果不需要,注释掉即可
 * 
 * @param message
 */
protected void notifyNewMessage(EMMessage message) {
    // 如果是设置了不提醒只显示数目的群组(这个是app里保存这个数据的,demo里不做判断)
    // 以及设置了setShowNotificationInbackgroup:false(设为false后,后台时sdk也发送广播)
    if (!EasyUtils.isAppRunningForeground(this)) {
        return;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this).setSmallIcon(getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis()).setAutoCancel(true);

    String ticker = CommonUtils.getMessageDigest(message, this);
    if (message.getType() == Type.TXT)
        ticker = ticker.replaceAll("\\[.{2,3}\\]", "[表情]");
    // 设置状态栏提示
    mBuilder.setTicker(message.getFrom() + ": " + ticker);

    // 必须设置pendingintent,否则在2.3的机器上会有bug
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notifiId,
            intent, PendingIntent.FLAG_ONE_SHOT);
    mBuilder.setContentIntent(pendingIntent);

    Notification notification = mBuilder.build();
    notificationManager.notify(notifiId, notification);
    notificationManager.cancel(notifiId);
}
 
Example #27
Source File: EaseChatFragment.java    From monolog-android with MIT License 5 votes vote down vote up
/**
 * 转发消息
 * 
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final 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();
        sendTextMessage(content);
        break;
    case IMAGE:
        // 发送图片
        String filePath = ((ImageMessageBody) forward_msg.getBody()).getLocalUrl();
        if (filePath != null) {
            File file = new File(filePath);
            if (!file.exists()) {
                // 不存在大图发送缩略图
                filePath = EaseImageUtils.getThumbnailImagePath(filePath);
            }
            sendImageMessage(filePath);
        }
        break;
    default:
        break;
    }
    
    if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){
        EMChatManager.getInstance().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example #28
Source File: EaseChatRowVoicePlayClickListener.java    From monolog-android with MIT License 5 votes vote down vote up
public EaseChatRowVoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity context) {
	this.message = message;
	voiceBody = (VoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = context;
	this.chatType = message.getChatType();
}
 
Example #29
Source File: EaseChatRow.java    From monolog-android with MIT License 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 #30
Source File: EaseChatRow.java    From monolog-android with MIT License 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();
}