Beispiel #1
0
    public View getView(int position, View convertView, ViewGroup parent) {
      FollowListItem item = null;
      boolean simpleMode = "FacebookMessenger".equals(platform.getName());
      if (convertView == null) {
        LinearLayout llItem = new LinearLayout(parent.getContext());
        item = new FollowListItem();
        llItem.setTag(item);
        convertView = llItem;

        int dp_52 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 52);
        int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(parent.getContext(), 10);
        int dp_5 = cn.sharesdk.framework.utils.R.dipToPx(parent.getContext(), 5);

        if (!simpleMode) {
          item.aivIcon = new AsyncImageView(getContext());
          LinearLayout.LayoutParams lpIcon = new LinearLayout.LayoutParams(dp_52, dp_52);
          lpIcon.gravity = Gravity.CENTER_VERTICAL;
          lpIcon.setMargins(dp_10, dp_5, dp_10, dp_5);
          item.aivIcon.setLayoutParams(lpIcon);
          llItem.addView(item.aivIcon);
        }

        LinearLayout llText = new LinearLayout(parent.getContext());
        llText.setPadding(0, dp_10, dp_10, dp_10);
        llText.setOrientation(LinearLayout.VERTICAL);
        LinearLayout.LayoutParams lpText =
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        lpText.gravity = Gravity.CENTER_VERTICAL;
        lpText.weight = 1;
        llText.setLayoutParams(lpText);
        llItem.addView(llText);

        item.tvName = new TextView(parent.getContext());
        item.tvName.setTextColor(0xff000000);
        item.tvName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        item.tvName.setSingleLine();
        if (simpleMode) {
          item.tvName.setPadding(dp_10, 0, 0, 0);
        }
        llText.addView(item.tvName);

        if (!simpleMode) {
          item.tvSign = new TextView(parent.getContext());
          item.tvSign.setTextColor(0x7f000000);
          item.tvSign.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
          item.tvSign.setSingleLine();
          llText.addView(item.tvSign);
        }

        item.ivCheck = new ImageView(parent.getContext());
        item.ivCheck.setPadding(0, 0, dp_10, 0);
        LinearLayout.LayoutParams lpCheck =
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        lpCheck.gravity = Gravity.CENTER_VERTICAL;
        item.ivCheck.setLayoutParams(lpCheck);
        llItem.addView(item.ivCheck);
      } else {
        item = (FollowListItem) convertView.getTag();
      }

      Following following = getItem(position);
      item.tvName.setText(following.screeName);
      if (!simpleMode) {
        item.tvSign.setText(following.description);
      }
      item.ivCheck.setImageBitmap(following.checked ? bmChd : bmUnch);
      if (!simpleMode) {
        if (isFling()) {
          Bitmap bm = BitmapProcessor.getBitmapFromCache(following.icon);
          if (bm != null && !bm.isRecycled()) {
            item.aivIcon.setImageBitmap(bm);
          } else {
            item.aivIcon.execute(null, AsyncImageView.DEFAULT_TRANSPARENT);
          }
        } else {
          item.aivIcon.execute(following.icon);
        }
      }

      if (position == getCount() - 1) {
        next();
      }
      return convertView;
    }
  @Override
  public View getView(
      final HashMap<String, Object> user, View convertView, final ViewGroup parent) {

    ViewHolder viewHolder;
    if (convertView == null) {
      viewHolder = new ViewHolder();
      LayoutInflater inflater = LayoutInflater.from(parent.getContext());
      int resId = getLayoutRes(parent.getContext(), "smssdk_contacts_listview_item");
      convertView = inflater.inflate(resId, null);
      resId = getIdRes(parent.getContext(), "iv_contact");
      viewHolder.ivContact = (AsyncImageView) convertView.findViewById(resId);
      resId = getIdRes(parent.getContext(), "tv_name");
      viewHolder.tvName = (TextView) convertView.findViewById(resId);
      resId = getIdRes(parent.getContext(), "tv_contact");
      viewHolder.tvContact = (TextView) convertView.findViewById(resId);
      resId = getIdRes(parent.getContext(), "btn_add");
      viewHolder.btnAdd = (Button) convertView.findViewById(resId);
      resId = getIdRes(parent.getContext(), "rl_lv_item_bg");
      viewHolder.bg = convertView.findViewById(resId);
      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }

    if (user != null) {
      // 如果user包含“fia”,则为应用内好友
      if (user.containsKey("fia")) {
        viewHolder.tvName.setText(String.valueOf(user.get("nickname")));
        viewHolder.tvContact.setVisibility(View.VISIBLE);
        String dspName = (String) user.get("displayname");
        if (TextUtils.isEmpty(dspName)) {
          viewHolder.tvContact.setText(String.valueOf(user.get("phone")));
        } else {
          viewHolder.tvContact.setText(dspName);
        }
        int resId = getStringRes(parent.getContext(), "smssdk_add_contact");
        if (resId > 0) {
          viewHolder.btnAdd.setText(resId);
        }
      } else {
        String dspName = (String) user.get("displayname");
        if (TextUtils.isEmpty(dspName)) {
          @SuppressWarnings("unchecked")
          ArrayList<HashMap<String, Object>> phones =
              (ArrayList<HashMap<String, Object>>) user.get("phones");
          if (phones != null && phones.size() > 0) {
            String cp = (String) phones.get(0).get("phone");
            viewHolder.tvName.setText(cp);
          }
        } else {
          viewHolder.tvName.setText(dspName);
        }
        viewHolder.tvContact.setVisibility(View.GONE);
        int resId = getStringRes(parent.getContext(), "smssdk_invite");
        if (resId > 0) {
          viewHolder.btnAdd.setText(resId);
        }
      }

      viewHolder.bg.setBackgroundColor(0xffffffff);
      // 是否有新好友,如有,改变背景颜色
      if (user.containsKey("isnew")) {
        boolean isNew = Boolean.valueOf(String.valueOf(user.get("isnew")));
        if (isNew) {
          viewHolder.bg.setBackgroundColor(0xfff7fcff);
        }
      }

      String iconUrl = user.containsKey("avatar") ? (String) user.get("avatar") : null;
      // 设置默认头像,如果有url,就去下载
      int resId = getBitmapRes(parent.getContext(), "smssdk_cp_default_avatar");
      if (resId > 0) {
        viewHolder.ivContact.execute(null, resId);
      }
      if (!TextUtils.isEmpty(iconUrl)) {
        Log.w(String.valueOf(user.get("displayname")) + " icon url ==>> ", iconUrl);
        Bitmap bm = BitmapProcessor.getBitmapFromCache(iconUrl);
        if (bm != null && !bm.isRecycled()) {
          viewHolder.ivContact.setImageBitmap(bm);
        } else {
          viewHolder.ivContact.execute(iconUrl);
        }
      }

      viewHolder.btnAdd.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              if (user.containsKey("fia")) {
                // 在这里添加第一组的按钮事件
                Toast.makeText(parent.getContext(), String.valueOf(user), Toast.LENGTH_SHORT)
                    .show();
              } else {
                ContactDetailPage contactDetailPage = new ContactDetailPage();
                contactDetailPage.setContact(user);
                contactDetailPage.show(parent.getContext(), null);
              }
            }
          });
    }
    return convertView;
  }