/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/ContactsBackend.java

  • Committer: edam
  • Date: 2012-12-21 14:47:57 UTC
  • Revision ID: tim@ed.am-20121221144757-5cb1lgsp7fdt7p2n
updated TODO

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * ContactsBackend.java
3
3
 *
4
 
 * Copyright (C) 2012 to 2013 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2012 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Import Contacts program (hereafter referred
7
 
 * to as "this program").  For more information, see
 
7
 * to as "this program"). For more information, see
8
8
 * http://ed.am/dev/android/import-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
58
58
                HashMap< Long, String > notes = new HashMap< Long, String >();
59
59
 
60
60
                // get all contacts
61
 
                cur = _activity.getContentResolver().query(
62
 
                        Contacts.People.CONTENT_URI,
 
61
                cur = _activity.managedQuery( Contacts.People.CONTENT_URI,
63
62
                        new String[] {
64
63
                                Contacts.People._ID,
65
64
                                Contacts.People.NAME,
97
96
                                        notes.put( id, note );
98
97
                        }
99
98
                }
100
 
                cur.close();
101
99
 
102
100
                // get contact organisations, primary ones first
103
 
                cur = _activity.getContentResolver().query(
104
 
                        Contacts.Organizations.CONTENT_URI,
 
101
                cur = _activity.managedQuery( Contacts.Organizations.CONTENT_URI,
105
102
                        new String[] {
106
103
                                Contacts.Phones.PERSON_ID,
107
104
                                Contacts.Organizations.COMPANY,
127
124
                        // add associated data
128
125
                        cache.addAssociatedOrganisation( id, organisation );
129
126
                }
130
 
                cur.close();
131
127
 
132
128
                // get all phone numbers, primary ones first
133
 
                cur = _activity.getContentResolver().query(
134
 
                        Contacts.Phones.CONTENT_URI,
 
129
                cur = _activity.managedQuery( Contacts.Phones.CONTENT_URI,
135
130
                        new String[] {
136
131
                                Contacts.Phones.PERSON_ID,
137
132
                                Contacts.Phones.NUMBER,
157
152
                        // add associated data
158
153
                        cache.addAssociatedNumber( id, number );
159
154
                }
160
 
                cur.close();
161
155
 
162
156
                // now get all email addresses, primary ones first, and postal addresses
163
 
                cur = _activity.getContentResolver().query(
164
 
                        Contacts.ContactMethods.CONTENT_URI,
 
157
                cur = _activity.managedQuery( Contacts.ContactMethods.CONTENT_URI,
165
158
                        new String[] {
166
159
                                Contacts.ContactMethods.PERSON_ID,
167
160
                                Contacts.ContactMethods.DATA,
205
198
                                cache.addAssociatedAddress( id, address );
206
199
                        }
207
200
                }
208
 
                cur.close();
209
201
 
210
202
                // finally, add the notes that we stored earlier (we have to add these
211
203
                // at the end because we can't be sure which piece of contact data will
257
249
                        switch( type )
258
250
                        {
259
251
                        case ContactData.TYPE_HOME:
260
 
                                return Contacts.PhonesColumns.TYPE_HOME;
 
252
                                return Contacts.Phones.TYPE_HOME;
261
253
                        case ContactData.TYPE_WORK:
262
 
                                return Contacts.PhonesColumns.TYPE_WORK;
 
254
                                return Contacts.Phones.TYPE_WORK;
263
255
                        case ContactData.TYPE_MOBILE:
264
 
                                return Contacts.PhonesColumns.TYPE_MOBILE;
 
256
                                return Contacts.Phones.TYPE_MOBILE;
265
257
                        case ContactData.TYPE_FAX_HOME:
266
 
                                return Contacts.PhonesColumns.TYPE_FAX_HOME;
 
258
                                return Contacts.Phones.TYPE_FAX_HOME;
267
259
                        case ContactData.TYPE_FAX_WORK:
268
 
                                return Contacts.PhonesColumns.TYPE_FAX_WORK;
 
260
                                return Contacts.Phones.TYPE_FAX_WORK;
269
261
                        case ContactData.TYPE_PAGER:
270
 
                                return Contacts.PhonesColumns.TYPE_PAGER;
 
262
                                return Contacts.Phones.TYPE_PAGER;
271
263
                        }
272
264
                }
273
265
                else if( cls == Contacts.ContactMethods.class )
275
267
                        switch( type )
276
268
                        {
277
269
                        case ContactData.TYPE_HOME:
278
 
                                return Contacts.ContactMethodsColumns.TYPE_HOME;
 
270
                                return Contacts.ContactMethods.TYPE_HOME;
279
271
                        case ContactData.TYPE_WORK:
280
 
                                return Contacts.ContactMethodsColumns.TYPE_WORK;
 
272
                                return Contacts.ContactMethods.TYPE_WORK;
281
273
                        }
282
274
                }
283
275
 
371
363
                        values, null, null );
372
364
        }
373
365
 
374
 
        @Override
375
 
        public void addContactBirthday( Long id, String birthday )
376
 
                throws ContactCreationException
377
 
        {
378
 
                // this contacts API doesn't support birthdays, so just ignore them
379
 
        }
380
366
}