628
private void buildContactsCache() throws AbortImportException
631
setProgressMessage( R.string.doit_caching );
636
// init contacts caches
637
_contacts = new HashMap< String, Long >();
638
_contactNumbers = new HashMap< Long, HashSet< String > >();
639
_contactEmails = new HashMap< Long, HashSet< String > >();
640
_contactAddresses = new HashMap< Long, HashSet< String > >();
642
// query and store map of contact names to ids
643
cols = new String[] { Contacts.People._ID, Contacts.People.NAME };
644
cur = _doit.managedQuery( Contacts.People.CONTENT_URI,
645
cols, null, null, null);
646
if( cur.moveToFirst() ) {
647
int idCol = cur.getColumnIndex( Contacts.People._ID );
648
int nameCol = cur.getColumnIndex( Contacts.People.NAME );
650
_contacts.put( cur.getString( nameCol ), cur.getLong( idCol ) );
651
} while( cur.moveToNext() );
654
// query and store map of contact ids to sets of phone numbers
655
cols = new String[] { Contacts.Phones.PERSON_ID,
656
Contacts.Phones.NUMBER };
657
cur = _doit.managedQuery( Contacts.Phones.CONTENT_URI,
658
cols, null, null, null);
659
if( cur.moveToFirst() ) {
660
int personIdCol = cur.getColumnIndex( Contacts.Phones.PERSON_ID );
661
int numberCol = cur.getColumnIndex( Contacts.Phones.NUMBER );
663
Long id = cur.getLong( personIdCol );
664
String number = sanitisePhoneNumber(
665
cur.getString( numberCol ) );
666
if( number != null ) {
667
HashSet< String > numbers = _contactNumbers.get( id );
668
if( numbers == null ) {
669
numbers = new HashSet< String >();
670
_contactNumbers.put( id, numbers );
672
numbers.add( number );
674
} while( cur.moveToNext() );
677
// query and store map of contact ids to sets of email addresses
678
cols = new String[] { Contacts.ContactMethods.PERSON_ID,
679
Contacts.ContactMethods.DATA };
680
cur = _doit.managedQuery( Contacts.ContactMethods.CONTENT_URI,
681
cols, Contacts.ContactMethods.KIND + " = ?",
682
new String[] { "" + Contacts.KIND_EMAIL }, null );
683
if( cur.moveToFirst() ) {
684
int personIdCol = cur.getColumnIndex(
685
Contacts.ContactMethods.PERSON_ID );
686
int addressCol = cur.getColumnIndex(
687
Contacts.ContactMethods.DATA );
689
Long id = cur.getLong( personIdCol );
690
String address = sanitiseEmailAddress(
691
cur.getString( addressCol ) );
692
if( address != null ) {
693
HashSet< String > addresses = _contactEmails.get( id );
694
if( addresses == null ) {
695
addresses = new HashSet< String >();
696
_contactEmails.put( id, addresses );
698
addresses.add( address );
700
} while( cur.moveToNext() );
703
// query and store map of contact ids to sets of postal addresses
704
cols = new String[] { Contacts.ContactMethods.PERSON_ID,
705
Contacts.ContactMethods.DATA };
706
cur = _doit.managedQuery( Contacts.ContactMethods.CONTENT_URI,
707
cols, Contacts.ContactMethods.KIND + " = ?",
708
new String[] { "" + Contacts.KIND_POSTAL }, null );
709
if( cur.moveToFirst() ) {
710
int personIdCol = cur.getColumnIndex(
711
Contacts.ContactMethods.PERSON_ID );
712
int addressCol = cur.getColumnIndex(
713
Contacts.ContactMethods.DATA );
715
Long id = cur.getLong( personIdCol );
716
String address = cur.getString( addressCol );
717
if( address != null ) {
718
HashSet< String > addresses = _contactAddresses.get( id );
719
if( addresses == null ) {
720
addresses = new HashSet< String >();
721
_contactAddresses.put( id, addresses );
723
addresses.add( address );
725
} while( cur.moveToNext() );
729
private String sanitisePhoneNumber( String number )
612
static public String sanitisePhoneNumber( String number )
731
614
number = number.replaceAll( "[-\\(\\) ]", "" );
732
615
Pattern p = Pattern.compile( "^[\\+0-9#*]+" );