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

  • Committer: edam
  • Date: 2012-04-24 09:56:17 UTC
  • Revision ID: tim@ed.am-20120424095617-lsfkkpkrlqk9xthn
updated all URLs, email addresses and package names to ed.am

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * FileChooser.java
3
3
 *
4
 
 * Copyright (C) 2010 Tim Marston <edam@waxworlds.org>
 
4
 * Copyright (C) 2010 Tim Marston <tim@ed.am>
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/import-contacts
 
8
 * http://ed.am/dev/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 org.waxworlds.edam.importcontacts;
 
24
package am.ed.importcontacts;
25
25
 
26
26
import java.io.File;
27
27
import java.io.FileFilter;
 
28
import java.io.IOException;
28
29
import java.util.ArrayList;
29
30
import java.util.Collections;
30
31
import java.util.Comparator;
33
34
import android.app.Dialog;
34
35
import android.content.Context;
35
36
import android.content.DialogInterface;
 
37
import android.os.Environment;
36
38
import android.view.LayoutInflater;
37
39
import android.view.View;
38
40
import android.view.View.OnClickListener;
322
324
 
323
325
        public static int pathIcon( String path )
324
326
        {
325
 
                if( path.equals( "/sdcard/" ) )
 
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 ) )
326
341
                        return R.drawable.sdcard;
327
342
 
 
343
                // default
328
344
                return R.drawable.directory;
329
345
        }
330
346
 
332
348
        {
333
349
                String path = full_path;
334
350
 
 
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
 
335
363
                // special names
336
 
                if( path.equals( "/sdcard/" ) )
 
364
                if( sdcard_path != null && path.equals( sdcard_path ) )
337
365
                        return " " + _context.getString( R.string.filechooser_path_sdcard );
338
366
 
339
367
                // remove prefix, if present
384
412
                        }
385
413
                }
386
414
                File[] files = dir.listFiles( new DirFilter() );
387
 
                for( int i = 0; i < files.length; i++ )
388
 
                        _items.add( new RowItem( files[ i ].getName(), true ) );
 
415
                if( files != null )
 
416
                        for( int i = 0; i < files.length; i++ )
 
417
                                _items.add( new RowItem( files[ i ].getName(), true ) );
389
418
 
390
419
                // get files
391
420
                if( _mode == MODE_FILE )
402
431
                                }
403
432
                        }
404
433
                        files = dir.listFiles( new VCardFilter() );
405
 
                        for( int i = 0; i < files.length; i++ )
406
 
                                _items.add( new RowItem( files[ i ].getName(), false ) );
 
434
                        if( files != null )
 
435
                                for( int i = 0; i < files.length; i++ )
 
436
                                        _items.add( new RowItem( files[ i ].getName(), false ) );
407
437
                }
408
438
 
409
439
                // sort