/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/org/waxworlds/edam/importcontacts/VCFImporter.java

  • Committer: edam
  • Date: 2011-05-05 21:49:43 UTC
  • Revision ID: edam@waxworlds.org-20110505214943-bg0cn6qz0gr49dlk
- updated TODO
- made varibale names consistent (camelCaseVariables now_use_underscores)

Show diffs side-by-side

added added

removed removed

44
44
import java.util.regex.Matcher;
45
45
import java.util.regex.Pattern;
46
46
 
47
 
import org.waxworlds.edam.importcontacts.Importer.ContactData.ExtraDetail;
48
 
 
49
47
import android.content.SharedPreferences;
50
48
import android.provider.Contacts;
51
49
import android.provider.Contacts.PhonesColumns;
52
50
 
53
51
public class VCFImporter extends Importer
54
52
{
55
 
        private int _vCardCount = 0;
 
53
        private int _vcard_count = 0;
56
54
        private int _progress = 0;
57
55
 
58
56
        public VCFImporter( Doit doit )
112
110
                        countVCardFile( files[ i ] );
113
111
                        setTmpProgress( i );
114
112
                }
115
 
                setProgressMax( _vCardCount );  // will also update tmp progress
 
113
                setProgressMax( _vcard_count ); // will also update tmp progress
116
114
 
117
115
                // import them
118
116
                setProgress( 0 );
130
128
 
131
129
                        // read
132
130
                        String line;
133
 
                        boolean inVCard = false;
 
131
                        boolean in_vcard = false;
134
132
                        while( ( line = reader.readLine() ) != null )
135
133
                        {
136
 
                                if( !inVCard ) {
 
134
                                if( !in_vcard ) {
137
135
                                        // look for vcard beginning
138
136
                                        if( line.matches( "^BEGIN:VCARD" ) ) {
139
 
                                                inVCard = true;
140
 
                                                _vCardCount++;
 
137
                                                in_vcard = true;
 
138
                                                _vcard_count++;
141
139
                                        }
142
140
                                }
143
141
                                else if( line.matches( "^END:VCARD" ) )
144
 
                                        inVCard = false;
 
142
                                        in_vcard = false;
145
143
                        }
146
144
 
147
145
                }
187
185
                throws AbortImportException
188
186
        {
189
187
                // go through lines
190
 
                VCard vCard = null;
 
188
                VCard vcard = null;
191
189
                ContentLineIterator cli = new ContentLineIterator( content );
192
190
                while( cli.hasNext() )
193
191
                {
204
202
                                line = "";
205
203
                        }
206
204
 
207
 
                        if( vCard == null ) {
 
205
                        if( vcard == null ) {
208
206
                                // look for vcard beginning
209
207
                                if( line.matches( "^BEGIN:VCARD" ) ) {
210
208
                                        setProgress( ++_progress );
211
 
                                        vCard = new VCard();
 
209
                                        vcard = new VCard();
212
210
                                }
213
211
                        }
214
212
                        else {
217
215
                                {
218
216
                                        // store vcard and do away with it
219
217
                                        try {
220
 
                                                vCard.finaliseParsing();
221
 
                                                importContact( vCard );
 
218
                                                vcard.finaliseParsing();
 
219
                                                importContact( vcard );
222
220
                                        }
223
221
                                        catch( VCard.ParseException e ) {
224
222
                                                skipContact();
233
231
                                                skipContact();
234
232
                                                // do nothing
235
233
                                        }
236
 
                                        vCard = null;
 
234
                                        vcard = null;
237
235
                                }
238
236
                                else
239
237
                                {
240
238
                                        // try giving the line to the vcard
241
239
                                        try {
242
 
                                                vCard.parseLine( buffer, line,
 
240
                                                vcard.parseLine( buffer, line,
243
241
                                                        cli.doesNextLineLookFolded() );
244
242
                                        }
245
243
                                        catch( VCard.ParseException e ) {
254
252
                                                // although we're continuing, we still need to abort
255
253
                                                // this vCard. Further lines will be ignored until we
256
254
                                                // get to another BEGIN:VCARD line.
257
 
                                                vCard = null;
 
255
                                                vcard = null;
258
256
                                        }
259
257
                                        catch( VCard.SkipContactException e ) {
260
258
                                                skipContact();
261
259
                                                // abort this vCard. Further lines will be ignored until
262
260
                                                // we get to another BEGIN:VCARD line.
263
 
                                                vCard = null;
 
261
                                                vcard = null;
264
262
                                        }
265
263
                                }
266
264
                        }
773
771
                                "PAGER", "BBS", "MODEM", "CAR", "ISDN", "VIDEO" ) );
774
772
 
775
773
                        // here's the logic...
776
 
                        boolean preferred = types.contains( "PREF" );
 
774
                        boolean is_preferred = types.contains( "PREF" );
777
775
                        int type;
778
776
                        if( types.contains( "FAX" ) )
779
777
                                if( types.contains( "HOME" ) )
790
788
                                type = PhonesColumns.TYPE_HOME;
791
789
 
792
790
                        // add phone number
793
 
                        addNumber( value, type, preferred );
 
791
                        addNumber( value, type, is_preferred );
794
792
                }
795
793
 
796
794
                public void parseEMAIL( String[] params, String value )
801
799
                                "PREF", "WORK", "HOME", "INTERNET" ) );
802
800
 
803
801
                        // add email address
804
 
                        boolean preferred = types.contains( "PREF" );
 
802
                        boolean is_preferred = types.contains( "PREF" );
805
803
                        int type;
806
804
                        if( types.contains( "WORK" ) )
807
805
                                type = Contacts.ContactMethods.TYPE_WORK;
808
806
                        else
809
807
                                type = Contacts.ContactMethods.TYPE_HOME;
810
808
 
811
 
                        addEmail( value, type, preferred );
 
809
                        addEmail( value, type, is_preferred );
812
810
                }
813
811
 
814
812
                private void parseADR( String[] params, String value )