/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:50:33 UTC
  • Revision ID: tim@ed.am-20121219175033-61acsxzjulqpnian
made contacts backend throw exceptions when it can't create contacts on the device; specified Locale in lower/upper case conversions; stripped old Contacts types from Importer (and replaced with our own types, which are now converted in the backend; switched using Integer() constructors to Integer.valueOf(); rewrote the main importer routine a bit

Show diffs side-by-side

added added

removed removed

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