private void insertStructuredName(Cursor c, SQLiteStatement insert) {
    String name = c.getString(PeopleQuery.NAME);
    if (TextUtils.isEmpty(name)) {
      return;
    }

    long id = c.getLong(PeopleQuery._ID);

    insert.bindLong(StructuredNameInsert.RAW_CONTACT_ID, id);
    insert.bindLong(StructuredNameInsert.MIMETYPE_ID, mStructuredNameMimetypeId);
    bindString(insert, StructuredNameInsert.DISPLAY_NAME, name);

    NameSplitter.Name splitName = new NameSplitter.Name();
    mNameSplitter.split(splitName, name);

    bindString(insert, StructuredNameInsert.PREFIX, splitName.getPrefix());
    bindString(insert, StructuredNameInsert.GIVEN_NAME, splitName.getGivenNames());
    bindString(insert, StructuredNameInsert.MIDDLE_NAME, splitName.getMiddleName());
    bindString(insert, StructuredNameInsert.FAMILY_NAME, splitName.getFamilyName());
    bindString(insert, StructuredNameInsert.SUFFIX, splitName.getSuffix());

    if (mPhoneticNameAvailable) {
      // TODO: add the ability to insert an unstructured phonetic name
      String phoneticName = c.getString(PeopleQuery.PHONETIC_NAME);
    }

    long dataId = insert(insert);

    mContactsProvider.insertNameLookupForStructuredName(id, dataId, name);
  }
Exemplo n.º 2
0
  private void insertStructuredName(Cursor c, SQLiteStatement insert) {
    String name = c.getString(PeopleQuery.NAME);
    if (TextUtils.isEmpty(name)) {
      return;
    }

    long id = c.getLong(PeopleQuery._ID);

    insert.bindLong(StructuredNameInsert.RAW_CONTACT_ID, id);
    insert.bindLong(StructuredNameInsert.MIMETYPE_ID, mStructuredNameMimetypeId);
    bindString(insert, StructuredNameInsert.DISPLAY_NAME, name);

    NameSplitter.Name splitName = new NameSplitter.Name();
    mNameSplitter.split(splitName, name);

    bindString(insert, StructuredNameInsert.PREFIX, splitName.getPrefix());
    bindString(insert, StructuredNameInsert.GIVEN_NAME, splitName.getGivenNames());
    bindString(insert, StructuredNameInsert.MIDDLE_NAME, splitName.getMiddleName());
    bindString(insert, StructuredNameInsert.FAMILY_NAME, splitName.getFamilyName());
    bindString(insert, StructuredNameInsert.SUFFIX, splitName.getSuffix());
    final String joined = mNameSplitter.join(splitName, true);
    bindString(insert, StructuredNameInsert.DISPLAY_NAME, joined);

    if (mPhoneticNameAvailable) {
      String phoneticName = c.getString(PeopleQuery.PHONETIC_NAME);
      if (phoneticName != null) {
        int index = phoneticName.indexOf(' ');
        if (index == -1) {
          splitName.phoneticFamilyName = phoneticName;
        } else {
          splitName.phoneticFamilyName = phoneticName.substring(0, index).trim();
          splitName.phoneticGivenName = phoneticName.substring(index + 1).trim();
        }
      }
    }

    mNameSplitter.guessNameStyle(splitName);

    int fullNameStyle = splitName.getFullNameStyle();
    insert.bindLong(StructuredNameInsert.FULL_NAME_STYLE, fullNameStyle);
    bindString(insert, StructuredNameInsert.PHONETIC_FAMILY_NAME, splitName.phoneticFamilyName);
    bindString(insert, StructuredNameInsert.PHONETIC_MIDDLE_NAME, splitName.phoneticMiddleName);
    bindString(insert, StructuredNameInsert.PHONETIC_GIVEN_NAME, splitName.phoneticGivenName);
    insert.bindLong(StructuredNameInsert.PHONETIC_NAME_STYLE, splitName.phoneticNameStyle);

    long dataId = insert(insert);

    mContactsProvider.insertNameLookupForStructuredName(
        id, dataId, name, mNameSplitter.getAdjustedFullNameStyle(fullNameStyle));
    if (splitName.phoneticFamilyName != null
        || splitName.phoneticMiddleName != null
        || splitName.phoneticGivenName != null) {
      mContactsProvider.insertNameLookupForPhoneticName(
          id,
          dataId,
          splitName.phoneticFamilyName,
          splitName.phoneticMiddleName,
          splitName.phoneticGivenName);
    }
  }