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

  • Committer: edam
  • Date: 2012-12-19 17:41:04 UTC
  • Revision ID: tim@ed.am-20121219174104-ly9xyjxdhqt0tu9b
ignore temporary files in eclipse project

Show diffs side-by-side

added added

removed removed

38
38
import java.util.HashSet;
39
39
import java.util.Iterator;
40
40
import java.util.List;
41
 
import java.util.Locale;
42
41
import java.util.NoSuchElementException;
43
42
import java.util.Set;
44
43
import java.util.Vector;
45
44
import java.util.regex.Matcher;
46
45
import java.util.regex.Pattern;
47
46
 
48
 
import android.annotation.SuppressLint;
49
47
import android.content.SharedPreferences;
 
48
import android.provider.Contacts;
 
49
import android.provider.Contacts.PhonesColumns;
50
50
 
51
51
public class VcardImporter extends Importer
52
52
{
58
58
                super( doit );
59
59
        }
60
60
 
61
 
        @SuppressLint( "SdCardPath" )
62
61
        @Override
63
62
        protected void onImport() throws AbortImportException
64
63
        {
83
82
                                // get files
84
83
                                class VCardFilter implements FilenameFilter {
85
84
                                        public boolean accept( File dir, String name ) {
86
 
                                                return name.toLowerCase( Locale.US ).endsWith( ".vcf" );
 
85
                                                return name.toLowerCase().endsWith( ".vcf" );
87
86
                                        }
88
87
                                }
89
88
                                files = file.listFiles( new VCardFilter() );
577
576
 
578
577
                                // parse encoding parameter
579
578
                                String encoding = checkParam( name_param_parts, "ENCODING" );
580
 
                                if( encoding != null )
581
 
                                        encoding = encoding.toUpperCase( Locale.US );
 
579
                                if( encoding != null ) encoding = encoding.toUpperCase();
582
580
                                if( is_interesting_field && encoding != null &&
583
581
                                        !encoding.equals( "8BIT" ) &&
584
582
                                        !encoding.equals( "QUOTED-PRINTABLE" ) )
589
587
 
590
588
                                // parse charset parameter
591
589
                                String charset = checkParam( name_param_parts, "CHARSET" );
592
 
                                if( charset != null )
593
 
                                        charset = charset.toUpperCase( Locale.US );
 
590
                                if( charset != null ) charset = charset.toUpperCase();
594
591
                                if( charset != null &&
595
592
                                        !charset.equals( "US-ASCII" ) &&
596
593
                                        !charset.equals( "ASCII" ) &&
882
879
                        int type;
883
880
                        if( types.contains( "FAX" ) )
884
881
                                if( types.contains( "HOME" ) )
885
 
                                        type = TYPE_FAX_HOME;
 
882
                                        type = PhonesColumns.TYPE_FAX_HOME;
886
883
                                else
887
 
                                        type = TYPE_FAX_WORK;
 
884
                                        type = PhonesColumns.TYPE_FAX_WORK;
888
885
                        else if( types.contains( "CELL" ) || types.contains( "VIDEO" ) )
889
 
                                type = TYPE_MOBILE;
 
886
                                type = PhonesColumns.TYPE_MOBILE;
890
887
                        else if( types.contains( "PAGER" ) )
891
 
                                type = TYPE_PAGER;
 
888
                                type = PhonesColumns.TYPE_PAGER;
892
889
                        else if( types.contains( "WORK" ) )
893
 
                                type = TYPE_WORK;
 
890
                                type = PhonesColumns.TYPE_WORK;
894
891
                        else
895
 
                                type = TYPE_HOME;
 
892
                                type = PhonesColumns.TYPE_HOME;
896
893
 
897
894
                        // add phone number
898
895
                        addNumber( value, type, is_preferred );
909
906
                        boolean is_preferred = types.contains( "PREF" );
910
907
                        int type;
911
908
                        if( types.contains( "WORK" ) )
912
 
                                type = TYPE_WORK;
 
909
                                type = Contacts.ContactMethods.TYPE_WORK;
913
910
                        else
914
 
                                type = TYPE_HOME;
 
911
                                type = Contacts.ContactMethods.TYPE_HOME;
915
912
 
916
913
                        addEmail( unescapeValue( value ), type, is_preferred );
917
914
                }
943
940
                        // add address
944
941
                        int type;
945
942
                        if( types.contains( "WORK" ) )
946
 
                                type = TYPE_WORK;
 
943
                                type = Contacts.ContactMethods.TYPE_WORK;
947
944
                        else
948
 
                                type = TYPE_HOME;
 
945
                                type = Contacts.ContactMethods.TYPE_HOME;
949
946
 
950
947
                        addAddress( unescapeValue( value ), type );
951
948
                }
958
955
                        // add address
959
956
                        int type;
960
957
                        if( types.contains( "WORK" ) )
961
 
                                type = TYPE_WORK;
 
958
                                type = Contacts.ContactMethods.TYPE_WORK;
962
959
                        else
963
 
                                type = TYPE_HOME;
 
960
                                type = Contacts.ContactMethods.TYPE_HOME;
964
961
 
965
962
                        addAddress( unescapeValue( value ), type );
966
963
                }