/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

1
1
/*
2
2
 * FileChooser.java
3
3
 *
4
 
 * Copyright (C) 2010 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2010 Tim Marston <edam@waxworlds.org>
5
5
 *
6
6
 * This file is part of the Import Contacts program (hereafter referred
7
 
 * to as "this program").  For more information, see
8
 
 * http://ed.am/dev/android/import-contacts
 
7
 * to as "this program"). For more information, see
 
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
21
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 */
23
23
 
24
 
package am.ed.importcontacts;
 
24
package org.waxworlds.edam.importcontacts;
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
29
import java.util.Collections;
31
30
import java.util.Comparator;
34
33
import android.app.Dialog;
35
34
import android.content.Context;
36
35
import android.content.DialogInterface;
37
 
import android.os.Environment;
38
36
import android.view.LayoutInflater;
39
37
import android.view.View;
40
38
import android.view.View.OnClickListener;
247
245
                }
248
246
        };
249
247
 
250
 
        private OnItemClickListener _fileChooserItemClickListener =
251
 
                        new OnItemClickListener() {
252
 
                public void onItemClick( AdapterView< ? > adapter_view, View view,
253
 
                        int position, long id )
 
248
        private OnItemClickListener _fileChooserItemClickListener = new OnItemClickListener() {
 
249
                public void onItemClick( AdapterView< ? > adapter_view, View view, int position, long id )
254
250
                {
255
251
                        RowItem rowitem = _items.get( position );
256
252
 
326
322
 
327
323
        public static int pathIcon( String path )
328
324
        {
329
 
                // get sdcard path
330
 
                String sdcard_path;
331
 
                try {
332
 
                        sdcard_path = Environment.getExternalStorageDirectory()
333
 
                                .getCanonicalPath();
334
 
                        if( sdcard_path.charAt( sdcard_path.length() - 1 ) != '/' )
335
 
                                sdcard_path += "/";
336
 
                }
337
 
                catch( IOException e ) {
338
 
                        sdcard_path = null;
339
 
                }
340
 
 
341
 
                // special paths
342
 
                if( sdcard_path != null && path.equals( sdcard_path ) )
 
325
                if( path.equals( "/sdcard/" ) )
343
326
                        return R.drawable.sdcard;
344
327
 
345
 
                // default
346
328
                return R.drawable.directory;
347
329
        }
348
330
 
350
332
        {
351
333
                String path = full_path;
352
334
 
353
 
                // get sdcard path
354
 
                String sdcard_path;
355
 
                try {
356
 
                        sdcard_path = Environment.getExternalStorageDirectory()
357
 
                                .getCanonicalPath();
358
 
                        if( sdcard_path.charAt( sdcard_path.length() - 1 ) != '/' )
359
 
                                sdcard_path += "/";
360
 
                }
361
 
                catch( IOException e ) {
362
 
                        sdcard_path = null;
363
 
                }
364
 
 
365
335
                // special names
366
 
                if( sdcard_path != null && path.equals( sdcard_path ) )
 
336
                if( path.equals( "/sdcard/" ) )
367
337
                        return " " + _context.getString( R.string.filechooser_path_sdcard );
368
338
 
369
339
                // remove prefix, if present
370
340
                if( path.startsWith( _path_prefix + "/" ) )
371
341
                        path = path.substring( _path_prefix.length() );
372
342
 
373
 
                // unless path is "/", strip trailing "/"
 
343
                // unless path is "/", strip trailing "/".
374
344
                if( path.length() > 1 && path.endsWith( "/" ) )
375
345
                        path = path.substring( 0, path.length() - 1 );
376
346
 
414
384
                        }
415
385
                }
416
386
                File[] files = dir.listFiles( new DirFilter() );
417
 
                if( files != null )
418
 
                        for( int i = 0; i < files.length; i++ )
419
 
                                _items.add( new RowItem( files[ i ].getName(), true ) );
 
387
                for( int i = 0; i < files.length; i++ )
 
388
                        _items.add( new RowItem( files[ i ].getName(), true ) );
420
389
 
421
390
                // get files
422
391
                if( _mode == MODE_FILE )
433
402
                                }
434
403
                        }
435
404
                        files = dir.listFiles( new VCardFilter() );
436
 
                        if( files != null )
437
 
                                for( int i = 0; i < files.length; i++ )
438
 
                                        _items.add( new RowItem( files[ i ].getName(), false ) );
 
405
                        for( int i = 0; i < files.length; i++ )
 
406
                                _items.add( new RowItem( files[ i ].getName(), false ) );
439
407
                }
440
408
 
441
409
                // sort