/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: Tim Marston
  • Date: 2013-10-20 17:51:32 UTC
  • Revision ID: tim@ed.am-20131020175132-lvqrbal1ztz5jepl
updated .bzrignore

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * ContactsBackend.java
3
3
 *
4
 
 * Copyright (C) 2012 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2012 to 2013 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.managedQuery( Contacts.People.CONTENT_URI,
 
61
                cur = _activity.getContentResolver().query(
 
62
                        Contacts.People.CONTENT_URI,
62
63
                        new String[] {
63
64
                                Contacts.People._ID,
64
65
                                Contacts.People.NAME,
96
97
                                        notes.put( id, note );
97
98
                        }
98
99
                }
 
100
                cur.close();
99
101
 
100
102
                // get contact organisations, primary ones first
101
 
                cur = _activity.managedQuery( Contacts.Organizations.CONTENT_URI,
 
103
                cur = _activity.getContentResolver().query(
 
104
                        Contacts.Organizations.CONTENT_URI,
102
105
                        new String[] {
103
106
                                Contacts.Phones.PERSON_ID,
104
107
                                Contacts.Organizations.COMPANY,
124
127
                        // add associated data
125
128
                        cache.addAssociatedOrganisation( id, organisation );
126
129
                }
 
130
                cur.close();
127
131
 
128
132
                // get all phone numbers, primary ones first
129
 
                cur = _activity.managedQuery( Contacts.Phones.CONTENT_URI,
 
133
                cur = _activity.getContentResolver().query(
 
134
                        Contacts.Phones.CONTENT_URI,
130
135
                        new String[] {
131
136
                                Contacts.Phones.PERSON_ID,
132
137
                                Contacts.Phones.NUMBER,
152
157
                        // add associated data
153
158
                        cache.addAssociatedNumber( id, number );
154
159
                }
 
160
                cur.close();
155
161
 
156
162
                // now get all email addresses, primary ones first, and postal addresses
157
 
                cur = _activity.managedQuery( Contacts.ContactMethods.CONTENT_URI,
 
163
                cur = _activity.getContentResolver().query(
 
164
                        Contacts.ContactMethods.CONTENT_URI,
158
165
                        new String[] {
159
166
                                Contacts.ContactMethods.PERSON_ID,
160
167
                                Contacts.ContactMethods.DATA,
198
205
                                cache.addAssociatedAddress( id, address );
199
206
                        }
200
207
                }
 
208
                cur.close();
201
209
 
202
210
                // finally, add the notes that we stored earlier (we have to add these
203
211
                // at the end because we can't be sure which piece of contact data will
249
257
                        switch( type )
250
258
                        {
251
259
                        case ContactData.TYPE_HOME:
252
 
                                return Contacts.Phones.TYPE_HOME;
 
260
                                return Contacts.PhonesColumns.TYPE_HOME;
253
261
                        case ContactData.TYPE_WORK:
254
 
                                return Contacts.Phones.TYPE_WORK;
 
262
                                return Contacts.PhonesColumns.TYPE_WORK;
255
263
                        case ContactData.TYPE_MOBILE:
256
 
                                return Contacts.Phones.TYPE_MOBILE;
 
264
                                return Contacts.PhonesColumns.TYPE_MOBILE;
257
265
                        case ContactData.TYPE_FAX_HOME:
258
 
                                return Contacts.Phones.TYPE_FAX_HOME;
 
266
                                return Contacts.PhonesColumns.TYPE_FAX_HOME;
259
267
                        case ContactData.TYPE_FAX_WORK:
260
 
                                return Contacts.Phones.TYPE_FAX_WORK;
 
268
                                return Contacts.PhonesColumns.TYPE_FAX_WORK;
261
269
                        case ContactData.TYPE_PAGER:
262
 
                                return Contacts.Phones.TYPE_PAGER;
 
270
                                return Contacts.PhonesColumns.TYPE_PAGER;
263
271
                        }
264
272
                }
265
273
                else if( cls == Contacts.ContactMethods.class )
267
275
                        switch( type )
268
276
                        {
269
277
                        case ContactData.TYPE_HOME:
270
 
                                return Contacts.ContactMethods.TYPE_HOME;
 
278
                                return Contacts.ContactMethodsColumns.TYPE_HOME;
271
279
                        case ContactData.TYPE_WORK:
272
 
                                return Contacts.ContactMethods.TYPE_WORK;
 
280
                                return Contacts.ContactMethodsColumns.TYPE_WORK;
273
281
                        }
274
282
                }
275
283
 
363
371
                        values, null, null );
364
372
        }
365
373
 
 
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
        }
366
380
}