/**
   * 根据消息内容和消息类型获取消息内容提示
   *
   * @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;
  }
Esempio n. 2
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;
 }
 public EaseChatRowVoicePlayClickListener(
     EMMessage message,
     ImageView v,
     ImageView iv_read_status,
     BaseAdapter adapter,
     Activity context) {
   this.message = message;
   voiceBody = (VoiceMessageBody) message.getBody();
   this.iv_read_status = iv_read_status;
   this.adapter = adapter;
   voiceIconView = v;
   this.activity = context;
   this.chatType = message.getChatType();
 }
 /**
  * @param message
  * @param v
  * @param iv_read_status
  * @param context
  * @param activity
  * @param user
  * @param chatType
  */
 public VoicePlayClickListener(
     EMMessage message,
     ImageView v,
     ImageView iv_read_status,
     BaseAdapter adapter,
     Activity activity,
     String username) {
   this.message = message;
   voiceBody = (VoiceMessageBody) message.getBody();
   this.iv_read_status = iv_read_status;
   this.adapter = adapter;
   voiceIconView = v;
   this.activity = activity;
   this.chatType = message.getChatType();
 }
 /**
  * @param message
  * @param v
  * @param iv_read_status
  * @param context
  * @param activity
  * @param user
  * @param chatType
  */
 public VoicePlayClickListener(
     EMMessage message,
     ImageView v,
     ImageView iv_read_status,
     Context context,
     Activity activity,
     String username) {
   this.message = message;
   voiceBody = (VoiceMessageBody) message.getBody();
   this.iv_read_status = iv_read_status;
   this.context = context;
   voiceIconView = v;
   this.activity = activity;
   this.username = username;
   this.chatType = message.getChatType();
 }
Esempio n. 6
0
        @SuppressWarnings("unused")
        @Override
        public void onReceive(Context context, Intent intent) {
          abortBroadcast();
          EMLog.d("收到消息", "收到透传消息");
          // 获取cmd message对象
          String msgId = intent.getStringExtra("msgid");
          EMMessage message = intent.getParcelableExtra("message");
          // 获取消息body
          CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody();
          String action = cmdMsgBody.action; // 获取自定义action

          // 获取扩展属性 此处省略
          //			message.getStringAttribute("");
          EMLog.d("收到消息", String.format("透传消息:action:%s,message:%s", action, message.toString()));
          //			String st9 = getResources().getString(R.string.receive_the_passthrough);
          //			Toast.makeText(MainActivity.this, st9+action, Toast.LENGTH_SHORT).show();
        }
Esempio n. 7
0
 @Override
 public void onReceive(Context context, Intent intent) {
   // 获取cmd message对象
   String msgId = intent.getStringExtra("msgid");
   EMMessage message = intent.getParcelableExtra("message");
   // 获取消息body
   CmdMessageBody cmdMsgBody = (CmdMessageBody) message.getBody();
   String aciton = cmdMsgBody.action; // 获取自定义action
   // 获取扩展属性
   try {
     String attr = message.getStringAttribute("photoUrl");
     ImageLoader.getInstance().getMemoryCache().remove(attr);
     ImageLoader.getInstance().getDiskCache().remove(attr);
     showToast("清除缓存");
     System.out.println("清除缓存");
   } catch (EaseMobException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
 @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;
 }