/android/export-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/export-contacts

« back to all changes in this revision

Viewing changes to src/org/waxworlds/edam/exportcontacts/FileChooser.java

  • Committer: edam
  • Date: 2011-06-11 08:22:04 UTC
  • Revision ID: edam@waxworlds.org-20110611082204-u2v1ri3a8iayq9b4
- added ContactReader interface
- added ContactsContactReader class to read old-style android.Contacts data
- updated FileChooser from import contacts app
- updated TODO
- added Doit activity
- added Exporter
- added VcardExporter that writes vCards

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import java.io.File;
27
27
import java.io.FileFilter;
 
28
import java.io.IOException;
28
29
import java.util.ArrayList;
 
30
import java.util.Collections;
 
31
import java.util.Comparator;
29
32
 
30
33
import android.app.AlertDialog;
31
34
import android.app.Dialog;
32
35
import android.content.Context;
33
36
import android.content.DialogInterface;
 
37
import android.os.Environment;
34
38
import android.view.LayoutInflater;
35
39
import android.view.View;
36
40
import android.view.View.OnClickListener;
77
81
        private DialogInterface.OnDismissListener _on_dismiss_listener;
78
82
 
79
83
        // class that represents a row in the list
80
 
        private class RowItem
 
84
        private class RowItem implements Comparable< RowItem >
81
85
        {
82
86
                private String _name;
83
87
                private boolean _directory;
97
101
                {
98
102
                        return _directory;
99
103
                }
 
104
 
 
105
                @Override
 
106
                public int compareTo( RowItem that )
 
107
                {
 
108
                        if( this._directory && !that._directory )
 
109
                                return -1;
 
110
                        else if( !this._directory && that._directory )
 
111
                                return 1;
 
112
                        else
 
113
                                return this._name.compareToIgnoreCase( that._name );
 
114
                }
100
115
        }
101
116
 
102
117
        // class to manage our list of RowItems
130
145
                }
131
146
        }
132
147
 
 
148
        @SuppressWarnings( "serial" )
133
149
        class InvalidPathPrefixException extends RuntimeException
134
150
        {
135
151
        }
232
248
        };
233
249
 
234
250
        private OnItemClickListener _fileChooserItemClickListener = new OnItemClickListener() {
235
 
                public void onItemClick( AdapterView adapterView, View view, int position, long id )
 
251
                public void onItemClick( AdapterView< ? > adapterView, View view, int position, long id )
236
252
                {
237
253
                        RowItem rowitem = _items.get( position );
238
254
 
308
324
 
309
325
        public static int pathIcon( String path )
310
326
        {
311
 
                if( path.equals( "/sdcard/" ) )
 
327
                // get sdcard path
 
328
                String sdcard_path;
 
329
                try {
 
330
                        sdcard_path = Environment.getExternalStorageDirectory()
 
331
                                .getCanonicalPath();
 
332
                        if( sdcard_path.charAt( sdcard_path.length() - 1 ) != '/' )
 
333
                                sdcard_path += "/";
 
334
                }
 
335
                catch( IOException e ) {
 
336
                        sdcard_path = null;
 
337
                }
 
338
 
 
339
                // special paths
 
340
                if( sdcard_path != null && path.equals( sdcard_path ) )
312
341
                        return R.drawable.sdcard;
313
342
 
 
343
                // default
314
344
                return R.drawable.directory;
315
345
        }
316
346
 
318
348
        {
319
349
                String path = full_path;
320
350
 
 
351
                // get sdcard path
 
352
                String sdcard_path;
 
353
                try {
 
354
                        sdcard_path = Environment.getExternalStorageDirectory()
 
355
                                .getCanonicalPath();
 
356
                        if( sdcard_path.charAt( sdcard_path.length() - 1 ) != '/' )
 
357
                                sdcard_path += "/";
 
358
                }
 
359
                catch( IOException e ) {
 
360
                        sdcard_path = null;
 
361
                }
 
362
 
321
363
                // special names
322
 
                if( path.equals( "/sdcard/" ) )
 
364
                if( sdcard_path != null && path.equals( sdcard_path ) )
323
365
                        return " " + _context.getString( R.string.filechooser_path_sdcard );
324
366
 
325
367
                // remove prefix, if present
370
412
                        }
371
413
                }
372
414
                File[] files = dir.listFiles( new DirFilter() );
373
 
                for( int i = 0; i < files.length; i++ )
374
 
                        _items.add( new RowItem( files[ i ].getName(), true ) );
 
415
                if( files != null )
 
416
                        for( int i = 0; i < files.length; i++ )
 
417
                                _items.add( new RowItem( files[ i ].getName(), true ) );
375
418
 
376
419
                // get files
377
420
                if( _mode == MODE_FILE )
388
431
                                }
389
432
                        }
390
433
                        files = dir.listFiles( new VCardFilter() );
391
 
                        for( int i = 0; i < files.length; i++ )
392
 
                                _items.add( new RowItem( files[ i ].getName(), false ) );
393
 
                }
 
434
                        if( files != null )
 
435
                                for( int i = 0; i < files.length; i++ )
 
436
                                        _items.add( new RowItem( files[ i ].getName(), false ) );
 
437
                }
 
438
 
 
439
                // sort
 
440
                class RowItemSorter implements Comparator< RowItem > {
 
441
                        @Override
 
442
                        public int compare( RowItem lhs, RowItem rhs ) {
 
443
                                return lhs.compareTo( rhs );
 
444
                        }
 
445
                }
 
446
                Collections.sort( _items, new RowItemSorter() );
394
447
 
395
448
                // setup directory list
396
449
                ( (ListView)_dialog.findViewById( R.id.list ) ).setAdapter(