/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

5
5
 *
6
6
 * This file is part of the Import Contacts program (hereafter referred
7
7
 * to as "this program"). For more information, see
8
 
 * http://www.waxworlds.org/edam/software/android/export-contacts
 
8
 * http://www.waxworlds.org/edam/software/android/import-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
11
11
 * it under the terms of the GNU General Public License as published by
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
        }
137
151
 
138
152
 
139
153
        // constructor
140
 
        public FileChooser()
 
154
        public FileChooser( Context context )
141
155
        {
 
156
                _context = context;
142
157
        }
143
158
 
144
159
        public void setMode( int mode )
178
193
        // set the path prefix
179
194
        public void setPathPrefix( String path_prefix )
180
195
        {
181
 
                // 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
182
197
                // trivially pre-pended to a cleaned-up path
183
198
                _path_prefix = cleanUpPath( path_prefix );
184
199
                _path_prefix = _path_prefix.substring( 0, _path_prefix.length() - 1 );
194
209
                return _path + _filename;
195
210
        }
196
211
 
197
 
        public Dialog onCreateDialog( Context context )
 
212
        public Dialog onCreateDialog()
198
213
        {
199
 
                _context = context;
200
 
 
201
214
                // custom layout in an AlertDialog
202
 
                LayoutInflater factory = LayoutInflater.from( context );
 
215
                LayoutInflater factory = LayoutInflater.from( _context );
203
216
                final View dialogView = factory.inflate(
204
217
                        R.layout.filechooser, null );
205
218
 
210
223
                        .setOnItemClickListener( _fileChooserItemClickListener );
211
224
 
212
225
                // return dialog
213
 
                Dialog dialog = new AlertDialog.Builder( context )
 
226
                Dialog dialog = new AlertDialog.Builder( _context )
214
227
                        .setTitle( " " )
215
228
                        .setView( dialogView )
216
229
                        .create();
233
246
        };
234
247
 
235
248
        private OnItemClickListener _fileChooserItemClickListener = new OnItemClickListener() {
236
 
                public void onItemClick( AdapterView adapterView, View view, int position, long id )
 
249
                public void onItemClick( AdapterView< ? > adapter_view, View view, int position, long id )
237
250
                {
238
251
                        RowItem rowitem = _items.get( position );
239
252
 
393
406
                                _items.add( new RowItem( files[ i ].getName(), false ) );
394
407
                }
395
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
 
396
418
                // setup directory list
397
419
                ( (ListView)_dialog.findViewById( R.id.list ) ).setAdapter(
398
420
                        new RowItemAdapter( _context, R.layout.filechooser_row,
410
432
                // enable/disable ok button
411
433
                if( _mode == MODE_FILE )
412
434
                        _dialog.findViewById( R.id.ok ).setEnabled( _filename != "" );
 
435
                else
 
436
                        _dialog.findViewById( R.id.ok ).setEnabled( true );
413
437
        }
414
438
 
415
439
}