/** * getPhoneType converts an Android phone type into a string * @param type * @return phone type as string. */ private String getOrgType(int type) { String stringType; switch (type) { case CommonDataKinds.Organization.TYPE_CUSTOM: stringType = "custom"; break; case CommonDataKinds.Organization.TYPE_WORK: stringType = "work"; break; case CommonDataKinds.Organization.TYPE_OTHER: default: stringType = "other"; break; } return stringType; }
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); }
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); }
public ContactOperations updateOrganization(String data, int type, String label, String title, String department, String jobDescription, boolean isPrimary, boolean isSuperPrimary, Uri uri) { mValues.clear(); mValues.put(Organization.COMPANY, data); mValues.put(Organization.LABEL, label); mValues.put(Organization.TYPE, type); mValues.put(Organization.TITLE, title); mValues.put(Organization.DEPARTMENT, department); mValues.put(Organization.JOB_DESCRIPTION, jobDescription); mValues.put(Organization.IS_PRIMARY, isPrimary ? 1 : 0); mValues.put(Organization.IS_SUPER_PRIMARY, isSuperPrimary ? 1 : 0); addUpdateOp(uri); return this; }
protected void populateOrganization(Contact c) throws RemoteException { @Cleanup Cursor cursor = providerClient.query(dataURI(), new String[] { Organization.COMPANY, Organization.DEPARTMENT, Organization.TITLE, Organization.JOB_DESCRIPTION }, Organization.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?", new String[] { String.valueOf(c.getLocalID()), Organization.CONTENT_ITEM_TYPE }, null); if (cursor != null && cursor.moveToNext()) { String company = cursor.getString(0), department = cursor.getString(1), title = cursor.getString(2), role = cursor.getString(3); if (!StringUtils.isEmpty(company) || !StringUtils.isEmpty(department)) { ezvcard.property.Organization org = new ezvcard.property.Organization(); if (!StringUtils.isEmpty(company)) org.addValue(company); if (!StringUtils.isEmpty(department)) org.addValue(department); c.setOrganization(org); } if (!StringUtils.isEmpty(title)) c.setJobTitle(title); if (!StringUtils.isEmpty(role)) c.setJobDescription(role); } }
protected Builder buildOrganization(Builder builder, Contact contact) { if (contact.getOrganization() == null && contact.getJobTitle() == null && contact.getJobDescription() == null) return null; ezvcard.property.Organization organization = contact.getOrganization(); String company = null, department = null; if (organization != null) { Iterator<String> org = organization.getValues().iterator(); if (org.hasNext()) company = org.next(); if (org.hasNext()) department = org.next(); } return builder .withValue(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE) .withValue(Organization.COMPANY, company) .withValue(Organization.DEPARTMENT, department) .withValue(Organization.TITLE, contact.getJobTitle()) .withValue(Organization.JOB_DESCRIPTION, contact.getJobDescription()); }
@Override public boolean addOrg(ContactStruct contact, Cursor orgs, boolean removeMatches) { boolean ret = false; String title = orgs.getString(orgs.getColumnIndexOrThrow(Organization.TITLE)); String company = orgs.getString(orgs.getColumnIndexOrThrow(Organization.COMPANY)); int type = orgs.getInt(orgs.getColumnIndexOrThrow(Organization.TYPE)); boolean primary = (orgs.getInt(orgs.getColumnIndexOrThrow(Organization.IS_PRIMARY)) != 0); if (!TextUtils.isEmpty(company) && isOrgNew(contact, company, title, removeMatches)) { contact.addOrganization(type, company, title, primary); if (primary) { contact.title = title; contact.company = company; ret = true; } } return ret; }
private boolean updateOrg(OrganizationData org, String rawContactId, Context ctx) { // seek for raw contact + company + title = same String[] proj = new String[] { Organization.RAW_CONTACT_ID, Data.MIMETYPE, Organization.COMPANY, Organization.TITLE }; String where = Organization.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=? AND (" + Organization.COMPANY + "=? OR " + Organization.TITLE + "=?)"; String[] args = new String[] { rawContactId, Organization.CONTENT_ITEM_TYPE, org.companyName, org.positionName }; ContentValues values = valuesOrg(org); values.put(Organization.RAW_CONTACT_ID, rawContactId); return updateDataRow(ctx, proj, where, args, values); }
/** * Add an organization to a list of database actions to be performed * * @param ops the list of database actions * @param org the item to be inserted */ private void insertOrganization(ArrayList<ContentProviderOperation> ops, JSONObject org) { ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE) .withValue(CommonDataKinds.Organization.TYPE, getOrgType(getJsonString(org, "type"))) .withValue(CommonDataKinds.Organization.DEPARTMENT, getJsonString(org, "department")) .withValue(CommonDataKinds.Organization.COMPANY, getJsonString(org, "name")) .withValue(CommonDataKinds.Organization.TITLE, getJsonString(org, "title")) .withValue(CommonDataKinds.Organization.LABEL, getJsonString(org, "type")) .build()); }
/** * Converts a string from the W3C Contact API to it's Android int value. * @param string * @return Android int value */ private int getOrgType(String string) { int type = CommonDataKinds.Organization.TYPE_OTHER; if (string != null) { String lowerType = string.toLowerCase(Locale.getDefault()); if ("work".equals(lowerType)) { return CommonDataKinds.Organization.TYPE_WORK; } else if ("other".equals(lowerType)) { return CommonDataKinds.Organization.TYPE_OTHER; } return CommonDataKinds.Organization.TYPE_CUSTOM; } return type; }
/** * @param contentResolver * @param contactId */ private static List<String> getOrganizationByContactId( ContentResolver contentResolver, String contactId) { List<String> list = new ArrayList<String>(2); Cursor organizationCursor = null; String company = ""; String position = ""; try { organizationCursor = contentResolver .query(ContactsContract.Data.CONTENT_URI, null, ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?", new String[] { contactId, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE }, null); if (organizationCursor.moveToFirst()) { company = organizationCursor .getString(organizationCursor .getColumnIndex(ContactsContract.CommonDataKinds.Organization.DATA1)); position = organizationCursor .getString(organizationCursor .getColumnIndex(ContactsContract.CommonDataKinds.Organization.DATA4)); } list.add(company); list.add(position); } catch (Exception e) { e.printStackTrace(); } finally { if (organizationCursor != null) { organizationCursor.close(); } } return list; }
private void getOrganizationDataAsJSONObject(Cursor cursor, JSONArray organizations, JSONArray jobTitles) throws JSONException { int organizationColumnIndex = cursor.getColumnIndex(Organization.COMPANY); int titleColumnIndex = cursor.getColumnIndex(Organization.TITLE); if (!cursor.isNull(organizationColumnIndex)) { organizations.put(cursor.getString(organizationColumnIndex)); } if (!cursor.isNull(titleColumnIndex)) { jobTitles.put(cursor.getString(titleColumnIndex)); } }
public ContactOperations addOrganization(String data, int type, String label, boolean isPrimary, boolean isSuperPrimary, String title, String department, String jobDescription) { mValues.clear(); if (!TextUtils.isEmpty(data)) { mValues.put(Organization.DATA, data); mValues.put(Organization.TYPE, type); mValues.put(Organization.MIMETYPE, Organization.CONTENT_ITEM_TYPE); if (!TextUtils.isEmpty(label)) { mValues.put(Organization.LABEL, label); } if (!TextUtils.isEmpty(title)) { mValues.put(Organization.TITLE, title); } if (isSuperPrimary) { mValues.put(Email.IS_SUPER_PRIMARY, 1); } if (isPrimary) { mValues.put(Email.IS_PRIMARY, 1); } mValues.put(Organization.DEPARTMENT, department); if (!TextUtils.isEmpty(jobDescription)) { mValues.put(Organization.JOB_DESCRIPTION, jobDescription); } addInsertOp(); } return this; }
public static int getAndroidOrganizationType(OrganizationType type) { switch (type) { case TYPE_CUSTOM: return Organization.TYPE_CUSTOM; case TYPE_OTHER: return Organization.TYPE_OTHER; case TYPE_WORK: return Organization.TYPE_WORK; default: return Organization.TYPE_OTHER; } }
public static OrganizationType getOrganizationType(int androidType) { switch (androidType) { case Organization.TYPE_CUSTOM: return OrganizationType.TYPE_CUSTOM; case Organization.TYPE_OTHER: return OrganizationType.TYPE_OTHER; case Organization.TYPE_WORK: return OrganizationType.TYPE_WORK; default: return OrganizationType.TYPE_OTHER; } }
@Override public String[] getProjOrg() { return new String[] { Organization.MIMETYPE, Organization.TITLE, Organization.COMPANY, Organization.TYPE, Organization.IS_PRIMARY, Organization.LABEL }; }
private ContentValues valuesOrg(OrganizationData org) { ContentValues val = new ContentValues(); val.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE); if (org.positionName != null) val.put(Organization.TITLE, org.positionName); if (org.companyName != null) val.put(Organization.COMPANY, org.companyName); val.put(Organization.IS_PRIMARY, org.isPrimary ? 1 : 0); val.put(Organization.TYPE, org.type); return val; }
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(); } }
@Override public String getQueryOrg() { return Organization.MIMETYPE + " = " + DatabaseUtils.sqlEscapeString("" + Organization.CONTENT_ITEM_TYPE); }
private List<ContentValues> getContactValues(final JSONObject contactProperties) throws JSONException { List<ContentValues> contactValues = new ArrayList<ContentValues>(); // Add the contact to the default group so it is shown in other apps // like the Contacts or People app ContentValues defaultGroupValues = new ContentValues(); defaultGroupValues.put(Data.MIMETYPE, GroupMembership.CONTENT_ITEM_TYPE); defaultGroupValues.put(GroupMembership.GROUP_ROW_ID, mGroupId); contactValues.add(defaultGroupValues); // Create all the values that will be inserted into the new contact getNameValues(contactProperties.optJSONArray("name"), contactProperties.optJSONArray("givenName"), contactProperties.optJSONArray("familyName"), contactProperties.optJSONArray("honorificPrefix"), contactProperties.optJSONArray("honorificSuffix"), contactValues); getGenericValues(MIMETYPE_ADDITIONAL_NAME, CUSTOM_DATA_COLUMN, contactProperties.optJSONArray("additionalName"), contactValues); getNicknamesValues(contactProperties.optJSONArray("nickname"), contactValues); getAddressesValues(contactProperties.optJSONArray("adr"), contactValues); getPhonesValues(contactProperties.optJSONArray("tel"), contactValues); getEmailsValues(contactProperties.optJSONArray("email"), contactValues); //getPhotosValues(contactProperties.optJSONArray("photo"), contactValues); getGenericValues(Organization.CONTENT_ITEM_TYPE, Organization.COMPANY, contactProperties.optJSONArray("org"), contactValues); getGenericValues(Organization.CONTENT_ITEM_TYPE, Organization.TITLE, contactProperties.optJSONArray("jobTitle"), contactValues); getNotesValues(contactProperties.optJSONArray("note"), contactValues); getWebsitesValues(contactProperties.optJSONArray("url"), contactValues); getImsValues(contactProperties.optJSONArray("impp"), contactValues); getCategoriesValues(contactProperties.optJSONArray("category"), contactValues); getEventValues(contactProperties.optString("bday"), Event.TYPE_BIRTHDAY, contactValues); getEventValues(contactProperties.optString("anniversary"), Event.TYPE_ANNIVERSARY, contactValues); getCustomMimetypeValues(contactProperties.optString("sex"), MIMETYPE_SEX, contactValues); getCustomMimetypeValues(contactProperties.optString("genderIdentity"), MIMETYPE_GENDER_IDENTITY, contactValues); getGenericValues(MIMETYPE_KEY, CUSTOM_DATA_COLUMN, contactProperties.optJSONArray("key"), contactValues); return contactValues; }