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

  • Committer: edam
  • Date: 2012-04-24 09:56:17 UTC
  • Revision ID: tim@ed.am-20120424095617-lsfkkpkrlqk9xthn
updated all URLs, email addresses and package names to ed.am

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * Importer.java
3
3
 *
4
 
 * Copyright (C) 2009 to 2013 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2009 to 2011 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
27
27
import java.util.HashMap;
28
28
import java.util.HashSet;
29
29
import java.util.Iterator;
30
 
import java.util.Locale;
31
30
import java.util.Set;
32
31
import java.util.regex.Matcher;
33
32
import java.util.regex.Pattern;
34
33
 
35
 
import am.ed.importcontacts.Backend.ContactCreationException;
 
34
import android.content.ContentUris;
 
35
import android.content.ContentValues;
36
36
import android.content.SharedPreferences;
 
37
import android.net.Uri;
37
38
import android.os.Message;
 
39
import android.provider.Contacts;
 
40
import android.provider.Contacts.PhonesColumns;
 
41
 
38
42
 
39
43
public class Importer extends Thread
40
44
{
55
59
        private boolean _abort = false;
56
60
        private boolean _is_finished = false;
57
61
        private ContactsCache _contacts_cache = null;
58
 
        private Backend _backend = null;
59
62
 
60
63
        /**
61
64
         * Data about a contact
62
65
         */
63
66
        public class ContactData
64
67
        {
65
 
                public final static int TYPE_HOME = 0;
66
 
                public final static int TYPE_WORK = 1;
67
 
                public final static int TYPE_MOBILE = 2;        // only used with phones
68
 
                public final static int TYPE_FAX_HOME = 3;      // only used with phones
69
 
                public final static int TYPE_FAX_WORK = 4;      // only used with phones
70
 
                public final static int TYPE_PAGER = 5;         // only used with phones
71
 
 
72
68
                class TypeDetail
73
69
                {
74
70
                        protected int _type;
141
137
                protected HashMap< String, PreferredDetail > _numbers = null;
142
138
                protected HashMap< String, PreferredDetail > _emails = null;
143
139
                protected HashMap< String, TypeDetail > _addresses = null;
144
 
                protected HashSet< String > _notes = null;
145
 
                protected String _birthday = null;
146
140
 
147
141
                private ContactsCache.CacheIdentifier _cache_identifier = null;
148
142
 
186
180
 
187
181
                        // if this is the first organisation added, or it's a preferred
188
182
                        // organisation and the current primary organisation isn't, then
189
 
                        // record this as the primary organisation
 
183
                        // record this as the primary organisation.
190
184
                        if( _primary_organisation == null ||
191
185
                                ( is_preferred && !_primary_organisation_is_preferred ) )
192
186
                        {
234
228
                                        new PreferredDetail( type, false ) );
235
229
 
236
230
                        final Set< Integer > non_voice_types = new HashSet< Integer >(
237
 
                                Arrays.asList( TYPE_FAX_HOME, TYPE_FAX_WORK, TYPE_PAGER ) );
 
231
                                Arrays.asList( PhonesColumns.TYPE_FAX_HOME,
 
232
                                        PhonesColumns.TYPE_FAX_WORK, PhonesColumns.TYPE_PAGER ) );
238
233
 
239
234
                        // if this is the first number added, or it's a preferred number
240
235
                        // and the current primary number isn't, or this number is on equal
241
236
                        // standing with the primary number in terms of preference and it is
242
237
                        // a voice number and the primary number isn't, then record this as
243
 
                        // the primary number
 
238
                        // the primary number.
244
239
                        if( _primary_number == null ||
245
240
                                ( is_preferred && !_primary_number_is_preferred ) ||
246
241
                                ( is_preferred == _primary_number_is_preferred &&
279
274
                        email = sanitisesEmailAddress( email );
280
275
                        if( email == null )
281
276
                        {
282
 
                                // TODO: warn that an imported email address is being ignored
 
277
                                // TODO: warn that an imported email addtrss is being ignored
283
278
                                return;
284
279
                        }
285
280
 
292
287
 
293
288
                        // if this is the first email added, or it's a preferred email and
294
289
                        // the current primary organisation isn't, then record this as the
295
 
                        // primary email
 
290
                        // primary email.
296
291
                        if( _primary_email == null ||
297
292
                                ( is_preferred && !_primary_email_is_preferred ) )
298
293
                        {
346
341
                        return _addresses;
347
342
                }
348
343
 
349
 
                protected void addNote( String note )
350
 
                {
351
 
                        if( _notes == null ) _notes = new HashSet< String >();
352
 
                        if( !_notes.contains( note ) )
353
 
                                _notes.add( note );
354
 
                }
355
 
 
356
 
                public boolean hasNotes()
357
 
                {
358
 
                        return _notes != null && _notes.size() > 0;
359
 
                }
360
 
 
361
 
                public HashSet< String > getNotes()
362
 
                {
363
 
                        return _notes;
364
 
                }
365
 
 
366
 
                public void setBirthday( String birthday )
367
 
                {
368
 
                        _birthday = birthday;
369
 
                }
370
 
 
371
 
                public boolean hasBirthday()
372
 
                {
373
 
                        return _birthday != null;
374
 
                }
375
 
 
376
 
                public String getBirthday()
377
 
                {
378
 
                        return _birthday;
379
 
                }
380
 
 
381
344
                protected void finalise()
382
345
                        throws ContactNotIdentifiableException
383
346
                {
384
 
                        // Ensure that if there is a primary number, it is preferred so
385
 
                        // that there is always one preferred number.  Android will assign
 
347
                        // ensure that if there is a primary number, it is preferred so
 
348
                        // that there is always one preferred number. Android will assign
386
349
                        // preference to one anyway so we might as well decide one sensibly.
387
350
                        if( _primary_number != null ) {
388
351
                                PreferredDetail data = _numbers.get( _primary_number );
406
369
 
407
370
                        // create a cache identifier from this contact data, which can be
408
371
                        // used to look-up an existing contact
409
 
                        _cache_identifier = ContactsCache.CacheIdentifier.factory( this );
 
372
                        _cache_identifier = ContactsCache.createIdentifier( this );
410
373
                        if( _cache_identifier == null )
411
374
                                throw new ContactNotIdentifiableException();
412
375
                }
433
396
                        Matcher m = p.matcher( email );
434
397
                        if( m.matches() ) {
435
398
                                String[] bits = email.split( "@" );
436
 
                                return bits[ 0 ] + "@" + bits[ 1 ].toLowerCase( Locale.US );
 
399
                                return bits[ 0 ] + "@" + bits[ 1 ].toLowerCase();
437
400
                        }
438
401
                        return null;
439
402
                }
458
421
                        // update UI
459
422
                        setProgressMessage( R.string.doit_caching );
460
423
 
461
 
                        // create the appropriate backend
462
 
                        if( Integer.parseInt( android.os.Build.VERSION.SDK ) >= 5 )
463
 
                                _backend = new ContactsContractBackend( _doit );
464
 
                        else
465
 
                                _backend = new ContactsBackend( _doit );
466
 
 
467
 
                        // create a cache of existing contacts and populate it
 
424
                        // build a cache of existing contacts
468
425
                        _contacts_cache = new ContactsCache();
469
 
                        _backend.populateCache( _contacts_cache );
 
426
                        _contacts_cache.buildCache( _doit );
470
427
 
471
428
                        // do the import
472
429
                        onImport();
599
556
                checkAbort();
600
557
                _doit._handler.sendMessage( Message.obtain(
601
558
                        _doit._handler, Doit.MESSAGE_SETMAXPROGRESS,
602
 
                        Integer.valueOf( max_progress ) ) );
 
559
                        new Integer( max_progress ) ) );
603
560
        }
604
561
 
605
562
        protected void setTmpProgress( int tmp_progress )
608
565
                checkAbort();
609
566
                _doit._handler.sendMessage( Message.obtain(
610
567
                        _doit._handler, Doit.MESSAGE_SETTMPPROGRESS,
611
 
                        Integer.valueOf( tmp_progress ) ) );
 
568
                        new Integer( tmp_progress ) ) );
612
569
        }
613
570
 
614
571
        protected void setProgress( int progress ) throws AbortImportException
616
573
                checkAbort();
617
574
                _doit._handler.sendMessage( Message.obtain(
618
575
                        _doit._handler, Doit.MESSAGE_SETPROGRESS,
619
 
                        Integer.valueOf( progress ) ) );
 
576
                        new Integer( progress ) ) );
620
577
        }
621
578
 
622
579
        protected void finish( int action ) throws AbortImportException
640
597
                return _doit.getText( res );
641
598
        }
642
599
 
643
 
        /**
644
 
         * Should we skip a contact, given whether it exists or not and the current
645
 
         * merge setting?  This routine handles throwing up a prompt, if required.
646
 
         *
647
 
         * @param contact_detail the display name of the contact
648
 
         * @param exists true if this contact matches one in the cache
649
 
         * @param merge_setting the merge setting to use
650
 
         * @return true if the contact should be skipped outright
651
 
         * @throws AbortImportException
652
 
         */
653
 
        synchronized private boolean shouldWeSkipContact( String contact_detail,
654
 
                boolean exists, int merge_setting ) throws AbortImportException
 
600
        synchronized private boolean checkForDuplicate(
 
601
                ContactsCache.CacheIdentifier cache_identifier, int merge_setting )
 
602
                throws AbortImportException
655
603
        {
656
604
                _last_merge_decision = merge_setting;
657
605
 
 
606
                // it is ok to use contact.getCacheIdentifier(). The contact has already
 
607
                // been finalised, which means a valid cache identifier will have been
 
608
                // created for it (or it would have been skipped)
 
609
 
658
610
                // handle special cases
659
611
                switch( merge_setting )
660
612
                {
661
613
                case Doit.ACTION_KEEP:
662
 
                        // if we are skipping on a duplicate, check for one
663
 
                        return exists;
 
614
                        // if we keep contacts on duplicate, we better check for one
 
615
                        return !_contacts_cache.canLookup( cache_identifier );
664
616
 
665
617
                case Doit.ACTION_PROMPT:
666
 
                        // if we are prompting on duplicate, then we can say that we won't
667
 
                        // skip if there isn't one
668
 
                        if( !exists ) return false;
 
618
                        // if we are prompting on duplicate, we better check for one and if
 
619
                        // the contact doesn'te exist, we want to import it
 
620
                        if( !_contacts_cache.canLookup( cache_identifier ) )
 
621
                                return true;
669
622
 
670
 
                        // ok, duplicate exists, so do prompt
 
623
                        // ok, it exists, so do prompt
671
624
                        _doit._handler.sendMessage( Message.obtain( _doit._handler,
672
 
                                Doit.MESSAGE_MERGEPROMPT, contact_detail ) );
 
625
                                Doit.MESSAGE_MERGEPROMPT, cache_identifier.getDetail() ) );
673
626
                        try {
674
627
                                wait();
675
628
                        }
683
636
                                _merge_setting = _response;
684
637
 
685
638
                        // recurse, with our new merge setting
686
 
                        return shouldWeSkipContact( contact_detail, exists, _response );
 
639
                        return checkForDuplicate( cache_identifier, _response );
687
640
                }
688
641
 
689
 
                // for all other cases (either overwriting or merging) we don't skip
690
 
                return false;
 
642
                // for all other cases (either overwriting or merging) we will need the
 
643
                // imported data
 
644
                return true;
691
645
        }
692
646
 
693
647
        protected void skipContact() throws AbortImportException
694
648
        {
695
649
                checkAbort();
696
 
 
697
 
                // show that we're skipping a new contact
698
650
                _doit._handler.sendEmptyMessage( Doit.MESSAGE_CONTACTSKIPPED );
699
651
        }
700
652
 
703
655
        {
704
656
                checkAbort();
705
657
 
706
 
                // It is expected that we use contact.getCacheIdentifier() here.  The
 
658
                // It is expected that we use contact.getCacheIdentifier() here. The
707
659
                // contact we are passed should have been successfully finalise()d,
708
660
                // which includes generating a valid cache identifier.
709
661
                ContactsCache.CacheIdentifier cache_identifier =
710
662
                        contact.getCacheIdentifier();
711
663
 
 
664
                // check to see if this contact is a duplicate and should be skipped
 
665
                if( !checkForDuplicate( cache_identifier, _merge_setting ) ) {
 
666
                        skipContact();
 
667
                        return;
 
668
                }
 
669
 
712
670
//              if( !showContinue( "====[ IMPORTING ]====\n: " + contact._name ) )
713
671
//                      finish( ACTION_ABORT );
714
672
 
 
673
                // keep track of whether we've informed the UI of what we're doing
 
674
                boolean ui_informed = false;
 
675
 
715
676
                // attempt to lookup the id of an existing contact in the cache with
716
677
                // this contact data's cache identifier
717
678
                Long id = (Long)_contacts_cache.lookup( cache_identifier );
718
679
 
719
 
                // check to see if this contact should be skipped
720
 
                if( shouldWeSkipContact( cache_identifier.getDetail(), id != null,
721
 
                        _merge_setting ) )
 
680
                // does contact exist already?
 
681
                if( id != null )
722
682
                {
723
 
                        // show that we're skipping a contact
724
 
                        _doit._handler.sendEmptyMessage( Doit.MESSAGE_CONTACTSKIPPED );
725
 
                        return;
 
683
                        // should we skip this import altogether?
 
684
                        if( _last_merge_decision == Doit.ACTION_KEEP ) return;
 
685
 
 
686
                        // get contact's URI
 
687
                        Uri contact_uri = ContentUris.withAppendedId(
 
688
                                Contacts.People.CONTENT_URI, id );
 
689
 
 
690
                        // should we destroy the existing contact before importing?
 
691
                        if( _last_merge_decision == Doit.ACTION_OVERWRITE )
 
692
                        {
 
693
                                // remove from device
 
694
                                _doit.getContentResolver().delete( contact_uri, null, null );
 
695
 
 
696
                                // update cache
 
697
                                _contacts_cache.removeLookup( contact.getCacheIdentifier() );
 
698
                                _contacts_cache.removeAssociatedData( id );
 
699
 
 
700
                                // show that we're overwriting a contact
 
701
                                _doit._handler.sendEmptyMessage(
 
702
                                                Doit.MESSAGE_CONTACTOVERWRITTEN );
 
703
                                ui_informed = true;
 
704
 
 
705
                                // discard the contact id
 
706
                                id = null;
 
707
                        }
726
708
                }
727
709
 
728
 
                // if a contact exists, and we're overwriting, destroy the existing
729
 
                // contact before importing
730
 
                boolean contact_deleted = false;
731
 
                if( id != null && _last_merge_decision == Doit.ACTION_OVERWRITE )
 
710
                // if we don't have a contact id yet (or if we did, but we destroyed it
 
711
                // when we deleted the contact), we'll have to create a new contact
 
712
                if( id == null )
732
713
                {
733
 
                        contact_deleted = true;
 
714
                        // create a new contact
 
715
                        ContentValues values = new ContentValues();
 
716
                        values.put( Contacts.People.NAME, contact._name );
 
717
                        Uri contact_uri = _doit.getContentResolver().insert(
 
718
                                Contacts.People.CONTENT_URI, values );
 
719
                        id = ContentUris.parseId( contact_uri );
 
720
                        if( id == null || id <= 0 )
 
721
                                showError( R.string.error_unabletoaddcontact );
734
722
 
735
 
                        // remove from device
736
 
                        _backend.deleteContact( id );
 
723
                        // try to add them to the "My Contacts" group
 
724
                        try {
 
725
                                Contacts.People.addToMyContactsGroup(
 
726
                                        _doit.getContentResolver(), id );
 
727
                        }
 
728
                        catch( IllegalStateException e ) {
 
729
                                // ignore any failure
 
730
                        }
737
731
 
738
732
                        // update cache
739
 
                        _contacts_cache.removeLookup( cache_identifier );
740
 
                        _contacts_cache.removeAssociatedData( id );
741
 
 
742
 
                        // show that we're overwriting a contact
743
 
                        _doit._handler.sendEmptyMessage( Doit.MESSAGE_CONTACTOVERWRITTEN );
744
 
 
745
 
                        // discard the contact id
746
 
                        id = null;
747
 
                }
748
 
 
749
 
                try {
750
 
                        // if we don't have a contact id yet (or we did, but we destroyed it
751
 
                        // when we deleted the contact), we'll have to create a new contact
752
 
                        if( id == null )
753
 
                        {
754
 
                                // create a new contact
755
 
                                id = _backend.addContact( contact._name );
756
 
 
757
 
                                // update cache
758
 
                                _contacts_cache.addLookup( cache_identifier, id );
759
 
 
760
 
                                // if we haven't already shown that we're overwriting a contact,
761
 
                                // show that we're creating a new contact
762
 
                                if( !contact_deleted )
763
 
                                        _doit._handler.sendEmptyMessage(
764
 
                                                Doit.MESSAGE_CONTACTCREATED );
 
733
                        _contacts_cache.addLookup(
 
734
                                ContactsCache.createIdentifier( contact ), id );
 
735
 
 
736
                        // if we haven't already shown that we're overwriting a contact,
 
737
                        // show that we're creating a new contact
 
738
                        if( !ui_informed ) {
 
739
                                _doit._handler.sendEmptyMessage( Doit.MESSAGE_CONTACTCREATED );
 
740
                                ui_informed = true;
765
741
                        }
766
 
                        else
767
 
                                // show that we're merging with an existing contact
768
 
                                _doit._handler.sendEmptyMessage( Doit.MESSAGE_CONTACTMERGED );
769
 
 
770
 
                        // import contact parts
771
 
                        if( contact.hasNumbers() )
772
 
                                importContactPhones( id, contact.getNumbers() );
773
 
                        if( contact.hasEmails() )
774
 
                                importContactEmails( id, contact.getEmails() );
775
 
                        if( contact.hasAddresses() )
776
 
                                importContactAddresses( id, contact.getAddresses() );
777
 
                        if( contact.hasOrganisations() )
778
 
                                importContactOrganisations( id, contact.getOrganisations() );
779
 
                        if( contact.hasNotes() )
780
 
                                importContactNotes( id, contact.getNotes() );
781
 
                        if( contact.hasBirthday() )
782
 
                                importContactBirthday( id, contact.getBirthday() );
783
 
                }
784
 
                catch( Backend.ContactCreationException e )
785
 
                {
786
 
                        showError( R.string.error_unabletoaddcontact );
787
 
                }
 
742
                }
 
743
 
 
744
                // if we haven't already shown that we're overwriting or creating a
 
745
                // contact, show that we're merging a contact
 
746
                if( !ui_informed )
 
747
                        _doit._handler.sendEmptyMessage( Doit.MESSAGE_CONTACTMERGED );
 
748
 
 
749
                // import contact parts
 
750
                if( contact.hasNumbers() )
 
751
                        importContactPhones( id, contact.getNumbers() );
 
752
                if( contact.hasEmails() )
 
753
                        importContactEmails( id, contact.getEmails() );
 
754
                if( contact.hasAddresses() )
 
755
                        importContactAddresses( id, contact.getAddresses() );
 
756
                if( contact.hasOrganisations() )
 
757
                        importContactOrganisations( id, contact.getOrganisations() );
788
758
        }
789
759
 
790
760
        private void importContactPhones( Long id,
791
 
                HashMap< String, ContactData.PreferredDetail > datas )
792
 
                throws ContactCreationException
 
761
                        HashMap< String, ContactData.PreferredDetail > datas )
793
762
        {
 
763
                // get URI to contact's phones
 
764
                Uri contact_phones_uri = Uri.withAppendedPath(
 
765
                        ContentUris.withAppendedId( Contacts.People.CONTENT_URI, id ),
 
766
                        Contacts.People.Phones.CONTENT_DIRECTORY );
 
767
                Set< String > datas_keys = datas.keySet();
 
768
 
794
769
                // add phone numbers
795
 
                Set< String > datas_keys = datas.keySet();
796
770
                Iterator< String > i = datas_keys.iterator();
797
771
                while( i.hasNext() ) {
798
772
                        String number = i.next();
799
773
                        ContactData.PreferredDetail data = datas.get( number );
800
774
 
801
 
                        // We don't want to add this number if it's crap, or it already
802
 
                        // exists (which would cause a duplicate to be created).  We don't
803
 
                        // take in to account the type when checking for duplicates.  This
804
 
                        // is intentional: types aren't really very reliable.  We assume
805
 
                        // that if the number exists at all, it doesn't need importing.
806
 
                        // Because of this, we also can't update the cache (which we don't
807
 
                        // need to anyway, so it's not a problem).
 
775
                        // we don't want to add this number if it's crap, or it already
 
776
                        // exists (which would cause a duplicate to be created). We don't
 
777
                        // take in to account the type when checking for duplicates. This is
 
778
                        // intentional: types aren't really very reliable. We assume that
 
779
                        // if the number exists at all, it doesn't need importing. Because
 
780
                        // of this, we also can't update the cache (which we don't need to
 
781
                        // anyway, so it's not a problem).
808
782
                        if( _contacts_cache.hasAssociatedNumber( id, number ) )
809
783
                                continue;
810
784
 
811
785
                        // add phone number
812
 
                        _backend.addContactPhone( id, number, data );
 
786
                        ContentValues values = new ContentValues();
 
787
                        values.put( Contacts.Phones.TYPE, data.getType() );
 
788
                        values.put( Contacts.Phones.NUMBER, number );
 
789
                        if( data.isPreferred() )
 
790
                                values.put( Contacts.Phones.ISPRIMARY, 1 );
 
791
                        _doit.getContentResolver().insert( contact_phones_uri, values );
813
792
 
814
793
                        // and add this address to the cache to prevent a addition of
815
794
                        // duplicate date from another file
818
797
        }
819
798
 
820
799
        private void importContactEmails( Long id,
821
 
                HashMap< String, ContactData.PreferredDetail > datas )
822
 
                throws ContactCreationException
 
800
                        HashMap< String, ContactData.PreferredDetail > datas )
823
801
        {
 
802
                // get URI to contact's contact methods
 
803
                Uri contact_contact_methods_uri = Uri.withAppendedPath(
 
804
                        ContentUris.withAppendedId( Contacts.People.CONTENT_URI, id ),
 
805
                        Contacts.People.ContactMethods.CONTENT_DIRECTORY );
 
806
                Set< String > datas_keys = datas.keySet();
 
807
 
824
808
                // add email addresses
825
 
                Set< String > datas_keys = datas.keySet();
826
809
                Iterator< String > i = datas_keys.iterator();
827
810
                while( i.hasNext() ) {
828
811
                        String email = i.next();
829
812
                        ContactData.PreferredDetail data = datas.get( email );
830
813
 
831
814
                        // we don't want to add this email address if it exists already or
832
 
                        // we would introduce duplicates
 
815
                        // we would introduce duplicates.
833
816
                        if( _contacts_cache.hasAssociatedEmail( id, email ) )
834
817
                                continue;
835
818
 
836
819
                        // add phone number
837
 
                        _backend.addContactEmail( id, email, data );
 
820
                        ContentValues values = new ContentValues();
 
821
                        values.put( Contacts.ContactMethods.KIND, Contacts.KIND_EMAIL );
 
822
                        values.put( Contacts.ContactMethods.DATA, email );
 
823
                        values.put( Contacts.ContactMethods.TYPE, data.getType() );
 
824
                        if( data.isPreferred() )
 
825
                                values.put( Contacts.ContactMethods.ISPRIMARY, 1 );
 
826
                        _doit.getContentResolver().insert( contact_contact_methods_uri,
 
827
                                values );
838
828
 
839
829
                        // and add this address to the cache to prevent a addition of
840
830
                        // duplicate date from another file
844
834
 
845
835
        private void importContactAddresses( Long id,
846
836
                HashMap< String, ContactData.TypeDetail > datas )
847
 
                throws ContactCreationException
848
837
        {
 
838
                // get URI to contact's contact methods
 
839
                Uri contact_contact_methods_uri = Uri.withAppendedPath(
 
840
                        ContentUris.withAppendedId( Contacts.People.CONTENT_URI, id ),
 
841
                        Contacts.People.ContactMethods.CONTENT_DIRECTORY );
 
842
 
849
843
                // add addresses
850
844
                Set< String > datas_keys = datas.keySet();
851
845
                Iterator< String > i = datas_keys.iterator();
859
853
                                continue;
860
854
 
861
855
                        // add postal address
862
 
                        _backend.addContactAddresses( id, address, data );
 
856
                        ContentValues values = new ContentValues();
 
857
                        values.put( Contacts.ContactMethods.KIND, Contacts.KIND_POSTAL );
 
858
                        values.put( Contacts.ContactMethods.DATA, address );
 
859
                        values.put( Contacts.ContactMethods.TYPE, data.getType() );
 
860
                        _doit.getContentResolver().insert( contact_contact_methods_uri,
 
861
                                values );
863
862
 
864
863
                        // and add this address to the cache to prevent a addition of
865
864
                        // duplicate date from another file
869
868
 
870
869
        private void importContactOrganisations( Long id,
871
870
                HashMap< String, ContactData.ExtraDetail > datas )
872
 
                throws ContactCreationException
873
871
        {
874
872
                // add addresses
875
873
                Set< String > datas_keys = datas.keySet();
884
882
                                continue;
885
883
 
886
884
                        // add organisation address
887
 
                        _backend.addContactOrganisation( id, organisation, data );
 
885
                        ContentValues values = new ContentValues();
 
886
                        values.put( Contacts.Organizations.PERSON_ID, id );
 
887
                        values.put( Contacts.Organizations.COMPANY, organisation );
 
888
                        values.put( Contacts.ContactMethods.TYPE,
 
889
                                Contacts.OrganizationColumns.TYPE_WORK );
 
890
                        if( data.getExtra() != null )
 
891
                                values.put( Contacts.Organizations.TITLE, data.getExtra() );
 
892
                        _doit.getContentResolver().insert(
 
893
                                Contacts.Organizations.CONTENT_URI, values );
888
894
 
889
895
                        // and add this address to the cache to prevent a addition of
890
896
                        // duplicate date from another file
892
898
                }
893
899
        }
894
900
 
895
 
        private void importContactNotes( Long id, HashSet< String > datas )
896
 
                throws ContactCreationException
897
 
        {
898
 
                // add notes
899
 
                Iterator< String > i = datas.iterator();
900
 
                while( i.hasNext() ) {
901
 
                        String note = i.next();
902
 
 
903
 
                        // we don't want to add this note if it exists already or we would
904
 
                        // introduce duplicates
905
 
                        if( _contacts_cache.hasAssociatedNote( id, note ) )
906
 
                                continue;
907
 
 
908
 
                        // add note
909
 
                        _backend.addContactNote( id, note );
910
 
 
911
 
                        // and add this note to the cache to prevent a addition of duplicate
912
 
                        // date from another file
913
 
                        _contacts_cache.addAssociatedNote( id, note );
914
 
                }
915
 
        }
916
 
 
917
 
        private void importContactBirthday( Long id, String birthday )
918
 
                throws ContactCreationException
919
 
        {
920
 
                // we don't want to import this birthday if it already exists
921
 
                if( _contacts_cache.hasAssociatedBirthday( id, birthday ) )
922
 
                        return;
923
 
 
924
 
                // add birthday
925
 
                _backend.addContactBirthday( id, birthday );
926
 
 
927
 
                // and update the cache
928
 
                _contacts_cache.addAssociatedBirthday( id, birthday );
929
 
        }
930
 
 
931
901
        synchronized protected void checkAbort() throws AbortImportException
932
902
        {
933
903
                if( _abort ) {