/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: 2013-01-06 18:09:16 UTC
  • Revision ID: tim@ed.am-20130106180916-va3zobskfkzvdkao
stop using managedQuery(), which isn't cleaning up my queries

Show diffs side-by-side

added added

removed removed

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