/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/FileChooser.java

  • Committer: edam
  • Date: 2010-10-30 09:55:31 UTC
  • Revision ID: edam@waxworlds.org-20101030095531-63vf9g84z5ol8qk9
- fixed bug in file chooser where "ok" button could remain disabled

Show diffs side-by-side

added added

removed removed

26
26
import java.io.File;
27
27
import java.io.FileFilter;
28
28
import java.util.ArrayList;
29
 
import java.util.Collections;
30
 
import java.util.Comparator;
31
29
 
32
30
import android.app.AlertDialog;
33
31
import android.app.Dialog;
79
77
        private DialogInterface.OnDismissListener _on_dismiss_listener;
80
78
 
81
79
        // class that represents a row in the list
82
 
        private class RowItem implements Comparable< RowItem >
 
80
        private class RowItem
83
81
        {
84
82
                private String _name;
85
83
                private boolean _directory;
99
97
                {
100
98
                        return _directory;
101
99
                }
102
 
 
103
 
                @Override
104
 
                public int compareTo( RowItem that )
105
 
                {
106
 
                        if( this._directory && !that._directory )
107
 
                                return -1;
108
 
                        else if( !this._directory && that._directory )
109
 
                                return 1;
110
 
                        else
111
 
                                return this._name.compareToIgnoreCase( that._name );
112
 
                }
113
100
        }
114
101
 
115
102
        // class to manage our list of RowItems
143
130
                }
144
131
        }
145
132
 
146
 
        @SuppressWarnings( "serial" )
147
133
        class InvalidPathPrefixException extends RuntimeException
148
134
        {
149
135
        }
193
179
        // set the path prefix
194
180
        public void setPathPrefix( String path_prefix )
195
181
        {
196
 
                // set to cleaned-up path, with trailing '/' removed so that it can be
 
182
                // set to cleaned-up path, with trailaing '/' removed so that it can be
197
183
                // trivially pre-pended to a cleaned-up path
198
184
                _path_prefix = cleanUpPath( path_prefix );
199
185
                _path_prefix = _path_prefix.substring( 0, _path_prefix.length() - 1 );
246
232
        };
247
233
 
248
234
        private OnItemClickListener _fileChooserItemClickListener = new OnItemClickListener() {
249
 
                public void onItemClick( AdapterView< ? > adapter_view, View view, int position, long id )
 
235
                public void onItemClick( AdapterView adapterView, View view, int position, long id )
250
236
                {
251
237
                        RowItem rowitem = _items.get( position );
252
238
 
384
370
                        }
385
371
                }
386
372
                File[] files = dir.listFiles( new DirFilter() );
387
 
                if( files != null )
388
 
                        for( int i = 0; i < files.length; i++ )
389
 
                                _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 ) );
390
375
 
391
376
                // get files
392
377
                if( _mode == MODE_FILE )
403
388
                                }
404
389
                        }
405
390
                        files = dir.listFiles( new VCardFilter() );
406
 
                        if( files != null )
407
 
                                for( int i = 0; i < files.length; i++ )
408
 
                                        _items.add( new RowItem( files[ i ].getName(), false ) );
409
 
                }
410
 
 
411
 
                // sort
412
 
                class RowItemSorter implements Comparator< RowItem > {
413
 
                        @Override
414
 
                        public int compare( RowItem lhs, RowItem rhs ) {
415
 
                                return lhs.compareTo( rhs );
416
 
                        }
417
 
                }
418
 
                Collections.sort( _items, new RowItemSorter() );
 
391
                        for( int i = 0; i < files.length; i++ )
 
392
                                _items.add( new RowItem( files[ i ].getName(), false ) );
 
393
                }
419
394
 
420
395
                // setup directory list
421
396
                ( (ListView)_dialog.findViewById( R.id.list ) ).setAdapter(