com.easemob.chat.ImageMessageBody Java Examples

The following examples show how to use com.easemob.chat.ImageMessageBody. 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 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 #2
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 #3
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 #4
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 #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 4 votes vote down vote up
/**
 * load image into image view
 * 
 * @param thumbernailPath
 * @param iv
 * @param position
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath,
        final ImageView iv, final String localFullSizePath,
        String remoteDir, final EMMessage message) {
    // String imagename =
    // localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1,
    // localFullSizePath.length());
    // final String remote = remoteDir != null ? remoteDir+imagename :
    // imagename;
    final String remote = remoteDir;
    EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote);
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                System.err.println("image view on click");
                Intent intent = new Intent(activity, ShowBigImage.class);
                File file = new File(localFullSizePath);
                if (file.exists()) {
                    Uri uri = Uri.fromFile(file);
                    intent.putExtra("uri", uri);
                    System.err
                            .println("here need to check why download everytime");
                } else {
                    // The local full size pic does not exist yet.
                    // ShowBigImage needs to download it from the server
                    // first
                    // intent.putExtra("", message.get);
                    ImageMessageBody body = (ImageMessageBody) message
                            .getBody();
                    intent.putExtra("secret", body.getSecret());
                    intent.putExtra("remotepath", remote);
                }
                if (message != null
                        && message.direct == EMMessage.Direct.RECEIVE
                        && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat) {
                    try {
                        EMChatManager.getInstance().ackMessageRead(
                                message.getFrom(), message.getMsgId());
                        message.isAcked = true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);
            }
        });
        return true;
    } else {

        new LoadImageTask().execute(thumbernailPath, localFullSizePath,
                remote, message.getChatType(), iv, activity, message);
        return true;
    }

}
 
Example #7
Source File: MessageAdapter.java    From school_shop with MIT License 4 votes vote down vote up
/**
 * load image into image view
 * 
 * @param thumbernailPath
 * @param iv
 * @param position
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath, final ImageView iv, final String localFullSizePath, String remoteDir,
		final EMMessage message) {
	// String imagename =
	// localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1,
	// localFullSizePath.length());
	// final String remote = remoteDir != null ? remoteDir+imagename :
	// imagename;
	final String remote = remoteDir;
	EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote);
	// first check if the thumbnail image already loaded into cache
	Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath);
	if (bitmap != null) {
		// thumbnail image is already loaded, reuse the drawable
		iv.setImageBitmap(bitmap);
		iv.setClickable(true); 
		iv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				System.err.println("image view on click");
				Intent intent = new Intent(activity, ShowBigImage.class);
				File file = new File(localFullSizePath);
				if (file.exists()) {
					Uri uri = Uri.fromFile(file);
					intent.putExtra("uri", uri);
					System.err.println("here need to check why download everytime");
				} else {
					// The local full size pic does not exist yet.
					// ShowBigImage needs to download it from the server
					// first
					// intent.putExtra("", message.get);
					ImageMessageBody body = (ImageMessageBody) message.getBody();
					intent.putExtra("secret", body.getSecret());
					intent.putExtra("remotepath", remote);
				}
				if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
						&& message.getChatType() != ChatType.GroupChat) {
					try {
						EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
						message.isAcked = true;
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
				activity.startActivity(intent);
			}
		});
		return true;
	} else {

		new LoadImageTask().execute(thumbernailPath, localFullSizePath, remote, message.getChatType(), iv, activity, message);
		return true;
	}

}