@Override
    public View getView(final int position, View convertView, ViewGroup parent) {
      PhoneItem item = mlist.get(position);

      final View view =
          LayoutInflater.from(mContext)
              .inflate(R.layout.contact_detail_set_default_phone_list_item, null);
      TextView mType = (TextView) view.findViewById(R.id.textView1);
      TextView mNumber = (TextView) view.findViewById(R.id.textView2);
      final RadioButton mRadioButton = (RadioButton) view.findViewById(R.id.radioButton1);
      int t = ContactsContract.CommonDataKinds.Phone.getTypeLabelResource((int) item.type);

      mType.setText(mContext.getResources().getString(t));
      mNumber.setText(item.phoneNumber);
      if (mCheckedPosition == -1) {
        if (item.phoneNumber.equals(primaryPhone)) {
          mCheckedPosition = position;
        }
      }
      if (mCheckedPosition == position) {
        mRadioButton.setChecked(true);
      } else {
        mRadioButton.setChecked(false);
      }
      return view;
    }
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
    final DataHolder contactData = (DataHolder) view.getTag(R.id.contact_info_tag);
    final ViewHolder holder = (ViewHolder) view.getTag(R.id.holder_tag);
    if (holder == null) {
      Log.w(TAG, "ViewHolder was null. This should not happen.");
      return;
    }
    if (contactData == null) {
      Log.w(TAG, "DataHolder was null. This should not happen.");
      return;
    }
    if (ID_COLUMN < 0) {
      populateColumnIndices(cursor);
    }

    contactData.type = cursor.getInt(TYPE_COLUMN);
    contactData.name = cursor.getString(NAME_COLUMN);
    contactData.number = cursor.getString(NUMBER_COLUMN);
    contactData.numberType = cursor.getInt(NUMBER_TYPE_COLUMN);
    contactData.id = cursor.getLong(ID_COLUMN);

    if (contactData.type != ContactsDatabase.PUSH_TYPE) {
      holder.name.setTextColor(drawables.getColor(1, 0xff000000));
      holder.number.setTextColor(drawables.getColor(1, 0xff000000));
    } else {
      holder.name.setTextColor(drawables.getColor(0, 0xa0000000));
      holder.number.setTextColor(drawables.getColor(0, 0xa0000000));
    }

    if (selectedContacts.containsKey(contactData.id)) {
      holder.checkBox.setChecked(true);
    } else {
      holder.checkBox.setChecked(false);
    }

    holder.name.setText(contactData.name);

    if (contactData.number == null || contactData.number.isEmpty()) {
      holder.name.setEnabled(false);
      holder.number.setText("");
    } else if (contactData.type == ContactsDatabase.PUSH_TYPE) {
      holder.number.setText(contactData.number);
    } else {
      final CharSequence label =
          ContactsContract.CommonDataKinds.Phone.getTypeLabel(
              context.getResources(), contactData.numberType, "");
      final CharSequence numberWithLabel = contactData.number + "  " + label;
      final Spannable numberLabelSpan = new SpannableString(numberWithLabel);
      numberLabelSpan.setSpan(
          new ForegroundColorSpan(drawables.getColor(2, 0xff444444)),
          contactData.number.length(),
          numberWithLabel.length(),
          Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
      holder.number.setText(numberLabelSpan);
    }
    holder.contactPhoto.setImageBitmap(defaultCroppedPhoto);
    loadBitmap(contactData.number, holder.contactPhoto);
  }
Example #3
0
 public CharSequence getPhoneTypeLabel(Integer value) {
   if (value == null) {
     return StringUtil.EMPTY;
   }
   Context context = ContextHolder.get();
   return ContactsContract.CommonDataKinds.Phone.getTypeLabel(
       context.getResources(), value, StringUtil.EMPTY);
 }
  @Override
  public void bindView(View view, Context context, Cursor cursor) {
    long id = cursor.getLong(cursor.getColumnIndexOrThrow(ContactsDatabase.ID_COLUMN));
    int type = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsDatabase.TYPE_COLUMN));
    String name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN));
    String number = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_COLUMN));
    int numberType =
        cursor.getInt(cursor.getColumnIndexOrThrow(ContactsDatabase.NUMBER_TYPE_COLUMN));
    String label = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.LABEL_COLUMN));
    String labelText =
        ContactsContract.CommonDataKinds.Phone.getTypeLabel(
                context.getResources(), numberType, label)
            .toString();

    int color =
        (type == ContactsDatabase.PUSH_TYPE)
            ? drawables.getColor(0, 0xa0000000)
            : drawables.getColor(1, 0xff000000);

    ((ContactSelectionListItem) view).unbind();
    ((ContactSelectionListItem) view).set(id, type, name, number, labelText, color, multiSelect);
    ((ContactSelectionListItem) view).setChecked(selectedContacts.containsKey(id));
  }
 public CharSequence getTypeString(Resources r) {
   return ContactsContract.CommonDataKinds.Phone.getTypeLabel(r, category, label);
 }
Example #6
0
 @Override
 public String getTypeString(Resources resources) {
   return ContactsContract.CommonDataKinds.Phone.getTypeLabel(resources, getType(), getLabel())
       .toString();
 }