/**
   * 根据消息内容和消息类型获取消息内容提示
   *
   * @param message
   * @param context
   * @return
   */
  private 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 = getStrng(context, R.string.location_recv);
          digest = String.format(digest, message.getFrom());
          return digest;
        } else {
          // digest = EasyUtils.getAppResourceString(context,
          // "location_prefix");
          digest = getStrng(context, R.string.location_prefix);
        }
        break;
      case IMAGE: // 图片消息
        ImageMessageBody imageBody = (ImageMessageBody) message.getBody();
        digest = getStrng(context, R.string.picture) + imageBody.getFileName();
        break;
      case VOICE: // 语音消息
        digest = getStrng(context, R.string.voice);
        break;
      case VIDEO: // 视频消息
        digest = getStrng(context, R.string.video);
        break;
      case TXT: // 文本消息
        if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message)) {
          digest = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotMenuMessageDigest(message);
        } else if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) {
          TextMessageBody txtBody = (TextMessageBody) message.getBody();
          digest = getStrng(context, R.string.voice_call) + txtBody.getMessage();
        } else {
          TextMessageBody txtBody = (TextMessageBody) message.getBody();
          digest = txtBody.getMessage();
        }
        break;
      case FILE: // 普通文件消息
        digest = getStrng(context, R.string.file);
        break;
      default:
        EMLog.e(TAG, "unknow type");
        return "";
    }

    return digest;
  }
예제 #2
0
 @Override
 public void onSetUpView() {
   /** TODO:设置聊天表情* */
   TextMessageBody txtBody = (TextMessageBody) message.getBody();
   Spannable span = EmojiUtils.getSmiledText(context, txtBody.getMessage());
   // 设置内容
   contentView.setText(span, BufferType.SPANNABLE);
   //        contentView.setText(txtBody.getMessage());
   if (message.direct == EMMessage.Direct.SEND) {
     // 设置发送消息后的相关回调
     setMessageSendCallback();
     switch (message.status) {
       case CREATE:
         progressBar.setVisibility(View.VISIBLE);
         statusView.setVisibility(View.GONE);
         break;
       case SUCCESS: // 发送成功
         progressBar.setVisibility(View.GONE);
         statusView.setVisibility(View.GONE);
         break;
       case FAIL: // 发送失败,显示感叹号
         progressBar.setVisibility(View.GONE);
         statusView.setVisibility(View.VISIBLE);
         break;
       case INPROGRESS: // 发送中
         progressBar.setVisibility(View.VISIBLE);
         statusView.setVisibility(View.GONE);
         break;
       default:
         break;
     }
   }
   // 如果是接收的message
   else {
     // 如果是收到的message还没有向发送者发送ack
     // 那么赶紧ack收到的此消息
     if (!message.isAcked() && message.getChatType() == ChatType.Chat) {
       try {
         EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
         message.isAcked = true;
       } catch (EaseMobException e) {
         e.printStackTrace();
         LogUtils.debug("message:" + message.getMsgId() + "ack失败!" + e.toString());
       }
     }
   }
 }
예제 #3
0
 /**
  * 根据消息内容和消息类型获取消息内容提示
  *
  * @param message
  * @param context
  * @return
  */
 private String getMessageDigest(EMMessage message, Context context) {
   String digest = "";
   switch (message.getType()) {
     case LOCATION: // 位置消息
       if (message.direct == EMMessage.Direct.RECEIVE) {
         digest = getStrng(context, R.string.location_recv);
         String name = message.getFrom();
         if (GloableParams.UserInfos != null) {
           User user = GloableParams.Users.get(message.getFrom());
           if (null != user.getUserName()) name = user.getUserName();
         }
         digest = String.format(digest, message.getFrom());
         return digest;
       } else {
         digest = getStrng(context, R.string.location_prefix);
       }
       break;
     case IMAGE: // 图片消息
       ImageMessageBody imageBody = (ImageMessageBody) message.getBody();
       digest = getStrng(context, R.string.picture) + imageBody.getFileName();
       break;
     case VOICE: // 语音消息
       digest = getStrng(context, R.string.voice_msg);
       break;
     case VIDEO: // 视频消息
       digest = getStrng(context, R.string.video);
       break;
     case TXT: // 文本消息
       if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) {
         TextMessageBody txtBody = (TextMessageBody) message.getBody();
         digest = txtBody.getMessage();
       } else {
         TextMessageBody txtBody = (TextMessageBody) message.getBody();
         digest = getStrng(context, R.string.voice_call) + txtBody.getMessage();
       }
       break;
     case FILE: // 普通文件消息
       digest = getStrng(context, R.string.file);
       break;
     default:
       System.err.println("error, unknow type");
       return "";
   }
   return digest;
 }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   EMMessage message = conversation.getAllMessages().get(position);
   TextMessageBody body = (TextMessageBody) message.getBody();
   if (message.direct == EMMessage.Direct.RECEIVE) { // 接收方
     if (message.getType() == EMMessage.Type.TXT) {
       convertView = LayoutInflater.from(mcontext).inflate(R.layout.item_chatmsg, null);
       username = (TextView) convertView.findViewById(R.id.tv_chatusername);
       username.setText(message.getFrom());
     }
   } else {
     if (message.getType() == EMMessage.Type.TXT) {
       convertView = LayoutInflater.from(mcontext).inflate(R.layout.item_chatmsg2, null);
       username = (TextView) convertView.findViewById(R.id.tv_chatusername);
       //                username.setText(message.getFrom());
     }
   }
   msg = (TextView) convertView.findViewById(R.id.tv_chatmsg);
   msg.setText(body.getMessage());
   return convertView;
 }