/**
   * Loads data from the content provider, organizes it into {@link RawContactInfo} objects and
   * returns a sorted list of {@link RawContactInfo}'s.
   */
  private List<RawContactInfo> loadData() {
    HashMap<Long, RawContactInfo> rawContactInfos = new HashMap<Long, RawContactInfo>();
    Uri dataUri = Uri.withAppendedPath(mAggregateUri, Data.CONTENT_DIRECTORY);
    Cursor cursor =
        getContext().getContentResolver().query(dataUri, SplitQuery.COLUMNS, null, null, null);
    try {
      while (cursor.moveToNext()) {
        long rawContactId = cursor.getLong(SplitQuery.RAW_CONTACT_ID);
        RawContactInfo info = rawContactInfos.get(rawContactId);
        if (info == null) {
          info = new RawContactInfo(rawContactId);
          rawContactInfos.put(rawContactId, info);
          info.accountType = cursor.getString(SplitQuery.ACCOUNT_TYPE);
          info.dataSet = cursor.getString(SplitQuery.DATA_SET);
        }

        String mimetype = cursor.getString(SplitQuery.MIMETYPE);
        if (StructuredName.CONTENT_ITEM_TYPE.equals(mimetype)) {
          loadStructuredName(cursor, info);
        } else if (Phone.CONTENT_ITEM_TYPE.equals(mimetype)) {
          loadPhoneNumber(cursor, info);
        } else if (Email.CONTENT_ITEM_TYPE.equals(mimetype)) {
          loadEmail(cursor, info);
        } else if (Nickname.CONTENT_ITEM_TYPE.equals(mimetype)) {
          loadNickname(cursor, info);
        }
      }
    } finally {
      cursor.close();
    }

    List<RawContactInfo> list = new ArrayList<RawContactInfo>(rawContactInfos.values());
    Collections.sort(list);
    return list;
  }
  public List<Suggestion> getSuggestions() {
    ArrayList<Suggestion> list = Lists.newArrayList();
    if (mDataCursor != null) {
      Suggestion suggestion = null;
      long currentContactId = -1;
      mDataCursor.moveToPosition(-1);
      while (mDataCursor.moveToNext()) {
        long contactId = mDataCursor.getLong(DataQuery.CONTACT_ID);
        if (contactId != currentContactId) {
          suggestion = new Suggestion();
          suggestion.contactId = contactId;
          suggestion.name = mDataCursor.getString(DataQuery.DISPLAY_NAME);
          suggestion.lookupKey = mDataCursor.getString(DataQuery.LOOKUP_KEY);
          suggestion.rawContacts = Lists.newArrayList();
          list.add(suggestion);
          currentContactId = contactId;
        }

        long rawContactId = mDataCursor.getLong(DataQuery.RAW_CONTACT_ID);
        if (!containsRawContact(suggestion, rawContactId)) {
          RawContact rawContact = new RawContact();
          rawContact.rawContactId = rawContactId;
          rawContact.accountName = mDataCursor.getString(DataQuery.ACCOUNT_NAME);
          rawContact.accountType = mDataCursor.getString(DataQuery.ACCOUNT_TYPE);
          rawContact.dataSet = mDataCursor.getString(DataQuery.DATA_SET);
          suggestion.rawContacts.add(rawContact);
        }

        String mimetype = mDataCursor.getString(DataQuery.MIMETYPE);
        if (Phone.CONTENT_ITEM_TYPE.equals(mimetype)) {
          String data = mDataCursor.getString(DataQuery.DATA1);
          int superprimary = mDataCursor.getInt(DataQuery.IS_SUPERPRIMARY);
          if (!TextUtils.isEmpty(data) && (superprimary != 0 || suggestion.phoneNumber == null)) {
            suggestion.phoneNumber = data;
          }
        } else if (Email.CONTENT_ITEM_TYPE.equals(mimetype)) {
          String data = mDataCursor.getString(DataQuery.DATA1);
          int superprimary = mDataCursor.getInt(DataQuery.IS_SUPERPRIMARY);
          if (!TextUtils.isEmpty(data) && (superprimary != 0 || suggestion.emailAddress == null)) {
            suggestion.emailAddress = data;
          }
        } else if (Nickname.CONTENT_ITEM_TYPE.equals(mimetype)) {
          String data = mDataCursor.getString(DataQuery.DATA1);
          if (!TextUtils.isEmpty(data)) {
            suggestion.nickname = data;
          }
        } else if (Photo.CONTENT_ITEM_TYPE.equals(mimetype)) {
          long dataId = mDataCursor.getLong(DataQuery.ID);
          long photoId = mDataCursor.getLong(DataQuery.PHOTO_ID);
          if (dataId == photoId && !mDataCursor.isNull(DataQuery.PHOTO)) {
            suggestion.photo = mDataCursor.getBlob(DataQuery.PHOTO);
          }
        }
      }
    }
    return list;
  }