Java Code Examples for com.hyphenate.chat.EMMessage#getBody()

The following examples show how to use com.hyphenate.chat.EMMessage#getBody() . 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: TextMessageBaseItemView.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
@Override
public void setMessageData(RcvHolder holder, EMMessage emMessage, int position)
{
    final EMTextMessageBody textMessageBody = (EMTextMessageBody) emMessage.getBody();
    TextView tvMessage = holder.findView(R.id.tv_chat_listitem_text_content);
    tvMessage.setText(textMessageBody.getMessage());
    tvMessage.setOnLongClickListener(new View.OnLongClickListener()
    {
        @Override
        public boolean onLongClick(View v)
        {
            ClipboardManager manager = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
            manager.setText(textMessageBody.getMessage());
            ToastUtils.showShortMsg(mContext, R.string.toast_text_be_copyed);
            return true;
        }
    });

    setMessage(holder, emMessage, position);
}
 
Example 2
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 3
Source File: HxChatPresenter.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
/**
 * 重新发送某条消息
 */
public void resendMessage(EMMessage message, int position)
{
    EMConversation.EMConversationType conType = mViewImpl.getConversationType();
    String conId = mViewImpl.getConversationId();
    //移除已有消息
    HxChatHelper.getInstance().deleteMessage(conType, conId, message);
    mViewImpl.removeMessage(message, position);
    //重发消息
    switch (message.getType())
    {
        case TXT:
            EMTextMessageBody textMessageBody = (EMTextMessageBody) message.getBody();
            sendTextMessage(conType, conId, textMessageBody.getMessage());
            break;
        case VOICE:
            EMVoiceMessageBody voiceMessageBody = (EMVoiceMessageBody) message.getBody();
            sendVoiceMessage(conType, conId, voiceMessageBody.getLocalUrl(), voiceMessageBody.getLength());
            break;
        case IMAGE:
            EMImageMessageBody imageMessageBody = (EMImageMessageBody) message.getBody();
            sendImageMessage(conType, conId, imageMessageBody.getLocalUrl(), imageMessageBody.isSendOriginalImage());
            break;
    }
}
 
Example 4
Source File: EaseChatRowVoicePlayClickListener.java    From Social with Apache License 2.0 5 votes vote down vote up
public EaseChatRowVoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity context) {
	this.message = message;
	voiceBody = (EMVoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = context;
	this.chatType = message.getChatType();
}
 
Example 5
Source File: EaseChatRowVoicePlayClickListener.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public EaseChatRowVoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity context) {
	this.message = message;
	voiceBody = (EMVoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = context;
	this.chatType = message.getChatType();
}
 
Example 6
Source File: EaseChatRowVoicePlayClickListener.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
public EaseChatRowVoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity context) {
	this.message = message;
	voiceBody = (EMVoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = context;
	this.chatType = message.getChatType();
}
 
Example 7
Source File: VideoMessageBaseItemView.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
@Override
public void setMessageData(RcvHolder holder, final EMMessage emMessage, final int position)
{
    SelectableRoundedImageView imgThumb = holder.findView(R.id.img_chat_listitem_video_content);
    TextView tvDuration = holder.findView(R.id.tv_chat_listitem_video_content_duration);
    TextView tvFileLength = holder.findView(R.id.tv_chat_listitem_video_content_filelength);

    EMVideoMessageBody messageBody = (EMVideoMessageBody) emMessage.getBody();

    //缩略图
    String localThumb = messageBody.getLocalThumb();
    String remoteThumb = messageBody.getThumbnailUrl();
    if (StringUtil.isNotEmpty(localThumb) && new File(localThumb).exists())
        CommonUtils.getInstance().getImageDisplayer()
                .display(mContext, imgThumb, localThumb, 240, 300);
    else
        CommonUtils.getInstance().getImageDisplayer()
                .display(mContext, imgThumb, remoteThumb, 240, 300);
    //视频时长
    String durationEx = mContext.getResources().getString(R.string.tv_chat_listitem_video_duration_Ex);
    String duration = durationEx.replaceFirst("%%1", String.valueOf(messageBody.getDuration()));
    tvDuration.setText(duration);
    //视频大小
    tvFileLength.setText(formetFileSize(messageBody.getVideoFileLength()));

    //点击播放
    holder.setClickListener(R.id.img_chat_listitem_video_start, new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            mPresenter.clickVideoMessage(emMessage, position);
        }
    });
    setMessage(holder, emMessage, position);
}
 
Example 8
Source File: HxShortVideoPlayPresenter.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化视频数据
 */
public void initData(EMMessage message)
{
    String msgId = message.getMsgId();
    EMVideoMessageBody messageBody = (EMVideoMessageBody) message.getBody();
    //检查文件是否存在本地文件
    String localUrl = messageBody.getLocalUrl();
    if (new File(localUrl).exists())
    {
        //存在就直接播放
        mViewImpl.startPlayVideo(localUrl);
        return;
    }

    //检查是否下载过
    ShortVideoBean videoBean = mModel.queryDataByMsgId(msgId);
    if (videoBean == null)
    {
        //没有下载过就直接下载
        downLoadRemoteUrlVideo(msgId, messageBody.getRemoteUrl());
    } else
    {
        //下载过就检查文件是否还在
        String downLoadUrl = videoBean.getLocal_url();
        if (new File(downLoadUrl).exists())
        {
            //下载的文件存在就直接播放
            mViewImpl.startPlayVideo(downLoadUrl);
        } else
        {
            //下载的文件不存在就重新下载
            ShortVideoDao.getInstance().delete(videoBean);
            downLoadRemoteUrlVideo(msgId, messageBody.getRemoteUrl());
        }
    }
}
 
Example 9
Source File: EaseCommonUtils.java    From Social with Apache License 2.0 4 votes vote down vote up
/**
     * 根据消息内容和消息类型获取消息内容提示
     * 
     * @param message
     * @param context
     * @return
     */
    public static String getMessageDigest(EMMessage message, Context context) {
        String digest = "";
        switch (message.getType()) {
        case LOCATION: // 位置消息
            if (message.direct() == EMMessage.Direct.RECEIVE) {
                //从sdk中提到了ui中,使用更简单不犯错的获取string方法
//              digest = EasyUtils.getAppResourceString(context, "location_recv");
                digest = getString(context, R.string.location_recv);
                digest = String.format(digest, message.getFrom());
                return digest;
            } else {
//              digest = EasyUtils.getAppResourceString(context, "location_prefix");
                digest = getString(context, R.string.location_prefix);
            }
            break;
        case IMAGE: // 图片消息
            digest = getString(context, R.string.picture);
            break;
        case VOICE:// 语音消息
            digest = getString(context, R.string.voice_prefix);
            break;
        case VIDEO: // 视频消息
            digest = getString(context, R.string.video);
            break;
        case TXT: // 文本消息
            EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
            /*if(((DemoHXSDKHelper)HXSDKHelper.getInstance()).isRobotMenuMessage(message)){
                digest = ((DemoHXSDKHelper)HXSDKHelper.getInstance()).getRobotMenuMessageDigest(message);
            }else */if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_VOICE_CALL, false)){
                digest = getString(context, R.string.voice_call) + txtBody.getMessage();
            }else if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_VIDEO_CALL, false)){
                digest = getString(context, R.string.video_call) + txtBody.getMessage();
            }else if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
                if(!TextUtils.isEmpty(txtBody.getMessage())){
                    digest = txtBody.getMessage();
                }else{
                    digest = getString(context, R.string.dynamic_expression);
                }
            }else{
                digest = txtBody.getMessage();
            }
            break;
        case FILE: //普通文件消息
            digest = getString(context, R.string.file);
            break;
        default:
            EMLog.e(TAG, "error, unknow type");
            return "";
        }

        return digest;
    }
 
Example 10
Source File: EaseCommonUtils.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
/**
 * Get digest according message type and content
 * 
 * @param message
 * @param context
 * @return
 */
public static String getMessageDigest(EMMessage message, Context context) {
    String digest = "";
    switch (message.getType()) {
    case LOCATION:
        if (message.direct() == EMMessage.Direct.RECEIVE) {
            digest = getString(context, R.string.location_recv);
            digest = String.format(digest, message.getFrom());
            return digest;
        } else {
            digest = getString(context, R.string.location_prefix);
        }
        break;
    case IMAGE:
        digest = getString(context, R.string.picture);
        break;
    case VOICE:
        digest = getString(context, R.string.voice_prefix);
        break;
    case VIDEO:
        digest = getString(context, R.string.video);
        break;
    case TXT:
        EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
        if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_VOICE_CALL, false)){
            digest = getString(context, R.string.voice_call) + txtBody.getMessage();
        }else if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_VIDEO_CALL, false)){
            digest = getString(context, R.string.video_call) + txtBody.getMessage();
        }else if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
            if(!TextUtils.isEmpty(txtBody.getMessage())){
                digest = txtBody.getMessage();
            }else{
                digest = getString(context, R.string.dynamic_expression);
            }
        }else{
            digest = txtBody.getMessage();
        }
        break;
    case FILE:
        digest = getString(context, R.string.file);
        break;
    default:
        EMLog.e(TAG, "error, unknow type");
        return "";
    }

    return digest;
}
 
Example 11
Source File: EaseCommonUtils.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
/**
     * 根据消息内容和消息类型获取消息内容提示
     * 
     * @param message
     * @param context
     * @return
     */
    public static String getMessageDigest(EMMessage message, Context context) {
        String digest = "";
        switch (message.getType()) {
        case LOCATION: // 位置消息
            if (message.direct() == EMMessage.Direct.RECEIVE) {
                //从sdk中提到了ui中,使用更简单不犯错的获取string方法
//              digest = EasyUtils.getAppResourceString(context, "location_recv");
                digest = getString(context, R.string.location_recv);
                digest = String.format(digest, message.getFrom());
                return digest;
            } else {
//              digest = EasyUtils.getAppResourceString(context, "location_prefix");
                digest = getString(context, R.string.location_prefix);
            }
            break;
        case IMAGE: // 图片消息
            digest = getString(context, R.string.picture);
            break;
        case VOICE:// 语音消息
            digest = getString(context, R.string.voice_prefix);
            break;
        case VIDEO: // 视频消息
            digest = getString(context, R.string.video);
            break;
        case TXT: // 文本消息
            EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
            /*if(((DemoHXSDKHelper)HXSDKHelper.getInstance()).isRobotMenuMessage(message)){
                digest = ((DemoHXSDKHelper)HXSDKHelper.getInstance()).getRobotMenuMessageDigest(message);
            }else */if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_VOICE_CALL, false)){
                digest = getString(context, R.string.voice_call) + txtBody.getMessage();
            }else if(message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
                if(!TextUtils.isEmpty(txtBody.getMessage())){
                    digest = txtBody.getMessage();
                }else{
                    digest = getString(context, R.string.dynamic_expression);
                }
            }else{
                digest = txtBody.getMessage();
            }
            break;
        case FILE: //普通文件消息
            digest = getString(context, R.string.file);
            break;
        default:
            EMLog.e(TAG, "error, unknow type");
            return "";
        }

        return digest;
    }
 
Example 12
Source File: VoiceMessageBaseItemView.java    From FamilyChat with Apache License 2.0 4 votes vote down vote up
@Override
public void setMessageData(RcvHolder holder, final EMMessage emMessage, final int position)
{
    final EMVoiceMessageBody messageBody = (EMVoiceMessageBody) emMessage.getBody();
    final FrameAnimImageView imgLabel = holder.findView(R.id.img_chat_listitem_voice_content);
    TextView tvLength = holder.findView(R.id.tv_chat_listitem_voice_content);
    View vLayout = holder.findView(R.id.fl_chat_listitem_voice_content);

    int voiceLength = messageBody.getLength();
    ViewGroup.LayoutParams layoutParams = vLayout.getLayoutParams();
    if (voiceLength <= MIN_VOICE_LENGTH)
        layoutParams.width = MIN_LAYOUT_WIDTH;
    else if (voiceLength >= MAX_VOICE_LENGTH)
        layoutParams.width = MAX_LAYOUT_WIDTH;
    else
        layoutParams.width = MIN_LAYOUT_WIDTH
                + (MAX_LAYOUT_WIDTH - MIN_LAYOUT_WIDTH)
                * (voiceLength - MIN_VOICE_LENGTH) / 5;//5=MAX_VOICE_LENGTH-MIN_VOICE_LENGTH
    vLayout.setLayoutParams(layoutParams);

    if (mPresenter.getCurPlayVoicePosition() == position)
    {
        if (emMessage.direct() == EMMessage.Direct.SEND)
            imgLabel.start(mAnimRight, true, ANIM_DURATION);
        else
            imgLabel.start(mAnimLeft, true, ANIM_DURATION);
    } else
    {
        imgLabel.stop();
        if (emMessage.direct() == EMMessage.Direct.SEND)
            imgLabel.setImageResource(R.drawable.ic_voice_right03);
        else
            imgLabel.setImageResource(R.drawable.ic_voice_left03);
    }

    //设置时长
    String lengthEx = mContext.getResources().getString(R.string.tv_chat_listitem_voice_length_Ex);
    String length = lengthEx.replaceFirst("%%1", String.valueOf(voiceLength));
    tvLength.setText(length);

    //是否已听
    if (emMessage.direct() == EMMessage.Direct.RECEIVE)
    {
        TextView tvUnlisten = holder.findView(R.id.tv_chat_listitem_voice_unlisten);
        if (emMessage.isListened())
            tvUnlisten.setVisibility(View.GONE);
        else
            tvUnlisten.setVisibility(View.VISIBLE);
    }

    //设置点击事件
    holder.setClickListener(R.id.fl_chat_listitem_voice_content, new VoiceClickListener(imgLabel, emMessage, position));

    setMessage(holder, emMessage, position);
}
 
Example 13
Source File: ImageMessageBaseItemView.java    From FamilyChat with Apache License 2.0 4 votes vote down vote up
@Override
public void setMessageData(RcvHolder holder, final EMMessage emMessage, final int position)
{
    EMImageMessageBody messageBody = (EMImageMessageBody) emMessage.getBody();
    //根据图片高度计算ImageView的尺寸
    int imgWidth = messageBody.getWidth();
    int imgHeight = messageBody.getHeight();
    if (imgWidth >= MAX_IMAGE_SIZE)
    {
        mLayoutWidth = MAX_IMAGE_SIZE;
        mLayoutHeight = mLayoutWidth * imgHeight / imgWidth;
    } else if (imgHeight >= MAX_IMAGE_SIZE)
    {
        mLayoutHeight = MAX_IMAGE_SIZE;
        mLayoutWidth = mLayoutHeight * imgWidth / imgHeight;
    } else
    {
        mLayoutWidth = imgWidth >= MIN_IMAGE_SIZE ? imgWidth : MIN_IMAGE_SIZE;
        mLayoutHeight = imgHeight >= MIN_IMAGE_SIZE ? imgHeight : MIN_IMAGE_SIZE;
    }

    SelectableRoundedImageView imageView = holder.findView(R.id.img_chat_listitem_img_content);
    ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
    layoutParams.width = mLayoutWidth + PADDING_LEFT + PADDING_RIGHT;
    layoutParams.height = mLayoutHeight + PADDING_TOP + PADDING_BOTTOM;
    imageView.setLayoutParams(layoutParams);

    //判断显示图地址
    String localUrl = messageBody.getLocalUrl();
    String remoteUrl = messageBody.getRemoteUrl();
    if (emMessage.direct() == EMMessage.Direct.SEND && StringUtil.isNotEmpty(localUrl) && new File(localUrl).exists())
        CommonUtils.getInstance().getImageDisplayer()
                .display(mContext, imageView, localUrl, mLayoutWidth, mLayoutHeight);
    else
        CommonUtils.getInstance().getImageDisplayer()
                .display(mContext, imageView, remoteUrl, mLayoutWidth, mLayoutHeight);

    //设置点击事件
    imageView.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            mPresenter.clickImageMessage(emMessage, position);
        }
    });

    setMessage(holder, emMessage, position);
}