Java 类android.provider.ContactsContract.CommonDataKinds.StructuredName 实例源码

项目:phoneContact    文件:Utils.java   
public static void addContact(String name, String number)
{
    ContentValues values = new ContentValues(); 
       //������RawContacts.CONTENT_URIִ��һ����ֵ���룬Ŀ���ǻ�ȡϵͳ���ص�rawContactId  
       Uri rawContactUri = m_context.getContentResolver().insert(RawContacts.CONTENT_URI, values); 
       long rawContactId = ContentUris.parseId(rawContactUri); 
       //��data������������� 
       values.clear(); 
       values.put(Data.RAW_CONTACT_ID, rawContactId);  
       values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);//�������� 
       values.put(StructuredName.GIVEN_NAME, name); 
       m_context.getContentResolver().insert(ContactsContract.Data.CONTENT_URI, values);

       //��data�����绰���� 
       values.clear(); 
       values.put(Data.RAW_CONTACT_ID, rawContactId); 
       values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); 
       values.put(Phone.NUMBER, number); 
       values.put(Phone.TYPE, Phone.TYPE_MOBILE); 
       m_context.getContentResolver().insert(ContactsContract.Data.CONTENT_URI, values); 

}
项目:phoneContact    文件:Utils.java   
public static void changeContact(String name, String number, String ContactId)
{
    Log.i("huahua", name);
    ContentValues values = new ContentValues();
    // ��������
       values.put(StructuredName.GIVEN_NAME, name);
       m_context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
                       values,
                       Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE  + "=?",
                       new String[] { ContactId,StructuredName.CONTENT_ITEM_TYPE });

    //���µ绰
       values.clear();
       values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, number);
       m_context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
            values, 
            Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE  + "=?",
            new String[] { ContactId,Phone.CONTENT_ITEM_TYPE});
}
项目:digits-android    文件:VCardBuilder.java   
private boolean containsNonEmptyName(final ContentValues contentValues) {
    final String familyName = contentValues.getAsString(StructuredName.FAMILY_NAME);
    final String middleName = contentValues.getAsString(StructuredName.MIDDLE_NAME);
    final String givenName = contentValues.getAsString(StructuredName.GIVEN_NAME);
    final String prefix = contentValues.getAsString(StructuredName.PREFIX);
    final String suffix = contentValues.getAsString(StructuredName.SUFFIX);
    final String phoneticFamilyName =
            contentValues.getAsString(StructuredName.PHONETIC_FAMILY_NAME);
    final String phoneticMiddleName =
            contentValues.getAsString(StructuredName.PHONETIC_MIDDLE_NAME);
    final String phoneticGivenName =
            contentValues.getAsString(StructuredName.PHONETIC_GIVEN_NAME);
    final String displayName = contentValues.getAsString(StructuredName.DISPLAY_NAME);
    return !(TextUtils.isEmpty(familyName) && TextUtils.isEmpty(middleName) &&
            TextUtils.isEmpty(givenName) && TextUtils.isEmpty(prefix) &&
            TextUtils.isEmpty(suffix) && TextUtils.isEmpty(phoneticFamilyName) &&
            TextUtils.isEmpty(phoneticMiddleName) && TextUtils.isEmpty(phoneticGivenName) &&
            TextUtils.isEmpty(displayName));
}
项目:digits-android    文件:VCardBuilderTest.java   
@Test
public void testVCardNameFieldFromDisplayName() {
    final ArrayList<ContentValues> contentList = new ArrayList<>();

    final ContentValues values = new ContentValues();
    values.put(StructuredName.DISPLAY_NAME, "ने");
    contentList.add(values);

    final VCardBuilder builder = new VCardBuilder(VCardConfig.VCARD_TYPE_DEFAULT);
    builder.appendNameProperties(contentList);
    final String actual = builder.toString();

    final String expectedCommon = ";CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:" +
            "=E0=A4=A8=E0=A5=87";

    final String expectedName = "N" + expectedCommon + ";;;;";
    final String expectedFullName = "FN" + expectedCommon;

    assertTrue("Actual value:\n" + actual + " expected to contain\n" + expectedName +
            "\nbut does not.", actual.contains(expectedName));
    assertTrue("Actual value:\n" + actual + " expected to contain\n" + expectedFullName +
            "\nbut does not.", actual.contains(expectedFullName));
}
项目:digits-android    文件:VCardBuilderTest.java   
@Test
public void testAppendNameProperties_name() {
    final VCardBuilder builder = new VCardBuilder(VCardConfig.VCARD_TYPE_V30_GENERIC,
            VCardConfig.DEFAULT_EXPORT_CHARSET);
    final ContentValues cv = new ContentValues();
    final List<ContentValues> group = new ArrayList<>();

    cv.put(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
    cv.put(Email.DATA1, "Spruce Grouse");
    cv.put(Email.DATA2, "Spruce");
    cv.put(Email.DATA3, "Grouse");

    group.add(cv);

    final String card = builder.appendNameProperties(group).toString();

    assertEquals(NAME_CARD, card);
}
项目:contact    文件:PeopleDao.java   
public static List<String> getContactsName(ContentResolver contentResolver) {
    List<String> listPeopleName = null;
    Cursor cursor = null;
    try {
        cursor = contentResolver.query(
                ContactsContract.Contacts.CONTENT_URI,
                new String[] { ContactsContract.Contacts.DISPLAY_NAME },
                null, null, StructuredName.SORT_KEY_PRIMARY);
        listPeopleName = new ArrayList<String>();
        while (cursor.moveToNext()) {
            listPeopleName
                    .add(cursor.getString(cursor
                            .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return listPeopleName;

}
项目:mc_backup    文件:ContactService.java   
private void initColumnNameConstantsMap() {
    if (mColumnNameConstantsMap != null) {
        return;
    }
    mColumnNameConstantsMap = new HashMap<String, String>();

    mColumnNameConstantsMap.put("name", StructuredName.DISPLAY_NAME);
    mColumnNameConstantsMap.put("givenname", StructuredName.GIVEN_NAME);
    mColumnNameConstantsMap.put("familyname", StructuredName.FAMILY_NAME);
    mColumnNameConstantsMap.put("honorificprefix", StructuredName.PREFIX);
    mColumnNameConstantsMap.put("honorificsuffix", StructuredName.SUFFIX);
    mColumnNameConstantsMap.put("additionalname", CUSTOM_DATA_COLUMN);
    mColumnNameConstantsMap.put("nickname", Nickname.NAME);
    mColumnNameConstantsMap.put("adr", StructuredPostal.STREET);
    mColumnNameConstantsMap.put("email", Email.ADDRESS);
    mColumnNameConstantsMap.put("url", Website.URL);
    mColumnNameConstantsMap.put("category", GroupMembership.GROUP_ROW_ID);
    mColumnNameConstantsMap.put("tel", Phone.NUMBER);
    mColumnNameConstantsMap.put("org", Organization.COMPANY);
    mColumnNameConstantsMap.put("jobTitle", Organization.TITLE);
    mColumnNameConstantsMap.put("note", Note.NOTE);
    mColumnNameConstantsMap.put("impp", Im.DATA);
    mColumnNameConstantsMap.put("sex", CUSTOM_DATA_COLUMN);
    mColumnNameConstantsMap.put("genderidentity", CUSTOM_DATA_COLUMN);
    mColumnNameConstantsMap.put("key", CUSTOM_DATA_COLUMN);
}
项目:mc_backup    文件:ContactService.java   
private void initMimeTypeConstantsMap() {
    if (mMimeTypeConstantsMap != null) {
        return;
    }
    mMimeTypeConstantsMap = new HashMap<String, String>();

    mMimeTypeConstantsMap.put("name", StructuredName.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("givenname", StructuredName.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("familyname", StructuredName.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("honorificprefix", StructuredName.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("honorificsuffix", StructuredName.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("additionalname", MIMETYPE_ADDITIONAL_NAME);
    mMimeTypeConstantsMap.put("nickname", Nickname.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("email", Email.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("url", Website.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("category", GroupMembership.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("tel", Phone.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("org", Organization.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("jobTitle", Organization.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("note", Note.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("impp", Im.CONTENT_ITEM_TYPE);
    mMimeTypeConstantsMap.put("sex", MIMETYPE_SEX);
    mMimeTypeConstantsMap.put("genderidentity", MIMETYPE_GENDER_IDENTITY);
    mMimeTypeConstantsMap.put("key", MIMETYPE_KEY);
}
项目:mobilecloud-15    文件:InsertContactsCommand.java   
/**
 * Synchronously insert a contact with the designated @name into
 * the ContactsContentProvider.  This code is explained at
 * http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html.
 */
private void addContact(String name,
                        List<ContentProviderOperation> cpops) {
    final int position = cpops.size();

    // First part of operation.
    cpops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
              .withValue(RawContacts.ACCOUNT_TYPE,
                         mOps.getAccountType())
              .withValue(RawContacts.ACCOUNT_NAME,
                         mOps.getAccountName())
              .withValue(Contacts.STARRED,
                         1)
              .build());

    // Second part of operation.
    cpops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
              .withValueBackReference(Data.RAW_CONTACT_ID,
                                      position)
              .withValue(Data.MIMETYPE,
                         StructuredName.CONTENT_ITEM_TYPE)
              .withValue(StructuredName.DISPLAY_NAME,
                         name)
              .build());
}
项目:mobilecloud-15    文件:InsertContactsCommand.java   
/**
 * Synchronously insert a contact with the designated @name into
 * the ContactsContentProvider.  This code is explained at
 * http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html.
 */
private void addContact(String name,
                        List<ContentProviderOperation> cpops) {
    final int position = cpops.size();

    // First part of operation.
    cpops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
              .withValue(RawContacts.ACCOUNT_TYPE,
                         mOps.getAccountType())
              .withValue(RawContacts.ACCOUNT_NAME,
                         mOps.getAccountName())
              .withValue(Contacts.STARRED,
                         1)
              .build());

    // Second part of operation.
    cpops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
              .withValueBackReference(Data.RAW_CONTACT_ID,
                                      position)
              .withValue(Data.MIMETYPE,
                         StructuredName.CONTENT_ITEM_TYPE)
              .withValue(StructuredName.DISPLAY_NAME,
                         name)
              .build());
}
项目:android-authenticator    文件:ContactOperations.java   
/**
 * Adds a contact name. We can take either a full name ("Bob Smith") or separated
 * first-name and last-name ("Bob" and "Smith").
 *
 * @param fullName  The full name of the contact - typically from an edit form
 *                  Can be null if firstName/lastName are specified.
 * @param firstName The first name of the contact - can be null if fullName
 *                  is specified.
 * @param lastName  The last name of the contact - can be null if fullName
 *                  is specified.
 * @return instance of ContactOperations
 */
public ContactOperations addName(String fullName, String firstName, String lastName) {
    mValues.clear();

    if (!TextUtils.isEmpty(fullName)) {
        mValues.put(StructuredName.DISPLAY_NAME, fullName);
        mValues.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
    } else {
        if (!TextUtils.isEmpty(firstName)) {
            mValues.put(StructuredName.GIVEN_NAME, firstName);
            mValues.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
        }
        if (!TextUtils.isEmpty(lastName)) {
            mValues.put(StructuredName.FAMILY_NAME, lastName);
            mValues.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
        }
    }
    if (mValues.size() > 0) {
        addInsertOp();
    }
    return this;
}
项目:CucumberSync    文件:LocalAddressBook.java   
private void populateStructuredName(Contact c) throws RemoteException {
    @Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] {
            /* 0 */ StructuredName.DISPLAY_NAME, StructuredName.PREFIX, StructuredName.GIVEN_NAME,
            /* 3 */ StructuredName.MIDDLE_NAME, StructuredName.FAMILY_NAME, StructuredName.SUFFIX,
            /* 6 */ StructuredName.PHONETIC_GIVEN_NAME, StructuredName.PHONETIC_MIDDLE_NAME, StructuredName.PHONETIC_FAMILY_NAME
        }, StructuredName.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
        new String[] { String.valueOf(c.getLocalID()), StructuredName.CONTENT_ITEM_TYPE }, null);

    if (cursor != null && cursor.moveToNext()) {
        c.setDisplayName(cursor.getString(0));

        c.setPrefix(cursor.getString(1));
        c.setGivenName(cursor.getString(2));
        c.setMiddleName(cursor.getString(3));
        c.setFamilyName(cursor.getString(4));
        c.setSuffix(cursor.getString(5));

        c.setPhoneticGivenName(cursor.getString(6));
        c.setPhoneticMiddleName(cursor.getString(7));
        c.setPhoneticFamilyName(cursor.getString(8));
    }
}
项目:SafeSlinger-Android    文件:ContactAccessorApi5.java   
@Override
public boolean addName(ContactStruct contact, Cursor names) {
    String display = names.getString(names.getColumnIndex(StructuredName.DISPLAY_NAME));
    String family = names.getString(names.getColumnIndex(StructuredName.FAMILY_NAME));
    String given = names.getString(names.getColumnIndex(StructuredName.GIVEN_NAME));
    String middle = names.getString(names.getColumnIndex(StructuredName.MIDDLE_NAME));
    String prefix = names.getString(names.getColumnIndex(StructuredName.PREFIX));
    String suffix = names.getString(names.getColumnIndex(StructuredName.SUFFIX));
    boolean super_primary = (names.getInt(names
            .getColumnIndexOrThrow(StructuredName.IS_SUPER_PRIMARY)) != 0);
    if (!TextUtils.isEmpty(display) && isNameNew(contact, display, super_primary)) {
        contact.name = new Name(family, given, middle, prefix, suffix,
                Name.NAME_ORDER_TYPE_ENGLISH);
        return true;
    }
    return false;
}
项目:amap    文件:AddressServiceImpl.java   
public static void AddContact(ContentResolver mResolver, String name, String number, String groupName)
{
    Log.i("hoperun", "name= " + name + ";number=" + number);
    if (!queryFromContact(mResolver, name, number))
    {
        ContentValues values = new ContentValues();
        // 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
        Uri rawContactUri = mResolver.insert(RawContacts.CONTENT_URI, values);

        if (rawContactUri != null)
        {
            long rawContactId = ContentUris.parseId(rawContactUri);
            // 往data表插入姓名数据
            values.clear();
            values.put(Data.RAW_CONTACT_ID, rawContactId);
            values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);// 内容类型
            values.put(StructuredName.GIVEN_NAME, name);
            mResolver.insert(ContactsContract.Data.CONTENT_URI, values);
            // 往data表插入电话数据
            values.clear();
            values.put(Data.RAW_CONTACT_ID, rawContactId);
            values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
            values.put(Phone.NUMBER, number);
            values.put(Phone.TYPE, Phone.TYPE_MOBILE);
            mResolver.insert(ContactsContract.Data.CONTENT_URI, values);
        }
        else
        {
            Log.i("hoperun", "name= " + name + ";number=" + number);
        }

    }
    else
    {
        Log.i("hoperun", "repeat name= " + name + ";number=" + number);
    }
}
项目:SmartChart    文件:CommonUtils.java   
/**
 * 往手机通讯录插入联系人
 *
 * @param ct
 * @param name
 * @param tel
 * @param email
 */
public static void insertContact(Context ct, String name, String tel, String email) {
    ContentValues values = new ContentValues();
    // 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
    Uri rawContactUri = ct.getContentResolver().insert(RawContacts.CONTENT_URI, values);
    long rawContactId = ContentUris.parseId(rawContactUri);
    // 往data表入姓名数据
    if (!TextUtils.isEmpty(tel)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);// 内容类型
        values.put(StructuredName.GIVEN_NAME, name);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
    // 往data表入电话数据
    if (!TextUtils.isEmpty(tel)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);// 内容类型
        values.put(Phone.NUMBER, tel);
        values.put(Phone.TYPE, Phone.TYPE_MOBILE);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
    // 往data表入Email数据
    if (!TextUtils.isEmpty(email)) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);// 内容类型
        values.put(Email.DATA, email);
        values.put(Email.TYPE, Email.TYPE_WORK);
        ct.getContentResolver().insert(android.provider.ContactsContract.Data.CONTENT_URI, values);
    }
}
项目:react-native-paged-contacts    文件:Name.java   
private void fillFromCursor() {
    namePrefix = getString(StructuredName.PREFIX);
    givenName = getString(StructuredName.GIVEN_NAME);
    middleName = getString(StructuredName.MIDDLE_NAME);
    familyName = getString(StructuredName.FAMILY_NAME);
    nameSuffix = getString(StructuredName.SUFFIX);
    phoneticGivenName = getString(StructuredName.PHONETIC_GIVEN_NAME);
    phoneticMiddleName = getString(StructuredName.PHONETIC_MIDDLE_NAME);
    phoneticFamilyName = getString(StructuredName.PHONETIC_FAMILY_NAME);
}
项目:BigApp_Discuz_Android    文件:ContactUtils.java   
public static void insertContact(Context context, String name, String phone) {
    // 首先插入空值,再得到rawContactsId ,用于下面插值
    ContentValues values = new ContentValues();
    // insert a null value
    Uri rawContactUri = context.getContentResolver().insert(
            RawContacts.CONTENT_URI, values);
    long rawContactsId = ContentUris.parseId(rawContactUri);

    // 往刚才的空记录中插入姓名
    values.clear();
    // A reference to the _ID that this data belongs to
    values.put(StructuredName.RAW_CONTACT_ID, rawContactsId);
    // "CONTENT_ITEM_TYPE" MIME type used when storing this in data table
    values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
    // The name that should be used to display the contact.
    values.put(StructuredName.DISPLAY_NAME, name);
    // insert the real values
    context.getContentResolver().insert(Data.CONTENT_URI, values);
    // 插入电话
    values.clear();
    values.put(Phone.RAW_CONTACT_ID, rawContactsId);
    // String "Data.MIMETYPE":The MIME type of the item represented by this
    // row
    // String "CONTENT_ITEM_TYPE": MIME type used when storing this in data
    // table.
    values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
    values.put(Phone.NUMBER, phone);
    context.getContentResolver().insert(Data.CONTENT_URI, values);
}
项目:digits-android    文件:ContactsHelper.java   
private List<String> processContactsMap(Map<String, List<ContentValues>> mapContactsData) {
    final List<String> vCards = new ArrayList<>();
    final Map<String, List<ContentValues>> contactMimeTypeMap = new HashMap<>();
    final VCardBuilder builder = new VCardBuilder(VCardConfig.VCARD_TYPE_V30_GENERIC,
            VCardConfig.DEFAULT_EXPORT_CHARSET);
    for (String key : mapContactsData.keySet()) {
        final List<ContentValues> contentValuesList = mapContactsData.get(key);
        boolean hasPhone = false;
        contactMimeTypeMap.clear();
        builder.clear();

        // Group by type so we can call builder.append<type> below
        for (ContentValues cv : contentValuesList) {
            final String mimeType = cv.getAsString(ContactsContract.Data.MIMETYPE);
            if (Phone.CONTENT_ITEM_TYPE.equals(mimeType)) {
                hasPhone = true;
            }
            List<ContentValues> group = contactMimeTypeMap.get(mimeType);
            if (group == null) {
                group = new ArrayList<>();
                contactMimeTypeMap.put(mimeType, group);
            }
            group.add(cv);
        }

        // Digits users are identified by phone, so ignore contacts w/o a phone
        if (!hasPhone) {
            continue;
        }

        builder.appendNameProperties(contactMimeTypeMap.get(StructuredName.CONTENT_ITEM_TYPE))
                .appendPhones(contactMimeTypeMap.get(Phone.CONTENT_ITEM_TYPE), null);

        final String vcard = builder.toString();
        vCards.add(vcard);
    }

    return vCards;
}
项目:mc_backup    文件:ContactService.java   
private void getNameValues(final JSONArray displayNames, final JSONArray givenNames,
                           final JSONArray familyNames, final JSONArray prefixes,
                           final JSONArray suffixes, List<ContentValues> newContactValues) throws JSONException {
    int maxLen = max((displayNames != null ? displayNames.length() : 0),
                     (givenNames != null ? givenNames.length() : 0),
                     (familyNames != null ? familyNames.length() : 0),
                     (prefixes != null ? prefixes.length() : 0),
                     (suffixes != null ? suffixes.length() : 0));

    for (int i = 0; i < maxLen; i++) {
        ContentValues contentValues = new ContentValues();
        contentValues.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);

        final String displayName = (displayNames != null ? displayNames.optString(i, null) : null);
        final String givenName = (givenNames != null ? givenNames.optString(i, null) : null);
        final String familyName = (familyNames != null ? familyNames.optString(i, null) : null);
        final String prefix = (prefixes != null ? prefixes.optString(i, null) : null);
        final String suffix = (suffixes != null ? suffixes.optString(i, null) : null);

        if (displayName != null) {
            contentValues.put(StructuredName.DISPLAY_NAME, displayName);
        }
        if (givenName != null) {
            contentValues.put(StructuredName.GIVEN_NAME, givenName);
        }
        if (familyName != null) {
            contentValues.put(StructuredName.FAMILY_NAME, familyName);
        }
        if (prefix != null) {
            contentValues.put(StructuredName.PREFIX, prefix);
        }
        if (suffix != null) {
            contentValues.put(StructuredName.SUFFIX, suffix);
        }

        newContactValues.add(contentValues);
    }
}
项目:mobilecloud-15    文件:InsertContactsCommand.java   
/**
 * Factory method that creates a ContentValues containing the data
 * associated with a RawContact.
 */
private ContentValues makeRawContactData(String displayName,
                                         Uri rawContactUri) {
    ContentValues values = new ContentValues();
    values.put(Data.RAW_CONTACT_ID,
               ContentUris.parseId(rawContactUri));
    values.put(Data.MIMETYPE,
               StructuredName.CONTENT_ITEM_TYPE);
    values.put(StructuredName.DISPLAY_NAME,
               displayName);
    return values;
}
项目:android-authenticator    文件:ContactOperations.java   
/**
 * Updates contact's name. The caller can either provide first-name
 * and last-name fields or a full-name field.
 *
 * @param uri               Uri for the existing raw contact to be updated
 * @param existingFirstName the first name stored in provider
 * @param existingLastName  the last name stored in provider
 * @param existingFullName  the full name stored in provider
 * @param firstName         the new first name to store
 * @param lastName          the new last name to store
 * @param fullName          the new full name to store
 * @return instance of ContactOperations
 */
public ContactOperations updateName(Uri uri,
                                    String existingFirstName,
                                    String existingLastName,
                                    String existingFullName,
                                    String firstName,
                                    String lastName,
                                    String fullName) {

    mValues.clear();
    if (TextUtils.isEmpty(fullName)) {
        if (!TextUtils.equals(existingFirstName, firstName)) {
            mValues.put(StructuredName.GIVEN_NAME, firstName);
        }
        if (!TextUtils.equals(existingLastName, lastName)) {
            mValues.put(StructuredName.FAMILY_NAME, lastName);
        }
    } else {
        if (!TextUtils.equals(existingFullName, fullName)) {
            mValues.put(StructuredName.DISPLAY_NAME, fullName);
        }
    }
    if (mValues.size() > 0) {
        addUpdateOp(uri);
    }
    return this;
}
项目:CucumberSync    文件:LocalAddressBook.java   
protected Builder buildStructuredName(Builder builder, Contact contact) {
    return builder
        .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
        .withValue(StructuredName.PREFIX, contact.getPrefix())
        .withValue(StructuredName.DISPLAY_NAME, contact.getDisplayName())
        .withValue(StructuredName.GIVEN_NAME, contact.getGivenName())
        .withValue(StructuredName.MIDDLE_NAME, contact.getMiddleName())
        .withValue(StructuredName.FAMILY_NAME, contact.getFamilyName())
        .withValue(StructuredName.SUFFIX, contact.getSuffix())
        .withValue(StructuredName.PHONETIC_GIVEN_NAME, contact.getPhoneticGivenName())
        .withValue(StructuredName.PHONETIC_MIDDLE_NAME, contact.getPhoneticMiddleName())
        .withValue(StructuredName.PHONETIC_FAMILY_NAME, contact.getPhoneticFamilyName());
}
项目:SafeSlinger-Android    文件:BaseActivity.java   
/**
 * Retrieve a user's application key, based on the key name.
 */
protected String getContactName(String contactLookupKey) {
    String name = "";
    if (!SafeSlinger.doesUserHavePermission(Manifest.permission.READ_CONTACTS)) {
        return null;
    }
    if (TextUtils.isEmpty(contactLookupKey)) {
        return null;
    }

    String where = Data.MIMETYPE + " = ?";
    String[] whereParameters = new String[] {
        StructuredName.CONTENT_ITEM_TYPE
    };

    Uri dataUri = getDataUri(contactLookupKey);
    if (dataUri != null) {
        Cursor c = getContentResolver().query(dataUri, null, where, whereParameters, null);
        if (c != null) {
            try {
                if (c.moveToFirst()) {
                    do {
                        String newname = c.getString(c
                                .getColumnIndexOrThrow(StructuredName.DISPLAY_NAME));
                        boolean super_primary = (c.getInt(c
                                .getColumnIndexOrThrow(StructuredName.IS_SUPER_PRIMARY)) != 0);
                        if ((TextUtils.isEmpty(name) || super_primary)) {
                            name = newname;
                        }
                    } while (c.moveToNext());
                }
            } finally {
                c.close();
            }
        }
    }
    return TextUtils.isEmpty(name) ? null : name;
}
项目:SafeSlinger-Android    文件:BaseActivity.java   
protected ArrayList<UseContactItem> getUseContactItemsByName(String name) {
    ArrayList<UseContactItem> contacts = new ArrayList<UseContactItem>();
    if (!SafeSlinger.doesUserHavePermission(Manifest.permission.READ_CONTACTS)) {
        return contacts;
    }
    if (TextUtils.isEmpty(name)) {
        return contacts;
    }

    // find aggregated contact
    String[] whereParameters = new String[] {
            StructuredName.DISPLAY_NAME, StructuredName.LOOKUP_KEY
    };
    String where = StructuredName.DISPLAY_NAME + " = "
            + DatabaseUtils.sqlEscapeString("" + name);
    Cursor c = getContentResolver().query(Data.CONTENT_URI, whereParameters, where, null, null);
    if (c != null) {
        try {
            if (c.moveToFirst()) {
                do {
                    String tempLookup = c.getString(c
                            .getColumnIndexOrThrow(StructuredName.LOOKUP_KEY));
                    String tempName = c.getString(c
                            .getColumnIndexOrThrow(StructuredName.DISPLAY_NAME));
                    byte[] tempPhoto = getContactPhoto(tempLookup);
                    if (!TextUtils.isEmpty(tempLookup)) {
                        contacts.add(new UseContactItem(tempName, tempPhoto, tempLookup,
                                UCType.CONTACT));
                    }
                } while (c.moveToNext());
            }
        } finally {
            c.close();
        }
    }

    return contacts;
}
项目:SafeSlinger-Android    文件:ContactAccessorApi5.java   
@Override
public String[] getProjName() {
    return new String[] {
            StructuredName.MIMETYPE, StructuredName.DISPLAY_NAME, StructuredName.FAMILY_NAME,
            StructuredName.GIVEN_NAME, StructuredName.MIDDLE_NAME, StructuredName.PREFIX,
            StructuredName.SUFFIX, StructuredName.IS_PRIMARY, StructuredName.IS_SUPER_PRIMARY
    };
}
项目:SafeSlinger-Android    文件:ContactAccessorApi5.java   
private ContentValues valuesName(ContactStruct contact) {
    ContentValues val = new ContentValues();
    val.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
    if (contact.name != null) {
        val.put(StructuredName.FAMILY_NAME, contact.name.getFamily());
        val.put(StructuredName.GIVEN_NAME, contact.name.getGiven());
        val.put(StructuredName.MIDDLE_NAME, contact.name.getMiddle());
        val.put(StructuredName.PREFIX, contact.name.getPrefix());
        val.put(StructuredName.SUFFIX, contact.name.getSuffix());
        val.put(StructuredName.DISPLAY_NAME, contact.name.toString());
    }
    return val;
}
项目:JCB    文件:ContactUtils.java   
public void addName(String displayname) {

        ops.add(ContentProviderOperation
                .newInsert(android.provider.ContactsContract.Data.CONTENT_URI)
                .withValueBackReference(Data.RAW_CONTACT_ID,
                        rawContactInsertIndex)
                .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
                .withValue(StructuredName.DISPLAY_NAME, displayname).build());
    }
项目:cordova-images-browser    文件:ImagesBrowser.java   
public void handleName(JSONObject contact, Cursor name) throws JSONException{
    contact.put("fn", name.getString(name.getColumnIndex(StructuredName.DISPLAY_NAME)));
    String sep = ";";
    contact.put("n",
            getString(name, StructuredName.FAMILY_NAME, "") + sep +
            getString(name, StructuredName.GIVEN_NAME, "") + sep +
            getString(name, StructuredName.MIDDLE_NAME, "") + sep +
            getString(name, StructuredName.PREFIX, "") + sep +
            getString(name, StructuredName.SUFFIX, ""));
}
项目:openxface-android    文件:XContactAccessorAPILevel5Impl.java   
@Override
public void cursorToHashMap(Map<String, Object> contactsMap, Cursor c) {
    // 获取当前行的 mimetype用于比较
    String mimetype = c.getString(c
            .getColumnIndex(ContactsContract.Data.MIMETYPE));

    if (StructuredName.CONTENT_ITEM_TYPE.equals(mimetype)) {
        contactsMap.put(LOGIC_FIELD_DISPLAYNAME,
                c.getString(c.getColumnIndex(StructuredName.DISPLAY_NAME)));
        nameQuery(contactsMap, c);
    } else if (Event.CONTENT_ITEM_TYPE.equals(mimetype)) {
        if (Event.TYPE_BIRTHDAY == c.getInt(c.getColumnIndex(Event.TYPE))) {
            contactsMap.put(LOGIC_FIELD_BIRTHDAY,
                    c.getString(c.getColumnIndex(Event.START_DATE)));
        }
    } else if (Nickname.CONTENT_ITEM_TYPE.equals(mimetype)) {
        contactsMap.put(LOGIC_FIELD_NICKNAME,
                c.getString(c.getColumnIndex(Nickname.NAME)));
    } else if (Note.CONTENT_ITEM_TYPE.equals(mimetype)) {
        contactsMap.put(LOGIC_FIELD_NOTE,
                c.getString(c.getColumnIndex(Note.NOTE)));
    } else {
        String logicField = LOGIC_FIELD_TO_CONTENT_TYPE_MAP
                .getKeyByValue(mimetype);
        if (LOGIC_CONTACT_MULTIPLE_VALUE_FIELDS.contains(logicField)) {
            multipleValueFieldQuery(contactsMap, c, logicField);
        }
    }
}
项目:amap    文件:AddressServiceImpl.java   
public static boolean queryFromContact(ContentResolver mResolver, String name, String number)
{
    ContentValues values = new ContentValues();
    // 首先向RawContacts.CONTENT_URI执行一个空值插入,目的是获取系统返回的rawContactId
    String where = Data.MIMETYPE + "=? and " + StructuredName.GIVEN_NAME + "=?";
    Cursor mCursor =
        mResolver.query(ContactsContract.Data.CONTENT_URI, null, where, new String[] {
            StructuredName.CONTENT_ITEM_TYPE, name}, null);
    System.out.println("--------------------phone--------------------1");
    if (mCursor != null)
    {
        while (mCursor.moveToNext())
        {
            String rowId = mCursor.getString(mCursor.getColumnIndex(Data.RAW_CONTACT_ID));

            String phoneWhere = Data.MIMETYPE + "=? and " + Phone.NUMBER + "=?";
            Cursor mPhoneCur =
                mResolver.query(ContactsContract.Data.CONTENT_URI, null, phoneWhere, new String[] {
                    Phone.CONTENT_ITEM_TYPE, number}, null);
            if (mPhoneCur != null)
            {
                while (mPhoneCur.moveToNext())
                {
                    String phoneRowId = mPhoneCur.getString(mPhoneCur.getColumnIndex(Data.RAW_CONTACT_ID));
                    if (rowId.equals(phoneRowId))
                    {
                        mPhoneCur.close();
                        mCursor.close();
                        return true;
                    }
                }
            }
            if (mPhoneCur != null)
            {
                mPhoneCur.close();
            }
        }
    }
    if (mCursor != null)
    {
        mCursor.close();
    }
    return false;
}
项目:phoneContact    文件:ContactDAO.java   
/**
 * �����ϵ��
 * 
 * @param contact
 *            ��ϵ��ʵ�����
 * @param groupId
 *            ���
 */
public boolean addContact1(SortEntry contact, int groupId) {
    if (TextUtils.isEmpty(contact.mName)) {
        Toast.makeText(context, "����������", Toast.LENGTH_LONG).show();
        return false;
    }
    ContentValues values = new ContentValues();
    Uri rawContactUri = context.getContentResolver().insert(
            RawContacts.CONTENT_URI, values);
    int rawContactId = (int) ContentUris.parseId(rawContactUri);
    // ��data���������
    if (contact.mName != "") {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
        values.put(StructuredName.GIVEN_NAME, contact.mName);
        context.getContentResolver().insert(
                ContactsContract.Data.CONTENT_URI,values);
    }

    // ��data�в���绰����
    if (contact.mNum != "") {
        values.clear();
        String[] numbers = Tools.getPhoneNumber(contact.mNum);
        for (int i = 0; i < numbers.length; i++) {
            values.put(Data.RAW_CONTACT_ID, rawContactId);
            values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
            values.put(Phone.NUMBER, numbers[i]);
            values.put(Phone.TYPE, Phone.TYPE_MOBILE);
            context.getContentResolver().insert(
                    ContactsContract.Data.CONTENT_URI, values);
        }
    }

    // ���ͷ��
    if (contact.contactPhoto != null) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
        values.put(Photo.PHOTO,
                ImageConvert.bitmapToByte(contact.contactPhoto));
        context.getContentResolver().insert(
                ContactsContract.Data.CONTENT_URI, values);
    }
    // // ��ӵ�ַ
    // if (contact.getAddress() != "") {
    // values.clear();
    // values.put(Data.RAW_CONTACT_ID, rawContactId);
    // values.put(Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE);
    // values.put(SipAddress.CONTENT_ITEM_TYPE, contact.getAddress());
    // context.getContentResolver().insert(
    // ContactsContract.Data.CONTENT_URI, values);
    // }
    // // �������
    // if (contact.getEmail() != "") {
    // values.clear();
    // values.put(Data.RAW_CONTACT_ID, rawContactId);
    // values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
    // values.put(Email.CONTENT_ITEM_TYPE, contact.getEmail());
    // context.getContentResolver().insert(
    // ContactsContract.Data.CONTENT_URI, values);
    // }
    if (groupId != 0) {
        new GroupDAO(context).addMemberToGroup(rawContactId, groupId);
    }
    return true;
}
项目:phoneContact    文件:ContactDAO.java   
/**
     * ������ϵ��
     * 
     * @param rawContactId
     *            ��ϵ��id
     */
    public void updataCotact(long rawContactId, SortEntry contact,
            int old_groupID) {
        ContentValues values = new ContentValues();
        // ��������
        values.put(StructuredName.GIVEN_NAME, contact.mName);
        context.getContentResolver().update(
                ContactsContract.Data.CONTENT_URI,
                values,
                Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + "=?",
                new String[] { String.valueOf(rawContactId),
                        StructuredName.CONTENT_ITEM_TYPE });

        // ���µ绰
        if (contact.mNum != "") {
            values.clear();
            String[] numbers = Tools.getPhoneNumber(contact.mNum);
            for (int i = 0; i < numbers.length; i++) {
                values.put(Data.RAW_CONTACT_ID, rawContactId);
                values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
                values.put(Phone.NUMBER, numbers[i]);
                values.put(Phone.TYPE, Phone.TYPE_MOBILE);
//              context.getContentResolver().insert(
//                      ContactsContract.Data.CONTENT_URI, values);
                context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
                        values,
                        Data.RAW_CONTACT_ID+"=? and "+Data.MIMETYPE+"=?",
                        new String[]{String.valueOf(rawContactId),Phone.CONTENT_ITEM_TYPE});
            }
        }
        // ����ͷ��
        values.clear();
        if (contact.contactPhoto != null) {
            values.put(ContactsContract.CommonDataKinds.Photo.PHOTO,
                    ImageConvert.bitmapToByte(contact.contactPhoto));
            context.getContentResolver().update(
                    ContactsContract.Data.CONTENT_URI,
                    values,
                    Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + " =?",
                    new String[] { String.valueOf(rawContactId),
                            Photo.CONTENT_ITEM_TYPE });
        }
        // ����Ⱥ��
        if (contact.groupId != 0) {
            values.clear();
            values.put(
                    ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,
                    contact.groupId);
            context.getContentResolver().update(
                    ContactsContract.Data.CONTENT_URI,
                    values,
                    Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + " =?",
                    new String[] { String.valueOf(rawContactId),
                            GroupMembership.CONTENT_ITEM_TYPE });
        } else {
            new GroupDAO(context).deleteMemberFromGroup(
                    Integer.parseInt(contact.mID), old_groupID);
        }
    }
项目:phoneContact    文件:ContactDAO.java   
/**
 * ������ϵ�� ��ʼû��ͷ�����ϵ��
 * 
 * @param rawContactId
 *            ��ϵ��id
 */
public void updataCotactNoPhoto(long rawContactId, SortEntry contact,
        int old_groupID) {
    ContentValues values = new ContentValues();
    // ��������
    values.put(StructuredName.GIVEN_NAME, contact.mName);
    context.getContentResolver().update(
            ContactsContract.Data.CONTENT_URI,
            values,
            Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + "=?",
            new String[] { String.valueOf(rawContactId),
                    StructuredName.CONTENT_ITEM_TYPE });

    // ���µ绰
    if (contact.mNum != "") {
        values.clear();
        String[] numbers = Tools.getPhoneNumber(contact.mNum);
        for (int i = 0; i < numbers.length; i++) {
            values.put(Data.RAW_CONTACT_ID, rawContactId);
            values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
            values.put(Phone.NUMBER, numbers[i]);
            values.put(Phone.TYPE, Phone.TYPE_MOBILE);
            context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
                    values,
                    Data.RAW_CONTACT_ID+"=? and "+Data.MIMETYPE+"=?",
                    new String[]{String.valueOf(rawContactId),Phone.CONTENT_ITEM_TYPE});
        }
    }
    // ���ͷ��
    if (contact.contactPhoto != null) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
        values.put(Photo.PHOTO,
                ImageConvert.bitmapToByte(contact.contactPhoto));
        context.getContentResolver().insert(
                ContactsContract.Data.CONTENT_URI, values);
    }
    // ����Ⱥ��
    if (contact.groupId != 0) {
        values.clear();
        values.put(
                ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,
                contact.groupId);
        context.getContentResolver().update(
                ContactsContract.Data.CONTENT_URI,
                values,
                Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + " =?",
                new String[] { String.valueOf(rawContactId),
                        GroupMembership.CONTENT_ITEM_TYPE });
    } else {
        new GroupDAO(context).deleteMemberFromGroup(
                Integer.parseInt(contact.mID), old_groupID);
    }
}
项目:phoneContact    文件:ContactDAO.java   
/**
 * ������ϵ�� ����ǰû��Ⱥ�����ϵ��
 * 
 * @param rawContactId
 *            ��ϵ��id
 */
public void updataCotactNoGroup(long rawContactId, SortEntry contact) {
    ContentValues values = new ContentValues();
    // ��������
    values.put(StructuredName.GIVEN_NAME, contact.mName);
    context.getContentResolver().update(
            ContactsContract.Data.CONTENT_URI,
            values,
            Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + "=?",
            new String[] { String.valueOf(rawContactId),
                    StructuredName.CONTENT_ITEM_TYPE });

    // ���µ绰
    if (contact.mNum != "") {
        values.clear();
        String[] numbers = Tools.getPhoneNumber(contact.mNum);
        for (int i = 0; i < numbers.length; i++) {
            values.put(Data.RAW_CONTACT_ID, rawContactId);
            values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
            values.put(Phone.NUMBER, numbers[i]);
            values.put(Phone.TYPE, Phone.TYPE_MOBILE);
            context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
                    values,
                    Data.RAW_CONTACT_ID+"=? and "+Data.MIMETYPE+"=?",
                    new String[]{String.valueOf(rawContactId),Phone.CONTENT_ITEM_TYPE});
        }
    }
    // ����ͷ��
    if (contact.contactPhoto != null) {
        values.clear();
        values.put(ContactsContract.CommonDataKinds.Photo.PHOTO,
                ImageConvert.bitmapToByte(contact.contactPhoto));
        context.getContentResolver().update(
                ContactsContract.Data.CONTENT_URI,
                values,
                Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + " =?",
                new String[] { String.valueOf(rawContactId),
                        Photo.CONTENT_ITEM_TYPE });
    }
    // ��ӵ�Ⱥ��
    if (contact.groupId != 0) {
        new GroupDAO(context).addMemberToGroup(
                Integer.parseInt(contact.mID), contact.groupId);
    }
}
项目:phoneContact    文件:ContactDAO.java   
/**
 * ������ϵ�� ����ǰû��ͷ��Ⱥ�����ϵ��
 * 
 * @param rawContactId
 *            ��ϵ��id
 */
public void updataCotactNoG_Photo(long rawContactId, SortEntry contact) {
    ContentValues values = new ContentValues();
    // ��������
    values.put(StructuredName.GIVEN_NAME, contact.mName);
    context.getContentResolver().update(
            ContactsContract.Data.CONTENT_URI,
            values,
            Data.RAW_CONTACT_ID + "=? and " + Data.MIMETYPE + "=?",
            new String[] { String.valueOf(rawContactId),
                    StructuredName.CONTENT_ITEM_TYPE });

    // ���µ绰
    if (contact.mNum != "") {
        values.clear();
        String[] numbers = Tools.getPhoneNumber(contact.mNum);
        for (int i = 0; i < numbers.length; i++) {
            values.put(Data.RAW_CONTACT_ID, rawContactId);
            values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
            values.put(Phone.NUMBER, numbers[i]);
            values.put(Phone.TYPE, Phone.TYPE_MOBILE);
            context.getContentResolver().update(ContactsContract.Data.CONTENT_URI,
                    values,
                    Data.RAW_CONTACT_ID+"=? and "+Data.MIMETYPE+"=?",
                    new String[]{String.valueOf(rawContactId),Phone.CONTENT_ITEM_TYPE});
        }
    }
    // ���ͷ��
    if (contact.contactPhoto != null) {
        values.clear();
        values.put(Data.RAW_CONTACT_ID, rawContactId);
        values.put(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
        values.put(Photo.PHOTO,
                ImageConvert.bitmapToByte(contact.contactPhoto));
        context.getContentResolver().insert(
                ContactsContract.Data.CONTENT_URI, values);
    }
    // ��ӵ�Ⱥ��
    if (contact.groupId != 0) {
        new GroupDAO(context).addMemberToGroup(
                Integer.parseInt(contact.mID), contact.groupId);
    }
}
项目:digits-android    文件:VCardBuilder.java   
private ContentValues getPrimaryContentValueWithStructuredName(
        final List<ContentValues> contentValuesList) {
    ContentValues primaryContentValues = null;
    ContentValues subprimaryContentValues = null;
    for (ContentValues contentValues : contentValuesList) {
        if (contentValues == null){
            continue;
        }
        Integer isSuperPrimary = contentValues.getAsInteger(StructuredName.IS_SUPER_PRIMARY);
        if (isSuperPrimary != null && isSuperPrimary > 0) {
            // We choose "super primary" ContentValues.
            primaryContentValues = contentValues;
            break;
        } else if (primaryContentValues == null) {
            // We choose the first "primary" ContentValues
            // if "super primary" ContentValues does not exist.
            final Integer isPrimary = contentValues.getAsInteger(StructuredName.IS_PRIMARY);
            if (isPrimary != null && isPrimary > 0 &&
                    containsNonEmptyName(contentValues)) {
                primaryContentValues = contentValues;
                // Do not break, since there may be ContentValues with "super primary"
                // afterword.
            } else if (subprimaryContentValues == null &&
                    containsNonEmptyName(contentValues)) {
                subprimaryContentValues = contentValues;
            }
        }
    }

    if (primaryContentValues == null) {
        if (subprimaryContentValues != null) {
            // We choose the first ContentValues if any "primary" ContentValues does not exist.
            primaryContentValues = subprimaryContentValues;
        } else {
            // There's no appropriate ContentValue with StructuredName.
            primaryContentValues = new ContentValues();
        }
    }

    return primaryContentValues;
}
项目:digits-android    文件:ContactsHelper.java   
public List<String> createContactList(Cursor cursor) {
    if (cursor == null || cursor.getCount() == 0) {
        return Collections.<String>emptyList();
    }

    final int mimeTypeColumnIndex = cursor.getColumnIndex(ContactsContract.Data.MIMETYPE);
    final int lookupKeyColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts
            .LOOKUP_KEY);
    final Map<String, List<ContentValues>> mapContactsData = new HashMap<>();
    while (cursor.moveToNext()) {
        final String mimeType = cursor.getString(mimeTypeColumnIndex);
        final ContentValues cv = new ContentValues();
        cv.put(ContactsContract.Data.MIMETYPE, mimeType);
        switch (mimeType) {
            case Phone.CONTENT_ITEM_TYPE:
                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, Phone.TYPE);
                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Phone.LABEL);
                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, Phone.IS_PRIMARY);
                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Phone.NUMBER);
                break;
            case StructuredName.CONTENT_ITEM_TYPE:
                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
                        StructuredName.DISPLAY_NAME);
                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
                        StructuredName.GIVEN_NAME);
                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
                        StructuredName.FAMILY_NAME);
                break;
            default:
                continue;
        }
        // Aggregate contacts based on their lookup key.
        final String lookupKey = cursor.getString(lookupKeyColumnIndex);
        List<ContentValues> contactDetails = mapContactsData.get(lookupKey);
        if (contactDetails == null) {
            contactDetails = new ArrayList<>();
            mapContactsData.put(lookupKey, contactDetails);
        }
        contactDetails.add(cv);
    }

    return processContactsMap(mapContactsData);
}
项目:contact    文件:PeopleDao.java   
private static void updateContacts(ContentResolver contentResolver,
        People people, String raw_contact_id) {
    contentResolver.delete(ContactsContract.Data.CONTENT_URI, ContactsContract.Data.RAW_CONTACT_ID + "=? AND "
            + ContactsContract.Data.MIMETYPE + "=?", new String[] { raw_contact_id, Phone.CONTENT_ITEM_TYPE });
    ArrayList<ContentProviderOperation> cpo = new ArrayList<ContentProviderOperation>();
    cpo.add(ContentProviderOperation
            .newUpdate(ContactsContract.Data.CONTENT_URI)
            .withSelection(
                    ContactsContract.Data.RAW_CONTACT_ID + "=? AND "
                            + ContactsContract.Data.MIMETYPE + "=?",
                    new String[] { raw_contact_id,
                            StructuredName.CONTENT_ITEM_TYPE })
            .withValue(StructuredName.DISPLAY_NAME, people.getpName())
            .build());

    List<String> listPhone = people.getpPhoneList();
    Log.d("编辑,电话号码", listPhone.toString());
    for (int i = 0; i < listPhone.size(); i++) {
        Log.d("编辑,电话号码", listPhone.get(i));
        cpo.add(ContentProviderOperation
                .newInsert(ContactsContract.Data.CONTENT_URI)
                .withValue(ContactsContract.Data.RAW_CONTACT_ID,
                        raw_contact_id)
                .withValue(ContactsContract.Data.MIMETYPE,
                        Phone.CONTENT_ITEM_TYPE)
                .withValue(Phone.TYPE, String.valueOf(2))
                .withValue(Phone.NUMBER, listPhone.get(i)).build());

    }
    cpo.add(ContentProviderOperation
            .newUpdate(ContactsContract.Data.CONTENT_URI)
            .withSelection(
                    ContactsContract.Data.RAW_CONTACT_ID + "=? AND "
                            + ContactsContract.Data.MIMETYPE + "=?",
                    new String[] { raw_contact_id, Email.CONTENT_ITEM_TYPE })
            .withValue(Email.DATA, people.getpEmail()).build());
    cpo.add(ContentProviderOperation
            .newUpdate(ContactsContract.Data.CONTENT_URI)
            .withSelection(
                    ContactsContract.Data.RAW_CONTACT_ID + "=? AND "
                            + ContactsContract.Data.MIMETYPE + "=?",
                    new String[] { raw_contact_id,
                            Organization.CONTENT_ITEM_TYPE })
            .withValue(Organization.DATA1, people.getpCompany())
            .withValue(Organization.DATA4, people.getpPosition()).build());

    try {
        contentResolver.applyBatch(ContactsContract.AUTHORITY, cpo);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:android-authenticator    文件:ContactManager.java   
/**
 * Return a User object with data extracted from a contact stored
 * in the local contacts database.
 * <p>
 * Because a contact is actually stored over several rows in the
 * database, our query will return those multiple rows of information.
 * We then iterate over the rows and build the User structure from
 * what we find.
 *
 * @param context      the Authenticator Activity context
 * @param rawContactId the unique ID for the local contact
 * @return a User object containing info on that contact
 */
public static XWikiUser getXWikiUser(Context context, long rawContactId) {
    String firstName = null;
    String lastName = null;
    String fullName = null;
    String cellPhone = null;
    String homePhone = null;
    String workPhone = null;
    String email = null;
    String serverId = null;

    final ContentResolver resolver = context.getContentResolver();
    final Cursor c =
            resolver.query(DataQuery.CONTENT_URI, DataQuery.PROJECTION, DataQuery.SELECTION,
                    new String[]{String.valueOf(rawContactId)}, null);
    try {
        while (c.moveToNext()) {
            final long id = c.getLong(DataQuery.COLUMN_ID);
            final String mimeType = c.getString(DataQuery.COLUMN_MIMETYPE);
            final String tempServerId = c.getString(DataQuery.COLUMN_SERVER_ID);
            if (tempServerId != null) {
                serverId = tempServerId;
            }
            final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, id);
            if (mimeType.equals(StructuredName.CONTENT_ITEM_TYPE)) {
                lastName = c.getString(DataQuery.COLUMN_FAMILY_NAME);
                firstName = c.getString(DataQuery.COLUMN_GIVEN_NAME);
                //fullName = c.getString(DataQuery.COLUMN_FULL_NAME);
            } else if (mimeType.equals(Phone.CONTENT_ITEM_TYPE)) {
                final int type = c.getInt(DataQuery.COLUMN_PHONE_TYPE);
                if (type == Phone.TYPE_MOBILE) {
                    cellPhone = c.getString(DataQuery.COLUMN_PHONE_NUMBER);
                } else if (type == Phone.TYPE_HOME) {
                    homePhone = c.getString(DataQuery.COLUMN_PHONE_NUMBER);
                } else if (type == Phone.TYPE_WORK) {
                    workPhone = c.getString(DataQuery.COLUMN_PHONE_NUMBER);
                }
            } else if (mimeType.equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {
                email = c.getString(DataQuery.COLUMN_EMAIL_ADDRESS);
            }
        } // while
    } finally {
        c.close();
    }

    // Now that we've extracted all the information we care about,
    // create the actual User object.
    XWikiUser wikiUser = new XWikiUser(serverId, null, firstName, lastName, email, cellPhone, null,
            rawContactId, null, null, null, null, null, null);

    return wikiUser;
}
项目:ntsync-android    文件:ContactOperations.java   
/**
 * Adds a contact name. We can take either a full name ("Bob Smith") or
 * separated first-name and last-name ("Bob" and "Smith").
 * 
 * @param fullName
 *            The full name of the contact - typically from an edit form Can
 *            be null if firstName/lastName are specified.
 * @param firstName
 *            The first name of the contact - can be null if fullName is
 *            specified.
 * @param lastName
 *            The last name of the contact - can be null if fullName is
 *            specified.
 * @return instance of ContactOperations
 */
public ContactOperations addName(String fullName, String firstName,
        String lastName, String middleName, String suffixName,
        String prefixName, String phoneticFirst, String phonecticMiddle,
        String phonecticLast) {
    mValues.clear();

    mValues.put(StructuredName.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
    if (!TextUtils.isEmpty(fullName)) {
        mValues.put(StructuredName.DISPLAY_NAME, fullName);
    }
    if (!TextUtils.isEmpty(firstName)) {
        mValues.put(StructuredName.GIVEN_NAME, firstName);
    }
    if (!TextUtils.isEmpty(lastName)) {
        mValues.put(StructuredName.FAMILY_NAME, lastName);
    }
    if (!TextUtils.isEmpty(middleName)) {
        mValues.put(StructuredName.MIDDLE_NAME, middleName);
    }
    if (!TextUtils.isEmpty(suffixName)) {
        mValues.put(StructuredName.SUFFIX, suffixName);
    }
    if (!TextUtils.isEmpty(prefixName)) {
        mValues.put(StructuredName.PREFIX, prefixName);
    }
    if (!TextUtils.isEmpty(phonecticLast)) {
        mValues.put(StructuredName.PHONETIC_FAMILY_NAME, phonecticLast);
    }
    if (!TextUtils.isEmpty(phoneticFirst)) {
        mValues.put(StructuredName.PHONETIC_GIVEN_NAME, phoneticFirst);
    }
    if (!TextUtils.isEmpty(phonecticMiddle)) {
        mValues.put(StructuredName.PHONETIC_MIDDLE_NAME, phonecticMiddle);
    }

    if (mValues.size() > 1) {
        addInsertOp();
    }
    return this;
}