/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: Tim Marston
  • Date: 2013-09-16 20:15:38 UTC
  • Revision ID: tim@ed.am-20130916201538-w2s54x86ml6kvjft
prevent NPE

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
281
281
                        }
282
282
                }
283
283
                cur.close();
 
284
 
 
285
                // get all birthdays
 
286
                cur = _activity.getContentResolver().query(
 
287
                        ContactsContract.Data.CONTENT_URI,
 
288
                        new String[] {
 
289
                                ContactsContract.Data.RAW_CONTACT_ID,
 
290
                                CommonDataKinds.Event.START_DATE,
 
291
                        },
 
292
                        ContactsContract.Data.MIMETYPE + " = '" +
 
293
                                CommonDataKinds.Event.CONTENT_ITEM_TYPE + "' AND " +
 
294
                                CommonDataKinds.Event.TYPE + " = '" +
 
295
                                CommonDataKinds.Event.TYPE_BIRTHDAY + "'",
 
296
                        null, null );
 
297
                while( cur.moveToNext() ) {
 
298
                        Long raw_id = cur.getLong( cur.getColumnIndex(
 
299
                                ContactsContract.Data.RAW_CONTACT_ID ) );
 
300
                        Long id = raw_to_aggregate_ids.get( raw_id );
 
301
                        if( id != null )
 
302
                        {
 
303
                                String birthday = cur.getString( cur.getColumnIndex(
 
304
                                        CommonDataKinds.Event.START_DATE ) );
 
305
 
 
306
                                // add associated data
 
307
                                cache.addAssociatedBirthday( id, birthday );
 
308
                        }
 
309
                }
 
310
                cur.close();
284
311
        }
285
312
 
286
313
        @Override
343
370
         * Obtain the raw contact id for the phone-only raw contact that is
344
371
         * associated with the aggregate contact id.  One will be created if
345
372
         * necessary.
 
373
         *
346
374
         * @param id the aggregate contact id
347
375
         * @return the raw contact id
348
376
         * @throws ContactCreationException
529
557
                        ContactsContract.Data.CONTENT_URI, values );
530
558
        }
531
559
 
 
560
        @Override
 
561
        public void addContactBirthday( Long id, String birthday )
 
562
                throws ContactCreationException
 
563
        {
 
564
                ContentValues values = new ContentValues();
 
565
                values.put( ContactsContract.Data.RAW_CONTACT_ID,
 
566
                        obtainRawContact( id ) );
 
567
                values.put( ContactsContract.Data.MIMETYPE,
 
568
                        CommonDataKinds.Event.CONTENT_ITEM_TYPE );
 
569
                values.put(
 
570
                        CommonDataKinds.Event.TYPE, CommonDataKinds.Event.TYPE_BIRTHDAY );
 
571
                values.put(
 
572
                        CommonDataKinds.Event.START_DATE, birthday );
 
573
                _activity.getContentResolver().insert(
 
574
                        ContactsContract.Data.CONTENT_URI, values );
 
575
        }
532
576
}