/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts

« back to all changes in this revision

Viewing changes to src/am/ed/importcontacts/ContactsContractBackend.java

  • Committer: edam
  • Date: 2012-12-21 21:05:13 UTC
  • Revision ID: tim@ed.am-20121221210513-scyf50006hqadgjw
updated NEWS

Show diffs side-by-side

added added

removed removed

57
57
                // build a set of aggregate contact ids that haven't been added to the
58
58
                // cache yet
59
59
                HashSet< Long > unadded_ids = new HashSet< Long >();
60
 
                cur = _activity.getContentResolver().query(
61
 
                        ContactsContract.Contacts.CONTENT_URI,
 
60
                cur = _activity.managedQuery( ContactsContract.Contacts.CONTENT_URI,
62
61
                        new String[] {
63
62
                                ContactsContract.Contacts._ID,
64
63
                        }, null, null, null );
67
66
                                cur.getColumnIndex( ContactsContract.Contacts._ID ) );
68
67
                        unadded_ids.add( id );
69
68
                }
70
 
                cur.close();
71
69
 
72
70
                // build a mapping of the ids of raw contacts to the ids of their
73
71
                // aggregate contacts
74
72
                HashMap< Long, Long > raw_to_aggregate_ids =
75
73
                        new HashMap< Long, Long >();
76
 
                cur = _activity.getContentResolver().query(
77
 
                        ContactsContract.RawContacts.CONTENT_URI,
 
74
                cur = _activity.managedQuery( ContactsContract.RawContacts.CONTENT_URI,
78
75
                        new String[] {
79
76
                                ContactsContract.RawContacts._ID,
80
77
                                ContactsContract.RawContacts.CONTACT_ID,
86
83
                                cur.getColumnIndex( ContactsContract.RawContacts.CONTACT_ID ) );
87
84
                        raw_to_aggregate_ids.put( raw_id, id );
88
85
                }
89
 
                cur.close();
90
86
 
91
87
                // get structured names, primary ones first
92
 
                cur = _activity.getContentResolver().query(
93
 
                        ContactsContract.Data.CONTENT_URI,
 
88
                cur = _activity.managedQuery( ContactsContract.Data.CONTENT_URI,
94
89
                        new String[] {
95
90
                                ContactsContract.Data.RAW_CONTACT_ID,
96
91
                                CommonDataKinds.StructuredName.DISPLAY_NAME,
119
114
                                }
120
115
                        }
121
116
                }
122
 
                cur.close();
123
117
 
124
118
                // get contact organisations, primary ones first
125
 
                cur = _activity.getContentResolver().query(
126
 
                        ContactsContract.Data.CONTENT_URI,
 
119
                cur = _activity.managedQuery( ContactsContract.Data.CONTENT_URI,
127
120
                        new String[] {
128
121
                                ContactsContract.Data.RAW_CONTACT_ID,
129
122
                                CommonDataKinds.Organization.COMPANY,
156
149
                                cache.addAssociatedOrganisation( id, organisation );
157
150
                        }
158
151
                }
159
 
                cur.close();
160
152
 
161
153
                // get all phone numbers, primary ones first
162
 
                cur = _activity.getContentResolver().query(
163
 
                        ContactsContract.Data.CONTENT_URI,
 
154
                cur = _activity.managedQuery( ContactsContract.Data.CONTENT_URI,
164
155
                        new String[] {
165
156
                                ContactsContract.Data.RAW_CONTACT_ID,
166
157
                                CommonDataKinds.Phone.NUMBER,
193
184
                                cache.addAssociatedNumber( id, number );
194
185
                        }
195
186
                }
196
 
                cur.close();
197
187
 
198
188
                // get all email addresses, primary ones first
199
 
                cur = _activity.getContentResolver().query(
200
 
                        ContactsContract.Data.CONTENT_URI,
 
189
                cur = _activity.managedQuery( ContactsContract.Data.CONTENT_URI,
201
190
                        new String[] {
202
191
                                ContactsContract.Data.RAW_CONTACT_ID,
203
192
                                CommonDataKinds.Email.DATA,
230
219
                                cache.addAssociatedEmail( id, email );
231
220
                        }
232
221
                }
233
 
                cur.close();
234
222
 
235
223
                // get all postal addresses, primary ones first
236
 
                cur = _activity.getContentResolver().query(
237
 
                        ContactsContract.Data.CONTENT_URI,
 
224
                cur = _activity.managedQuery( ContactsContract.Data.CONTENT_URI,
238
225
                        new String[] {
239
226
                                ContactsContract.Data.RAW_CONTACT_ID,
240
227
                                CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS,
255
242
                                cache.addAssociatedAddress( id, address );
256
243
                        }
257
244
                }
258
 
                cur.close();
259
245
 
260
246
                // get all notes
261
 
                cur = _activity.getContentResolver().query(
262
 
                        ContactsContract.Data.CONTENT_URI,
 
247
                cur = _activity.managedQuery( ContactsContract.Data.CONTENT_URI,
263
248
                        new String[] {
264
249
                                ContactsContract.Data.RAW_CONTACT_ID,
265
250
                                CommonDataKinds.Note.NOTE,
280
265
                                cache.addAssociatedNote( id, note );
281
266
                        }
282
267
                }
283
 
                cur.close();
284
268
        }
285
269
 
286
270
        @Override
316
300
                        ContentUris.withAppendedId(
317
301
                                ContactsContract.RawContacts.CONTENT_URI, raw_id ),
318
302
                        ContactsContract.RawContacts.Entity.CONTENT_DIRECTORY );
319
 
                Cursor cur = _activity.getContentResolver().query( contact_uri,
 
303
                Cursor cur = _activity.managedQuery( contact_uri,
320
304
                        new String[] {
321
305
                                ContactsContract.RawContacts.CONTACT_ID,
322
306
                        }, null, null, null );
324
308
                if( cur.moveToNext() )
325
309
                        id = cur.getLong(
326
310
                                cur.getColumnIndex( ContactsContract.RawContacts.CONTACT_ID ) );
327
 
                cur.close();
328
311
                if( id == null || id == 0 )
329
312
                {
330
313
                        // we didn't find an aggregate contact id, so try to clean up (by
354
337
                if( raw_id != null ) return raw_id;
355
338
 
356
339
                // find a corresponding raw contact that has no account name/type
357
 
                Cursor cur = _activity.getContentResolver().query(
 
340
                Cursor cur = _activity.managedQuery(
358
341
                        ContactsContract.RawContacts.CONTENT_URI,
359
342
                        new String[] {
360
343
                                ContactsContract.RawContacts._ID,
372
355
                if( cur.moveToNext() )
373
356
                        raw_id = cur.getLong(
374
357
                                cur.getColumnIndex( ContactsContract.RawContacts._ID ) );
375
 
                cur.close();
376
358
 
377
359
                // if one wasn't found, we'll need to create one
378
360
                if( raw_id == null ) {