com.hyphenate.chat.EMTextMessageBody Java Examples

The following examples show how to use com.hyphenate.chat.EMTextMessageBody. 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: 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 #3
Source File: MyEaseChatFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
/**
 * 转发消息
 *
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id);
    EMMessage.Type type = forward_msg.getType();
    switch (type) {
        case TXT:
            if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
                sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(),
                        forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null));
            }else{
                // 获取消息内容,发送消息
                String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage();
                sendTextMessage(content);
            }
            break;
        case IMAGE:
            // 发送图片
            String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl();
            if (filePath != null) {
                File file = new File(filePath);
                if (!file.exists()) {
                    // 不存在大图发送缩略图
                    filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath();
                }
                sendImageMessage(filePath);
            }
            break;
        default:
            break;
    }

    if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example #4
Source File: EaseChatFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
/**
 * 转发消息
 * 
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id);
    EMMessage.Type type = forward_msg.getType();
    switch (type) {
    case TXT:
        if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
            sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(),
                    forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null));
        }else{
            // 获取消息内容,发送消息
            String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage();
            sendTextMessage(content);
        }
        break;
    case IMAGE:
        // 发送图片
        String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl();
        if (filePath != null) {
            File file = new File(filePath);
            if (!file.exists()) {
                // 不存在大图发送缩略图
                filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath();
            }
            sendImageMessage(filePath);
        }
        break;
    default:
        break;
    }
    
    if(forward_msg.getChatType() == ChatType.ChatRoom){
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example #5
Source File: EaseChatRowText.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
public void onSetUpView() {
    EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
    Spannable span = EaseSmileUtils.getSmiledText(context, txtBody.getMessage());
    // 设置内容
    contentView.setText(span, BufferType.SPANNABLE);

    handleTextMessage();
}
 
Example #6
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * forward message
 * 
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id);
    EMMessage.Type type = forward_msg.getType();
    switch (type) {
    case TXT:
        if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
            sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(),
                    forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null));
        }else{
            // get the content and send it
            String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage();
            sendTextMessage(content);
        }
        break;
    case IMAGE:
        // send image
        String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl();
        if (filePath != null) {
            File file = new File(filePath);
            if (!file.exists()) {
                // send thumb nail if original image does not exist
                filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath();
            }
            sendImageMessage(filePath);
        }
        break;
    default:
        break;
    }
    
    if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example #7
Source File: EaseChatRowText.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
@Override
public void onSetUpView() {
    EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
    Spannable span = EaseSmileUtils.getSmiledText(context, txtBody.getMessage());
    // 设置内容
    contentView.setText(span, BufferType.SPANNABLE);

    handleTextMessage();
}
 
Example #8
Source File: EaseChatFragment.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 转发消息
 * 
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id);
    EMMessage.Type type = forward_msg.getType();
    switch (type) {
    case TXT:
        if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
            sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(),
                    forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null));
        }else{
            // 获取消息内容,发送消息
            String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage();
            sendTextMessage(content);
        }
        break;
    case IMAGE:
        // 发送图片
        String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl();
        if (filePath != null) {
            File file = new File(filePath);
            if (!file.exists()) {
                // 不存在大图发送缩略图
                filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath();
            }
            sendImageMessage(filePath);
        }
        break;
    default:
        break;
    }
    
    if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example #9
Source File: EaseChatRowText.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onSetUpView() {
    EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
    Spannable span = EaseSmileUtils.getSmiledText(context, txtBody.getMessage());
    // 设置内容
    contentView.setText(span, BufferType.SPANNABLE);

    handleTextMessage();
}
 
Example #10
Source File: MyEaseChatFragment.java    From Social with Apache License 2.0 4 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_CODE_CAMERA) { // 发送照片
            if (cameraFile != null && cameraFile.exists())
                sendImageMessage(cameraFile.getAbsolutePath());
        } else if (requestCode == REQUEST_CODE_LOCAL) { // 发送本地图片
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null) {
                    sendPicByUri(selectedImage);
                }
            }
        } else if (requestCode == REQUEST_CODE_MAP) { // 地图
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                sendLocationMessage(latitude, longitude, locationAddress);
            } else {
                Toast.makeText(getActivity(), com.hyphenate.easeui.R.string.unable_to_get_loaction, 0).show();
            }

        } else if(requestCode == REQUEST_CODE_SHARE_DIALOG_ACTIVITY){
            isVip = 1;
            messageCount = 10;
        }else if(requestCode == REQUEST_CODE_SEND_RED_PACKET){
        }
    }


    if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
        switch (resultCode) {
            case ContextMenuActivity.RESULT_CODE_COPY: // 复制消息
                clipboard.setText(((EMTextMessageBody) contextMenuMessage.getBody()).getMessage());
                break;
            case ContextMenuActivity.RESULT_CODE_DELETE: // 删除消息
                conversation.removeMessage(contextMenuMessage.getMsgId());
                messageList.refresh();
                break;

            case ContextMenuActivity.RESULT_CODE_FORWARD: // 转发消息
                Toast.makeText(getActivity(),"转发",Toast.LENGTH_LONG).show();
                Intent intent = new Intent(getActivity(), ChooseForwardUserActivity.class);
                intent.putExtra("forward_msg_id", contextMenuMessage.getMsgId());
                startActivity(intent);
                break;
            case ContextMenuActivity.RESULT_CODE_WITHDRAW:
                //Toast.makeText(getActivity(),"撤回",Toast.LENGTH_LONG).show();
                Toast.makeText(getActivity(),"msgId = " + contextMenuMessage.getMsgId(),Toast.LENGTH_LONG).show();
                withdrawMsg();
                break;

            default:
                break;
        }
    }
}
 
Example #11
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 #12
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 #13
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;
    }