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