/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: 2010-07-04 15:14:46 UTC
  • Revision ID: edam@waxworlds.org-20100704151446-2yah1u00ml5m3wq9
- added facility to enter a filename (instead of a directory to scan) and just use that

Show diffs side-by-side

added added

removed removed

21
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 */
23
23
 
24
 
package org.waxworlds.importcontacts;
 
24
package org.waxworlds.edam.importcontacts;
25
25
 
26
26
import java.io.BufferedReader;
27
27
import java.io.File;
38
38
import java.util.regex.Matcher;
39
39
import java.util.regex.Pattern;
40
40
 
41
 
import org.waxworlds.importcontacts.Importer.AbortImportException;
42
 
 
43
41
import android.content.SharedPreferences;
44
42
import android.provider.Contacts;
45
43
import android.provider.Contacts.PhonesColumns;
69
67
                        // open directory
70
68
                        String location = prefs.getString( "location", "" );
71
69
                        File dir = new File( location );
72
 
                        if( !dir.exists() || !dir.isDirectory() )
 
70
                        if( !dir.exists() )
73
71
                                showError( R.string.error_locationnotfound );
74
72
 
75
 
                        // get files
76
 
                        class VCardFilter implements FilenameFilter {
77
 
                            public boolean accept( File dir, String name ) {
78
 
                                return name.toLowerCase().endsWith( ".vcf" );
79
 
                            }
80
 
                        }
81
 
                        files = dir.listFiles( new VCardFilter() );
 
73
                        // directory, or file?
 
74
                        if( dir.isDirectory() )
 
75
                        {
 
76
                                // get files
 
77
                                class VCardFilter implements FilenameFilter {
 
78
                                        public boolean accept( File dir, String name ) {
 
79
                                                return name.toLowerCase().endsWith( ".vcf" );
 
80
                                        }
 
81
                                }
 
82
                                files = dir.listFiles( new VCardFilter() );
 
83
                        }
 
84
                        else
 
85
                        {
 
86
                                // use just this file
 
87
                                files = new File[ 1 ];
 
88
                                files[ 0 ] = dir;
 
89
                        }
82
90
                }
83
91
                catch( SecurityException e ) {
84
92
                        showError( R.string.error_locationpermissions );
246
254
                private Vector< String > _lines = null;
247
255
                private int _nameLevel = NAMELEVEL_NONE;
248
256
 
 
257
                @SuppressWarnings("serial")
249
258
                protected class ParseException extends Exception
250
259
                {
 
260
                        @SuppressWarnings("unused")
251
261
                        public ParseException( String error )
252
262
                        {
253
263
                                super( error );
259
269
                        }
260
270
                }
261
271
 
 
272
                @SuppressWarnings("serial")
262
273
                protected class SkipContactException extends Exception { }
263
274
 
264
275
                public void parseLine( String line )