android.provider.ContactsContract.CommonDataKinds.StructuredPostal Java Examples
The following examples show how to use
android.provider.ContactsContract.CommonDataKinds.StructuredPostal.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PostalAddress.java From react-native-paged-contacts with MIT License | 5 votes |
private void fillFromCursor() { Integer type = getInt(StructuredPostal.TYPE); label = getTypeString(type, getString(StructuredPostal.LABEL)); formattedAddress = getString(StructuredPostal.FORMATTED_ADDRESS); poBox = getString(StructuredPostal.POBOX); street = getString(StructuredPostal.STREET); neighborhood = getString(StructuredPostal.NEIGHBORHOOD); city = getString(StructuredPostal.CITY); region = getString(StructuredPostal.REGION); postcode = getString(StructuredPostal.POSTCODE); country = getString(StructuredPostal.COUNTRY); }
Example #2
Source File: PostalAddress.java From react-native-paged-contacts with MIT License | 5 votes |
private String getTypeString(Integer type, String label) { if (type == null) { throw new InvalidCursorTypeException(); } switch (type) { case StructuredPostal.TYPE_HOME: return "home"; case StructuredPostal.TYPE_WORK: return "work"; case StructuredPostal.TYPE_OTHER: return "other"; default: return label; } }
Example #3
Source File: PostalAddress.java From react-native-paged-contacts with MIT License | 5 votes |
private int getTypeInt(String label) { int postalAddressType; switch (label) { case "home": postalAddressType = StructuredPostal.TYPE_HOME; break; case "work": postalAddressType = StructuredPostal.TYPE_WORK; break; default: postalAddressType = StructuredPostal.TYPE_OTHER; break; } return postalAddressType; }
Example #4
Source File: PostalAddress.java From react-native-paged-contacts with MIT License | 5 votes |
@Override public void addCreationOp(ArrayList<ContentProviderOperation> ops) { ContentProviderOperation.Builder op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) .withValue(ContactsContract.Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE) .withValue(StructuredPostal.LABEL, getTypeInt(label)) .withValue(StructuredPostal.STREET, street) .withValue(StructuredPostal.CITY, city) .withValue(StructuredPostal.REGION, region) .withValue(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE, postcode) .withValue(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY, country); ops.add(op.build()); }
Example #5
Source File: ContactUtil.java From haxsync with GNU General Public License v2.0 | 5 votes |
public static void removeContactLocations(Context c, Account account){ ContactsSyncAdapterService.mContentResolver = c.getContentResolver(); HashMap<String, ContactsSyncAdapterService.SyncEntry> localContacts = ContactsSyncAdapterService.getLocalContacts(account); for (ContactsSyncAdapterService.SyncEntry s : localContacts.values()){ ContactsSyncAdapterService.mContentResolver.delete(ContactsContract.Data.CONTENT_URI, ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.Data.RAW_CONTACT_ID + " = " + s.raw_id, null); } }
Example #6
Source File: ContactUtil.java From haxsync with GNU General Public License v2.0 | 5 votes |
public static void updateContactLocation(long rawContactId, String location){ if ((location == null || location.equals(""))){ return; } String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId + "' AND " + ContactsContract.Data.MIMETYPE + " = '" + StructuredPostal.CONTENT_ITEM_TYPE + "'"; String[] projection = {StructuredPostal.FORMATTED_ADDRESS}; Cursor cursor = ContactsSyncAdapterService.mContentResolver.query(ContactsContract.Data.CONTENT_URI, projection, where, null, null); boolean insert = false; if (cursor.getCount() == 0){ insert = true; } else{ cursor.moveToFirst(); String oldloc = cursor.getString(cursor.getColumnIndex(StructuredPostal.FORMATTED_ADDRESS)); if ((oldloc == null) || (!oldloc.equals(location))){ ContactsSyncAdapterService.mContentResolver.delete(ContactsContract.Data.CONTENT_URI, where, null); insert = true; } } cursor.close(); if (insert){ ContentValues contentValues = new ContentValues(); //op.put(ContactsContract.CommonDataKinds.StructuredPostal.CONTACT_ID, ); contentValues.put(ContactsContract.Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE); contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId); contentValues.put(StructuredPostal.FORMATTED_ADDRESS, location); try { ContactsSyncAdapterService.mContentResolver.insert(ContactsContract.Data.CONTENT_URI, contentValues); // mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList); } catch (Exception e) { e.printStackTrace(); //Log.e("ERROR:" , e.^); } } }
Example #7
Source File: SelectContactModule.java From react-native-select-contact with MIT License | 4 votes |
private void addPostalData(WritableArray postalAddresses, Cursor cursor, Activity activity) { // we need to see if the postal address columns exist, if so, add them int formattedAddressColumn = cursor.getColumnIndex(StructuredPostal.FORMATTED_ADDRESS); int streetColumn = cursor.getColumnIndex(StructuredPostal.STREET); int cityColumn = cursor.getColumnIndex(StructuredPostal.CITY); int stateColumn = cursor.getColumnIndex(StructuredPostal.REGION); int postalCodeColumn = cursor.getColumnIndex(StructuredPostal.POSTCODE); int isoCountryCodeColumn = cursor.getColumnIndex(StructuredPostal.COUNTRY); WritableMap addressEntry = Arguments.createMap(); if (formattedAddressColumn != -1) { addressEntry.putString("formattedAddress", cursor.getString(formattedAddressColumn)); } if (streetColumn != -1) { addressEntry.putString("street", cursor.getString(streetColumn)); } if (cityColumn != -1) { addressEntry.putString("city", cursor.getString(cityColumn)); } if (stateColumn != -1) { addressEntry.putString("state", cursor.getString(stateColumn)); } if (postalCodeColumn != -1) { addressEntry.putString("postalCode", cursor.getString(postalCodeColumn)); } if (isoCountryCodeColumn != -1) { addressEntry.putString("isoCountryCode", cursor.getString(isoCountryCodeColumn)); } // add the address type here int addressTypeColumn = cursor.getColumnIndex(StructuredPostal.TYPE); int addressLabelColumn = cursor.getColumnIndex(StructuredPostal.LABEL); if (addressTypeColumn != -1 && addressLabelColumn != -1) { String addressLabel = cursor.getString(addressLabelColumn); int addressType = cursor.getInt(addressTypeColumn); CharSequence typeLabel = StructuredPostal.getTypeLabel(activity.getResources(), addressType, addressLabel); addressEntry.putString("type", String.valueOf(typeLabel)); } postalAddresses.pushMap(addressEntry); }
Example #8
Source File: ContactUtil.java From haxsync with GNU General Public License v2.0 | 4 votes |
public static void updateContactLocation(long rawContactId, String country, String region, String city){ if ((country == null || country.equals("")) && (region == null || region.equals("")) && (city == null || city.equals(""))){ return; } String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId + "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "'"; String[] projection = {ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY, ContactsContract.CommonDataKinds.StructuredPostal.REGION, ContactsContract.CommonDataKinds.StructuredPostal.CITY}; Cursor cursor = ContactsSyncAdapterService.mContentResolver.query(ContactsContract.Data.CONTENT_URI, projection, where, null, null); boolean insert = false; if (cursor.getCount() == 0){ insert = true; } else{ cursor.moveToFirst(); String oldCountry = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY)); String oldRegion = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION)); String oldCity = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.CITY)); if ((oldCountry != null && !oldCountry.equals(country)) || (oldRegion != null && !oldRegion.equals(region)) || (oldCity != null && oldCity.equals(city))){ ContactsSyncAdapterService.mContentResolver.delete(ContactsContract.Data.CONTENT_URI, where, null); insert = true; } } cursor.close(); if (insert){ ContentValues contentValues = new ContentValues(); //op.put(ContactsContract.CommonDataKinds.StructuredPostal.CONTACT_ID, ); contentValues.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE); contentValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId); if (country != null && ! country.equals("")){ contentValues.put(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY, country); } if (region != null && ! region.equals("")){ contentValues.put(ContactsContract.CommonDataKinds.StructuredPostal.REGION, region); } if (city != null && ! city.equals("")){ contentValues.put(ContactsContract.CommonDataKinds.StructuredPostal.CITY, city); } try { ContactsSyncAdapterService.mContentResolver.insert(ContactsContract.Data.CONTENT_URI, contentValues); // mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList); } catch (Exception e) { e.printStackTrace(); //Log.e("ERROR:" , e.^); } } }