/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: Tim Marston
  • Date: 2016-03-28 18:18:11 UTC
  • Revision ID: tim@ed.am-20160328181811-as61lllmvnv8e5os
handle vcards with missing vesion lines (treat as v2.1)

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
 
 * to as "this program"). For more information, see
8
 
 * http://www.waxworlds.org/edam/software/android/import-contacts
 
7
 * to as "this program").  For more information, see
 
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;
 
32
import java.util.Locale;
31
33
 
32
34
import android.app.AlertDialog;
33
35
import android.app.Dialog;
34
36
import android.content.Context;
35
37
import android.content.DialogInterface;
 
38
import android.os.Environment;
36
39
import android.view.LayoutInflater;
37
40
import android.view.View;
38
41
import android.view.View.OnClickListener;
245
248
                }
246
249
        };
247
250
 
248
 
        private OnItemClickListener _fileChooserItemClickListener = new OnItemClickListener() {
249
 
                public void onItemClick( AdapterView< ? > adapter_view, View view, int position, long id )
 
251
        private OnItemClickListener _fileChooserItemClickListener =
 
252
                        new OnItemClickListener() {
 
253
                public void onItemClick( AdapterView< ? > adapter_view, View view,
 
254
                        int position, long id )
250
255
                {
251
256
                        RowItem rowitem = _items.get( position );
252
257
 
322
327
 
323
328
        public static int pathIcon( String path )
324
329
        {
325
 
                if( path.equals( "/sdcard/" ) )
 
330
                // get sdcard path
 
331
                String sdcard_path;
 
332
                try {
 
333
                        sdcard_path = Environment.getExternalStorageDirectory()
 
334
                                .getCanonicalPath();
 
335
                        if( sdcard_path.charAt( sdcard_path.length() - 1 ) != '/' )
 
336
                                sdcard_path += "/";
 
337
                }
 
338
                catch( IOException e ) {
 
339
                        sdcard_path = null;
 
340
                }
 
341
 
 
342
                // special paths
 
343
                if( sdcard_path != null && path.equals( sdcard_path ) )
326
344
                        return R.drawable.sdcard;
327
345
 
 
346
                // default
328
347
                return R.drawable.directory;
329
348
        }
330
349
 
332
351
        {
333
352
                String path = full_path;
334
353
 
 
354
                // get sdcard path
 
355
                String sdcard_path;
 
356
                try {
 
357
                        sdcard_path = Environment.getExternalStorageDirectory()
 
358
                                .getCanonicalPath();
 
359
                        if( sdcard_path.charAt( sdcard_path.length() - 1 ) != '/' )
 
360
                                sdcard_path += "/";
 
361
                }
 
362
                catch( IOException e ) {
 
363
                        sdcard_path = null;
 
364
                }
 
365
 
335
366
                // special names
336
 
                if( path.equals( "/sdcard/" ) )
 
367
                if( sdcard_path != null && path.equals( sdcard_path ) )
337
368
                        return " " + _context.getString( R.string.filechooser_path_sdcard );
338
369
 
339
370
                // remove prefix, if present
340
371
                if( path.startsWith( _path_prefix + "/" ) )
341
372
                        path = path.substring( _path_prefix.length() );
342
373
 
343
 
                // unless path is "/", strip trailing "/".
 
374
                // unless path is "/", strip trailing "/"
344
375
                if( path.length() > 1 && path.endsWith( "/" ) )
345
376
                        path = path.substring( 0, path.length() - 1 );
346
377
 
384
415
                        }
385
416
                }
386
417
                File[] files = dir.listFiles( new DirFilter() );
387
 
                for( int i = 0; i < files.length; i++ )
388
 
                        _items.add( new RowItem( files[ i ].getName(), true ) );
 
418
                if( files != null )
 
419
                        for( int i = 0; i < files.length; i++ )
 
420
                                _items.add( new RowItem( files[ i ].getName(), true ) );
389
421
 
390
422
                // get files
391
423
                if( _mode == MODE_FILE )
394
426
                                public boolean accept( File file ) {
395
427
                                        if( file.isDirectory() || file.getName().startsWith( "." ) )
396
428
                                                return false;
397
 
                                        String filename = file.getName().toLowerCase();
 
429
                                        String filename =
 
430
                                                file.getName().toLowerCase( Locale.ENGLISH );
398
431
                                        for( int i = 0; i < _extensions.length; i++ )
399
432
                                                if( filename.endsWith( "." + _extensions[ i ] ) )
400
433
                                                        return true;
402
435
                                }
403
436
                        }
404
437
                        files = dir.listFiles( new VCardFilter() );
405
 
                        for( int i = 0; i < files.length; i++ )
406
 
                                _items.add( new RowItem( files[ i ].getName(), false ) );
 
438
                        if( files != null )
 
439
                                for( int i = 0; i < files.length; i++ )
 
440
                                        _items.add( new RowItem( files[ i ].getName(), false ) );
407
441
                }
408
442
 
409
443
                // sort