Java Code Examples for com.easemob.chat.EMMessage#getType()

The following examples show how to use com.easemob.chat.EMMessage#getType() . 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 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 2
Source File: EaseMessageAdapter.java    From monolog-android with MIT License 5 votes vote down vote up
/**
 * 获取item类型
 */
public int getItemViewType(int position) {
	EMMessage message = getItem(position); 
	if (message == null) {
		return -1;
	}
	
	if(customRowProvider != null && customRowProvider.getCustomChatRowType(message) > 0){
	    return customRowProvider.getCustomChatRowType(message) + 11;
	}
	
	if (message.getType() == EMMessage.Type.TXT) {
		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.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
}
 
Example 3
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 4
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 5
Source File: ChatActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 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, false);
        }
        break;
    default:
        break;
    }
}
 
Example 6
Source File: MessageAdapter.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 获取item类型
 */
public int getItemViewType(int position) {
    EMMessage message = conversation.getMessage(position);
    if (message.getType() == EMMessage.Type.TXT) {
        if (message.getBooleanAttribute(
                Constant.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(
                Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false))
            return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_VIDEO_CALL
                    : MESSAGE_TYPE_SENT_VIDEO_CALL;
        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
}
 
Example 7
Source File: MessageAdapter.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@SuppressLint("InflateParams")
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(
                Constant.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);
        return message.direct == EMMessage.Direct.RECEIVE ? inflater
                .inflate(R.layout.row_received_message, null) : inflater
                .inflate(R.layout.row_sent_message, null);
    }
}
 
Example 8
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 9
Source File: MessageAdapter.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * 获取item类型
 */
public int getItemViewType(int position) {
	EMMessage message = getItem(position); 
	if (message == null) {
		return -1;
	}
	if (message.getType() == EMMessage.Type.TXT) {
		if (message.getBooleanAttribute(Constants.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(Constants.MESSAGE_ATTR_IS_VIDEO_CALL, false))
		    return message.direct == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_VIDEO_CALL : MESSAGE_TYPE_SENT_VIDEO_CALL;
		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
}
 
Example 10
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);
		}
	}