97
97
Long raw_id = cur.getLong( cur.getColumnIndex(
98
98
ContactsContract.Data.RAW_CONTACT_ID ) );
99
99
Long id = raw_to_aggregate_ids.get( raw_id );
100
String name = ContactsCache.normaliseName(
101
cur.getString( cur.getColumnIndex(
102
CommonDataKinds.StructuredName.DISPLAY_NAME ) ) );
103
if( name != null && id != null )
102
String name = cur.getString( cur.getColumnIndex(
103
CommonDataKinds.StructuredName.DISPLAY_NAME ) );
105
105
// if this is a name for a contact for whom we have not added a
106
106
// lookup, add a lookup for the contact id by name
107
107
if( unadded_ids.contains( id ) ) {
108
cache.addLookup( new CacheIdentifier(
109
CacheIdentifier.Type.NAME, name ), id );
110
unadded_ids.remove( id );
108
CacheIdentifier cache_identifier = CacheIdentifier.factory(
109
CacheIdentifier.Type.NAME, name );
110
if( cache_identifier != null ) {
111
cache.addLookup( cache_identifier, id );
112
unadded_ids.remove( id );
125
128
Long raw_id = cur.getLong( cur.getColumnIndex(
126
129
ContactsContract.Data.RAW_CONTACT_ID ) );
127
130
Long id = raw_to_aggregate_ids.get( raw_id );
128
String organisation = ContactsCache.normaliseOrganisation(
129
cur.getString( cur.getColumnIndex(
130
CommonDataKinds.Organization.COMPANY ) ) );
131
if( organisation != null && id != null )
133
String organisation = cur.getString( cur.getColumnIndex(
134
CommonDataKinds.Organization.COMPANY ) );
133
136
// if this is an organisation name for a contact for whom we
134
137
// have not added a lookup, add a lookup for the contact id
135
138
// by organisation
136
139
if( unadded_ids.contains( id ) ) {
137
cache.addLookup( new CacheIdentifier(
138
CacheIdentifier.Type.ORGANISATION, organisation ), id );
139
unadded_ids.remove( id );
140
CacheIdentifier cache_identifier = CacheIdentifier.factory(
141
CacheIdentifier.Type.ORGANISATION, organisation );
142
if( cache_identifier != null ) {
143
cache.addLookup( cache_identifier, id );
144
unadded_ids.remove( id );
142
148
// add associated data
157
163
Long raw_id = cur.getLong( cur.getColumnIndex(
158
164
ContactsContract.Data.RAW_CONTACT_ID ) );
159
165
Long id = raw_to_aggregate_ids.get( raw_id );
160
String number = ContactsCache.normalisePhoneNumber(
161
cur.getString( cur.getColumnIndex(
162
CommonDataKinds.Phone.NUMBER ) ) );
163
if( number != null && id != null )
168
String number = cur.getString( cur.getColumnIndex(
169
CommonDataKinds.Phone.NUMBER ) );
165
171
// if this is a number for a contact for whom we have not
166
172
// added a lookup, add a lookup for the contact id by phone
168
174
if( unadded_ids.contains( id ) ) {
169
cache.addLookup( new CacheIdentifier(
170
CacheIdentifier.Type.PRIMARY_NUMBER, number ), id );
171
unadded_ids.remove( id );
175
CacheIdentifier cache_identifier = CacheIdentifier.factory(
176
CacheIdentifier.Type.PRIMARY_NUMBER, number );
177
if( cache_identifier != null ) {
178
cache.addLookup( cache_identifier, id );
179
unadded_ids.remove( id );
174
183
// add associated data
189
198
Long raw_id = cur.getLong( cur.getColumnIndex(
190
199
ContactsContract.Data.RAW_CONTACT_ID ) );
191
200
Long id = raw_to_aggregate_ids.get( raw_id );
192
String email = ContactsCache.normaliseEmailAddress(
193
cur.getString( cur.getColumnIndex(
194
CommonDataKinds.Email.DATA ) ) );
195
if( email != null && id != null )
203
String email = cur.getString( cur.getColumnIndex(
204
CommonDataKinds.Email.DATA ) );
197
206
// if this is an email address for a contact for whom we have
198
207
// not added a lookup, add a lookup for the contact id by email
200
209
if( unadded_ids.contains( id ) ) {
201
cache.addLookup( new CacheIdentifier(
202
CacheIdentifier.Type.PRIMARY_EMAIL, email ), id );
203
unadded_ids.remove( id );
210
CacheIdentifier cache_identifier = CacheIdentifier.factory(
211
CacheIdentifier.Type.PRIMARY_EMAIL, email );
212
if( cache_identifier != null ) {
213
cache.addLookup( cache_identifier, id );
214
unadded_ids.remove( id );
206
218
// add associated data
215
227
CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS,
217
229
ContactsContract.Data.MIMETYPE + " = '" +
218
CommonDataKinds.Organization.CONTENT_ITEM_TYPE + "'",
230
CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "'",
219
231
null, ContactsContract.Data.IS_PRIMARY + " DESC" );
220
232
while( cur.moveToNext() ) {
221
233
Long raw_id = cur.getLong( cur.getColumnIndex(
222
234
ContactsContract.Data.RAW_CONTACT_ID ) );
223
235
Long id = raw_to_aggregate_ids.get( raw_id );
224
String address = ContactsCache.normaliseAddress(
225
cur.getString( cur.getColumnIndex(
226
CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS ) ) );
227
if( address != null && id != null )
238
String address = cur.getString( cur.getColumnIndex(
239
CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS ) );
229
241
// add associated data
230
242
cache.addAssociatedAddress( id, address );
247
cur = _activity.managedQuery( ContactsContract.Data.CONTENT_URI,
249
ContactsContract.Data.RAW_CONTACT_ID,
250
CommonDataKinds.Note.NOTE,
252
ContactsContract.Data.MIMETYPE + " = '" +
253
CommonDataKinds.Note.CONTENT_ITEM_TYPE + "'",
255
while( cur.moveToNext() ) {
256
Long raw_id = cur.getLong( cur.getColumnIndex(
257
ContactsContract.Data.RAW_CONTACT_ID ) );
258
Long id = raw_to_aggregate_ids.get( raw_id );
261
String note = cur.getString( cur.getColumnIndex(
262
CommonDataKinds.Note.NOTE ) );
264
// add associated data
265
cache.addAssociatedNote( id, note );
459
494
_activity.getContentResolver().insert(
460
495
ContactsContract.Data.CONTENT_URI, values );
499
public void addContactNote( Long id, String note )
500
throws ContactCreationException
502
ContentValues values = new ContentValues();
503
values.put( ContactsContract.Data.RAW_CONTACT_ID,
504
obtainRawContact( id ) );
505
values.put( ContactsContract.Data.MIMETYPE,
506
CommonDataKinds.Note.CONTENT_ITEM_TYPE );
508
CommonDataKinds.Note.NOTE, note );
510
_activity.getContentResolver().insert(
511
ContactsContract.Data.CONTENT_URI, values );