76
76
ContactsContract.RawContacts._ID,
77
77
ContactsContract.RawContacts.CONTACT_ID,
78
}, ContactsContract.RawContacts.DELETED + " = 0", null, null );
78
}, ContactsContract.RawContacts.DELETED + " != 0", null, null );
79
79
while( cur.moveToNext() ) {
80
80
Long raw_id = cur.getLong(
81
81
cur.getColumnIndex( ContactsContract.RawContacts._ID ) );
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
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 );
108
cache.addLookup( new CacheIdentifier(
109
CacheIdentifier.Type.NAME, name ), id );
110
unadded_ids.remove( id );
128
125
Long raw_id = cur.getLong( cur.getColumnIndex(
129
126
ContactsContract.Data.RAW_CONTACT_ID ) );
130
127
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 ) );
136
133
// if this is an organisation name for a contact for whom we
137
134
// have not added a lookup, add a lookup for the contact id
138
135
// by organisation
139
136
if( unadded_ids.contains( 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 );
137
cache.addLookup( new CacheIdentifier(
138
CacheIdentifier.Type.ORGANISATION, organisation ), id );
139
unadded_ids.remove( id );
148
142
// add associated data
163
157
Long raw_id = cur.getLong( cur.getColumnIndex(
164
158
ContactsContract.Data.RAW_CONTACT_ID ) );
165
159
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 ) );
171
165
// if this is a number for a contact for whom we have not
172
166
// added a lookup, add a lookup for the contact id by phone
174
168
if( unadded_ids.contains( 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 );
169
cache.addLookup( new CacheIdentifier(
170
CacheIdentifier.Type.PRIMARY_NUMBER, number ), id );
171
unadded_ids.remove( id );
183
174
// add associated data
198
189
Long raw_id = cur.getLong( cur.getColumnIndex(
199
190
ContactsContract.Data.RAW_CONTACT_ID ) );
200
191
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 ) );
206
197
// if this is an email address for a contact for whom we have
207
198
// not added a lookup, add a lookup for the contact id by email
209
200
if( unadded_ids.contains( 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 );
201
cache.addLookup( new CacheIdentifier(
202
CacheIdentifier.Type.PRIMARY_EMAIL, email ), id );
203
unadded_ids.remove( id );
218
206
// add associated data
227
215
CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS,
229
217
ContactsContract.Data.MIMETYPE + " = '" +
230
CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE + "'",
218
CommonDataKinds.Organization.CONTENT_ITEM_TYPE + "'",
231
219
null, ContactsContract.Data.IS_PRIMARY + " DESC" );
232
220
while( cur.moveToNext() ) {
233
221
Long raw_id = cur.getLong( cur.getColumnIndex(
234
222
ContactsContract.Data.RAW_CONTACT_ID ) );
235
223
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 ) );
241
229
// add associated data
242
230
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 );
341
306
ContactsContract.RawContacts.CONTENT_URI,
343
308
ContactsContract.RawContacts._ID,
344
ContactsContract.RawContacts.ACCOUNT_NAME,
346
ContactsContract.RawContacts.DELETED + " = 0 AND " +
347
ContactsContract.RawContacts.CONTACT_ID + " = ? AND " +
310
ContactsContract.RawContacts.DELETED + " != 0 AND " +
348
311
"IFNULL( " + ContactsContract.RawContacts.ACCOUNT_NAME +
349
312
", '' ) = '' AND " +
350
313
"IFNULL( " + ContactsContract.RawContacts.ACCOUNT_TYPE +
353
String.valueOf( id ),
355
316
if( cur.moveToNext() )
356
317
raw_id = cur.getLong(
357
318
cur.getColumnIndex( ContactsContract.RawContacts._ID ) );
494
455
_activity.getContentResolver().insert(
495
456
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 );