/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-12-14 15:55:43 UTC
  • Revision ID: edam@waxworlds.org-20101214155543-2ds0oqqj3zj9ejci
- take over orientation and keyboard hiden/shown config changes, to prevent our activities being restarted
- sort dirs/files alphabetically in filechooser

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;
29
31
 
30
32
import android.app.AlertDialog;
31
33
import android.app.Dialog;
77
79
        private DialogInterface.OnDismissListener _on_dismiss_listener;
78
80
 
79
81
        // class that represents a row in the list
80
 
        private class RowItem
 
82
        private class RowItem implements Comparable< RowItem >
81
83
        {
82
84
                private String _name;
83
85
                private boolean _directory;
97
99
                {
98
100
                        return _directory;
99
101
                }
 
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
                }
100
113
        }
101
114
 
102
115
        // class to manage our list of RowItems
130
143
                }
131
144
        }
132
145
 
 
146
        @SuppressWarnings( "serial" )
133
147
        class InvalidPathPrefixException extends RuntimeException
134
148
        {
135
149
        }
179
193
        // set the path prefix
180
194
        public void setPathPrefix( String path_prefix )
181
195
        {
182
 
                // set to cleaned-up path, with trailaing '/' removed so that it can be
 
196
                // set to cleaned-up path, with trailing '/' removed so that it can be
183
197
                // trivially pre-pended to a cleaned-up path
184
198
                _path_prefix = cleanUpPath( path_prefix );
185
199
                _path_prefix = _path_prefix.substring( 0, _path_prefix.length() - 1 );
232
246
        };
233
247
 
234
248
        private OnItemClickListener _fileChooserItemClickListener = new OnItemClickListener() {
235
 
                public void onItemClick( AdapterView adapterView, View view, int position, long id )
 
249
                public void onItemClick( AdapterView< ? > adapter_view, View view, int position, long id )
236
250
                {
237
251
                        RowItem rowitem = _items.get( position );
238
252
 
392
406
                                _items.add( new RowItem( files[ i ].getName(), false ) );
393
407
                }
394
408
 
 
409
                // sort
 
410
                class RowItemSorter implements Comparator< RowItem > {
 
411
                        @Override
 
412
                        public int compare( RowItem lhs, RowItem rhs ) {
 
413
                                return lhs.compareTo( rhs );
 
414
                        }
 
415
                }
 
416
                Collections.sort( _items, new RowItemSorter() );
 
417
 
395
418
                // setup directory list
396
419
                ( (ListView)_dialog.findViewById( R.id.list ) ).setAdapter(
397
420
                        new RowItemAdapter( _context, R.layout.filechooser_row,