com.easemob.chat.EMMessage.Direct Java Examples

The following examples show how to use com.easemob.chat.EMMessage.Direct. 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: 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 #2
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 #3
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
 */
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 #4
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 #5
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 #6
Source File: MessageAdapter.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * 显示用户头像
 * @param message
 * @param imageView
 */
private void setUserAvatar(EMMessage message, ImageView imageView){
    if(message.direct == Direct.SEND){
        //显示自己头像
        UserUtils.setUserAvatar(context, EMChatManager.getInstance().getCurrentUser(), imageView);
    }else{
        UserUtils.setUserAvatar(context, message.getFrom(), imageView,ChatActivity.buserAvatar);
    }
}
 
Example #7
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 #8
Source File: EaseChatRow.java    From monolog-android with MIT License 4 votes vote down vote up
private void setUpBaseView() {
        // 设置用户昵称头像,bubble背景等
        TextView timestamp = (TextView) findViewById(R.id.timestamp);
        if (timestamp != null) {
            if (position == 0) {
                timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
                timestamp.setVisibility(View.VISIBLE);
            } else {
                // 两条消息时间离得如果稍长,显示时间
                EMMessage prevMessage = (EMMessage) adapter.getItem(position - 1);
                if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) {
                    timestamp.setVisibility(View.GONE);
                } else {
                    timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
                    timestamp.setVisibility(View.VISIBLE);
                }
            }
        }
        //设置头像和nick
        if(message.direct == Direct.SEND){
            EaseUserUtils.setUserAvatar(context, EMChatManager.getInstance().getCurrentUser(), userAvatarView);
            //发送方不显示nick
//            UserUtils.setUserNick(EMChatManager.getInstance().getCurrentUser(), usernickView);
        }else{
            EaseUserUtils.setUserAvatar(context, message.getFrom(), userAvatarView);
            EaseUserUtils.setUserNick(message.getFrom(), usernickView);
        }
        
        if(deliveredView != null){
            if (message.isDelivered) {
                deliveredView.setVisibility(View.VISIBLE);
            } else {
                deliveredView.setVisibility(View.INVISIBLE);
            }
        }
        
        if(ackedView != null){
            if (message.isAcked) {
                if (deliveredView != null) {
                    deliveredView.setVisibility(View.INVISIBLE);
                }
                ackedView.setVisibility(View.VISIBLE);
            } else {
                ackedView.setVisibility(View.INVISIBLE);
            }
        }
        

        if (adapter instanceof EaseMessageAdapter) {
            if (((EaseMessageAdapter) adapter).isShowAvatar())
                userAvatarView.setVisibility(View.VISIBLE);
            else
                userAvatarView.setVisibility(View.GONE);
            if (usernickView != null) {
                if (((EaseMessageAdapter) adapter).isShowUserNick())
                    usernickView.setVisibility(View.VISIBLE);
                else
                    usernickView.setVisibility(View.GONE);
            }
            if (message.direct == Direct.SEND) {
                if (((EaseMessageAdapter) adapter).getMyBubbleBg() != null)
                    bubbleLayout.setBackgroundDrawable(((EaseMessageAdapter) adapter).getMyBubbleBg());
                // else
                // bubbleLayout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.chatto_bg));
            } else if (message.direct == Direct.RECEIVE) {
                if (((EaseMessageAdapter) adapter).getOtherBuddleBg() != null)
                    bubbleLayout.setBackgroundDrawable(((EaseMessageAdapter) adapter).getOtherBuddleBg());
//                else
//                    bubbleLayout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.ease_chatfrom_bg));
            }
        }
    }
 
Example #9
Source File: MessageAdapter.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 处理位置消息
 * 
 * @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);
    }
}
 
Example #10
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 #11
Source File: MessageAdapter.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 展示视频缩略图
 * 
 * @param localThumb
 *            本地缩略图路径
 * @param iv
 * @param thumbnailUrl
 *            远程缩略图路径
 * @param message
 */
private void showVideoThumbView(String localThumb, ImageView iv,
        String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    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) {
                VideoMessageBody videoBody = (VideoMessageBody) message
                        .getBody();
                System.err.println("video view is on click");
                Intent intent = new Intent(activity,
                        ShowVideoActivity.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.GroupChat) {
                    message.isAcked = true;
                    try {
                        EMChatManager.getInstance().ackMessageRead(
                                message.getFrom(), message.getMsgId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);

            }
        });

    } else {
        new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv,
                activity, message, this);
    }

}
 
Example #12
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;
	}

}