Exemplo n.º 1
0
  private void handle_getList() {

    if (!isSX) {
      isSX = true;

      messageList = new ArrayList<Message_wddd_wz>();

      now_add.clear();
      try {
        String a = "";
        a =
            Chuli.getHtml(
                Chuli.yuming
                    + "/App/AppPost.aspx?action=MyWzBillList&PageIndex="
                    + now_page
                    + "&PageSize=10&Status=&UserId="
                    + BaseActivity.now_userid
                    + "&LoginName="
                    + BaseActivity.now_userloginname
                    + "&PassWord="******"地址",
            Chuli.yuming
                + "/App/AppPost.aspx?action=MyWzBillList&PageIndex="
                + now_page
                + "&PageSize=10&Status=&UserId="
                + BaseActivity.now_userid
                + "&LoginName="
                + BaseActivity.now_userloginname
                + "&PassWord="******"返回:", a);

        a = a.substring(1, a.length());
        a = a.substring(0, a.length() - 1);

        JSONObject p = new JSONObject(a);
        String data = p.getString("Data");
        JSONArray p2 = new JSONArray(data);
        JSONObject p3;
        for (int i = 0; i < p2.length(); i++) {
          p3 = p2.getJSONObject(i);

          Message_wddd_wz message = new Message_wddd_wz();
          message.setcphm(p3.getString("车牌号码").trim());
          message.setddh(p3.getString("订单编号"));
          message.setUrl("");
          message.setId(p3.getString("文书编号"));
          message.setddzt(p3.getString("状态"));
          message.setfkje(p3.getString("罚款金额"));
          message.setfwf(p3.getString("服务费"));
          message.setxdrq(p3.getString("下单时间"));

          message.setwfdd(p3.getString("违法地点"));
          message.setwfsj(p3.getString("违法时间"));
          message.setwfdm(p3.getString("违法代码"));
          message.setwsbh(p3.getString("文书编号"));

          now_add.add("");
          messageList.add(message);

          //	 loadImage(Chuli.yuming+p3.getString("titlephoto"),i);

        }

      } catch (Exception e) {
        e.printStackTrace();
      }

    } else {

      now_add.clear();
      now_page = now_page + 1;

      String a = "";
      a =
          Chuli.getHtml(
              Chuli.yuming
                  + "/App/AppPost.aspx?action=MyWzBillList&PageIndex="
                  + now_page
                  + "&PageSize=10&UserId="
                  + BaseActivity.now_userid
                  + "&LoginName="
                  + BaseActivity.now_userloginname
                  + "&PassWord="******"地址",
          Chuli.yuming
              + "/App/AppPost.aspx?action=MyWzBillList&PageIndex="
              + now_page
              + "&PageSize=10&UserId="
              + BaseActivity.now_userid
              + "&LoginName="
              + BaseActivity.now_userloginname
              + "&PassWord="******"返回:", a);

      a = a.substring(1, a.length());
      a = a.substring(0, a.length() - 1);

      try {
        JSONObject p = new JSONObject(a);
        String data = p.getString("Data");
        JSONArray p2 = new JSONArray(data);
        JSONObject p3;
        for (int i = 0; i < p2.length(); i++) {
          p3 = p2.getJSONObject(i);

          Message_wddd_wz message = new Message_wddd_wz();
          message.setcphm(p3.getString("车牌号码").trim());
          message.setddh(p3.getString("订单编号"));
          message.setUrl("");
          message.setId(p3.getString("文书编号"));
          message.setddzt(p3.getString("状态"));
          message.setfkje(p3.getString("罚款金额"));
          message.setfwf(p3.getString("服务费"));
          message.setxdrq(p3.getString("下单时间"));

          message.setwfdd(p3.getString("违法地点"));
          message.setwfsj(p3.getString("违法时间"));
          message.setwfdm(p3.getString("违法代码"));
          message.setwsbh(p3.getString("文书编号"));

          now_add.add("");
          messageList.add(message);

          //	 loadImage(Chuli.yuming+p3.getString("titlephoto"),i);

        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    try {
      for (int i = 0; i < messageList.size(); i++) {
        Message_wddd_wz message = messageList.get(i);
        messageTemp.add(message);
        HashMap<String, Object> hashmap = new HashMap<String, Object>();
        hashmap.put("message", message.getcphm());
        hashmap.put("time", message.getId());
        hashmap.put("imgitem", R.drawable.cxmr);
        arraylist.add(hashmap);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder1 = null;
    ViewHolder holder2 = null;
    // AVIMTypedMessage message = messageList.get(position);
    AVIMTextMessage message = (AVIMTextMessage) messageList.get(position);
    String text;
    /*
    Thread t3 = new Thread() {
     	 @Override
     	public void run() {
        	try{
        		bitmapavatal = ImageTools.GetLocalOrNetBitmap(BaseActivity.now_userimgheadurl);
        	}
        	catch(Exception e)
        	{
        		Log.d("image upload ", e.toString());
        	}
        }
    };
    t3.start();
    */

    if (AVIMReservedMessageType.getAVIMReservedMessageType(message.getMessageType())
        == AVIMReservedMessageType.TextMessageType) {
      AVIMTextMessage textMessage = (AVIMTextMessage) message;
      text = textMessage.getText();
    } else {
      text = message.getContent();
    }
    // Log.v("来源:",message.getFrom()+" 自己:"+selfId+" 信息:"+text);

    if (message.getFrom().trim().equals(selfId.trim())) {

      if (convertView == null) {
        Log.v("设置了自己1", "1");
        convertView = LayoutInflater.from(context).inflate(R.layout.list_xx2, null);
        holder1 = new ViewHolder();
        holder1.messageText = (TextView) convertView.findViewById(R.id.list_xx2_text_content);
        holder1.sender = (TextView) convertView.findViewById(R.id.list_xx2_text_name);
        holder1.time = (TextView) convertView.findViewById(R.id.list_xx2_text_time);
        holder1.id = (TextView) convertView.findViewById(R.id.list_xx2_text_id);
        holder1.avatalurl = (ImageView) convertView.findViewById(R.id.list_xx2_image);
        convertView.setTag(holder1);

      } else {
        Log.v("设置了自己2", "1");
        // holder1 = (ViewHolder) convertView.getTag();
        convertView = LayoutInflater.from(context).inflate(R.layout.list_xx2, null);
        holder1 = new ViewHolder();
        holder1.messageText = (TextView) convertView.findViewById(R.id.list_xx2_text_content);
        holder1.sender = (TextView) convertView.findViewById(R.id.list_xx2_text_name);
        holder1.time = (TextView) convertView.findViewById(R.id.list_xx2_text_time);
        holder1.id = (TextView) convertView.findViewById(R.id.list_xx2_text_id);
        holder1.avatalurl = (ImageView) convertView.findViewById(R.id.list_xx2_image);
        convertView.setTag(holder1);
      }
    } else {

      if (convertView == null) {
        Log.v("设置了他人1", "1");
        convertView = LayoutInflater.from(context).inflate(R.layout.list_xx, null);
        holder2 = new ViewHolder();
        holder2.messageText = (TextView) convertView.findViewById(R.id.list_xx_text_content);
        holder2.sender = (TextView) convertView.findViewById(R.id.list_xx_text_name);
        holder2.time = (TextView) convertView.findViewById(R.id.list_xx_text_time);
        holder2.id = (TextView) convertView.findViewById(R.id.list_xx_text_id);
        holder2.avatalurl = (ImageView) convertView.findViewById(R.id.list_xx_image);
        convertView.setTag(holder2);

      } else {
        Log.v("设置了他人2", "1");
        // holder2 = (ViewHolder) convertView.getTag();
        convertView = LayoutInflater.from(context).inflate(R.layout.list_xx, null);
        holder2 = new ViewHolder();
        holder2.messageText = (TextView) convertView.findViewById(R.id.list_xx_text_content);
        holder2.sender = (TextView) convertView.findViewById(R.id.list_xx_text_name);
        holder2.time = (TextView) convertView.findViewById(R.id.list_xx_text_time);
        holder2.id = (TextView) convertView.findViewById(R.id.list_xx_text_id);
        holder2.avatalurl = (ImageView) convertView.findViewById(R.id.list_xx_image);
        convertView.setTag(holder2);
      }
    }

    if (AVIMReservedMessageType.getAVIMReservedMessageType(message.getMessageType())
        == AVIMReservedMessageType.TextMessageType) {
      AVIMTextMessage textMessage = (AVIMTextMessage) message;

      try {
        text = textMessage.getText().substring(0, textMessage.getText().indexOf("NAME"));
      } catch (Exception e) {
        text = textMessage.getText();
      }
    } else {
      try {
        text = message.getContent().substring(0, message.getContent().indexOf("NAME"));

      } catch (Exception e) {
        text = message.getContent();
      }
    }

    if (message.getFrom().equals(selfId)) {

      holder1.messageText.setText(text);
      holder1.sender.setText("我");
      holder1.time.setText("" + Chuli.getNormalTime(message.getTimestamp()));
      try {
        if (BaseActivity.bitmapavatal != null) {
          // Bitmap tempAvatal = ImageTools.GetLocalOrNetBitmap(BaseActivity.now_userimgheadurl);
          // holder1.avatalurl.setImageBitmap(tempAvatal);//.setImageResource(bitmapavatal);
          holder1.avatalurl.setImageBitmap(
              BaseActivity.bitmapavatal); // .setImageResource(bitmapavatal);
          // Bitmap bitmapAvatal = (Bitmap) message.getAttrs().get("avatal_url");
          // holder1.avatalurl.setImageBitmap(bitmapAvatal);
        }
      } catch (Exception ee) {
        Log.v("处理头像  ", ee.toString());
      }
      holder1.id.setText("" + message.getMessageId());

    } else {

      // 遍历学生列表匹配学生名字  设置姓名
      try {
        JSONArray p2 = new JSONArray(BaseActivity.now_studentlist);
        JSONObject p3;
        for (int i = 0; i < p2.length(); i++) {
          p3 = p2.getJSONObject(i);

          String st = p3.getString("student");
          JSONObject p4 = new JSONObject(st);

          // Log.v("当前ID:",message.getFrom()+":"+p4.getString("client_token"));
          if (message.getFrom().equals(p4.getString("client_token"))) {
            fromname = p4.getString("name");
            break;
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      holder2.messageText.setText(text);
      holder2.sender.setText(fromname);
      holder2.time.setText("" + Chuli.getNormalTime(message.getTimestamp()));
      try {
        // if(BaseActivity.bitmapavatal!=null){
        // holder2.avatalurl.setImageBitmap(BaseActivity.bitmapavatal);
        String avatalUrl = message.getAttrs().get("avatar_url").toString();
        Bitmap tempAvatal = ImageTools.GetLocalOrNetBitmap(avatalUrl);
        holder2.avatalurl.setImageBitmap(tempAvatal);
        // holder2.avatalurl.setImageBitmap();
        // }
      } catch (Exception ee) {
        Log.v("头像   ", ee.toString());
      }
      holder2.id.setText("" + message.getMessageId());
    }
    return convertView;
  }