/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: 2010-10-30 09:56:26 UTC
  • Revision ID: edam@waxworlds.org-20101030095626-cavsscp5jukannwl
- fixed bug in file chooser where "ok" button could remain disabled

Show diffs side-by-side

added added

removed removed

25
25
 
26
26
import java.io.File;
27
27
import java.io.FileFilter;
28
 
import java.io.IOException;
29
28
import java.util.ArrayList;
30
 
import java.util.Collections;
31
 
import java.util.Comparator;
32
29
 
33
30
import android.app.AlertDialog;
34
31
import android.app.Dialog;
35
32
import android.content.Context;
36
33
import android.content.DialogInterface;
37
 
import android.os.Environment;
38
34
import android.view.LayoutInflater;
39
35
import android.view.View;
40
36
import android.view.View.OnClickListener;
81
77
        private DialogInterface.OnDismissListener _on_dismiss_listener;
82
78
 
83
79
        // class that represents a row in the list
84
 
        private class RowItem implements Comparable< RowItem >
 
80
        private class RowItem
85
81
        {
86
82
                private String _name;
87
83
                private boolean _directory;
101
97
                {
102
98
                        return _directory;
103
99
                }
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
 
                }
115
100
        }
116
101
 
117
102
        // class to manage our list of RowItems
145
130
                }
146
131
        }
147
132
 
148
 
        @SuppressWarnings( "serial" )
149
133
        class InvalidPathPrefixException extends RuntimeException
150
134
        {
151
135
        }
248
232
        };
249
233
 
250
234
        private OnItemClickListener _fileChooserItemClickListener = new OnItemClickListener() {
251
 
                public void onItemClick( AdapterView< ? > adapterView, View view, int position, long id )
 
235
                public void onItemClick( AdapterView adapterView, View view, int position, long id )
252
236
                {
253
237
                        RowItem rowitem = _items.get( position );
254
238
 
324
308
 
325
309
        public static int pathIcon( String path )
326
310
        {
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 ) )
 
311
                if( path.equals( "/sdcard/" ) )
341
312
                        return R.drawable.sdcard;
342
313
 
343
 
                // default
344
314
                return R.drawable.directory;
345
315
        }
346
316
 
348
318
        {
349
319
                String path = full_path;
350
320
 
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
 
 
363
321
                // special names
364
 
                if( sdcard_path != null && path.equals( sdcard_path ) )
 
322
                if( path.equals( "/sdcard/" ) )
365
323
                        return " " + _context.getString( R.string.filechooser_path_sdcard );
366
324
 
367
325
                // remove prefix, if present
412
370
                        }
413
371
                }
414
372
                File[] files = dir.listFiles( new DirFilter() );
415
 
                if( files != null )
416
 
                        for( int i = 0; i < files.length; i++ )
417
 
                                _items.add( new RowItem( files[ i ].getName(), true ) );
 
373
                for( int i = 0; i < files.length; i++ )
 
374
                        _items.add( new RowItem( files[ i ].getName(), true ) );
418
375
 
419
376
                // get files
420
377
                if( _mode == MODE_FILE )
431
388
                                }
432
389
                        }
433
390
                        files = dir.listFiles( new VCardFilter() );
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() );
 
391
                        for( int i = 0; i < files.length; i++ )
 
392
                                _items.add( new RowItem( files[ i ].getName(), false ) );
 
393
                }
447
394
 
448
395
                // setup directory list
449
396
                ( (ListView)_dialog.findViewById( R.id.list ) ).setAdapter(