java类android.provider.ContactsContract.CommonDataKinds.StructuredName的实例源码

Utils.java 文件源码 项目:phoneContact 阅读 24 收藏 0 点赞 0 评论 0
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); 

}
Utils.java 文件源码 项目:phoneContact 阅读 26 收藏 0 点赞 0 评论 0
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});
}
VCardBuilder.java 文件源码 项目:digits-android 阅读 23 收藏 0 点赞 0 评论 0
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));
}
VCardBuilderTest.java 文件源码 项目:digits-android 阅读 39 收藏 0 点赞 0 评论 0
@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));
}
VCardBuilderTest.java 文件源码 项目:digits-android 阅读 29 收藏 0 点赞 0 评论 0
@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);
}
PeopleDao.java 文件源码 项目:contact 阅读 30 收藏 0 点赞 0 评论 0
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;

}
ContactService.java 文件源码 项目:mc_backup 阅读 20 收藏 0 点赞 0 评论 0
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);
}
ContactService.java 文件源码 项目:mc_backup 阅读 29 收藏 0 点赞 0 评论 0
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);
}
InsertContactsCommand.java 文件源码 项目:mobilecloud-15 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 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());
}
InsertContactsCommand.java 文件源码 项目:mobilecloud-15 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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());
}
ContactOperations.java 文件源码 项目:android-authenticator 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
LocalAddressBook.java 文件源码 项目:CucumberSync 阅读 30 收藏 0 点赞 0 评论 0
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));
    }
}
ContactAccessorApi5.java 文件源码 项目:SafeSlinger-Android 阅读 29 收藏 0 点赞 0 评论 0
@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;
}
AddressServiceImpl.java 文件源码 项目:amap 阅读 28 收藏 0 点赞 0 评论 0
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);
    }
}
CommonUtils.java 文件源码 项目:SmartChart 阅读 35 收藏 0 点赞 0 评论 0
/**
 * 往手机通讯录插入联系人
 *
 * @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);
    }
}
Name.java 文件源码 项目:react-native-paged-contacts 阅读 30 收藏 0 点赞 0 评论 0
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);
}
ContactUtils.java 文件源码 项目:BigApp_Discuz_Android 阅读 23 收藏 0 点赞 0 评论 0
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);
}
ContactsHelper.java 文件源码 项目:digits-android 阅读 25 收藏 0 点赞 0 评论 0
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;
}
ContactService.java 文件源码 项目:mc_backup 阅读 31 收藏 0 点赞 0 评论 0
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);
    }
}
InsertContactsCommand.java 文件源码 项目:mobilecloud-15 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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;
}
ContactOperations.java 文件源码 项目:android-authenticator 阅读 31 收藏 0 点赞 0 评论 0
/**
 * 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;
}
LocalAddressBook.java 文件源码 项目:CucumberSync 阅读 28 收藏 0 点赞 0 评论 0
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());
}
BaseActivity.java 文件源码 项目:SafeSlinger-Android 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
BaseActivity.java 文件源码 项目:SafeSlinger-Android 阅读 41 收藏 0 点赞 0 评论 0
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;
}
ContactAccessorApi5.java 文件源码 项目:SafeSlinger-Android 阅读 27 收藏 0 点赞 0 评论 0
@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
    };
}
ContactAccessorApi5.java 文件源码 项目:SafeSlinger-Android 阅读 29 收藏 0 点赞 0 评论 0
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;
}
ContactUtils.java 文件源码 项目:JCB 阅读 40 收藏 0 点赞 0 评论 0
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());
    }
ImagesBrowser.java 文件源码 项目:cordova-images-browser 阅读 26 收藏 0 点赞 0 评论 0
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, ""));
}
XContactAccessorAPILevel5Impl.java 文件源码 项目:openxface-android 阅读 30 收藏 0 点赞 0 评论 0
@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);
        }
    }
}
AddressServiceImpl.java 文件源码 项目:amap 阅读 30 收藏 0 点赞 0 评论 0
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;
}


问题


面经


文章

微信
公众号

扫码关注公众号