/android/export-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/export-contacts

« back to all changes in this revision

Viewing changes to src/am/ed/exportcontacts/Exporter.java

  • Committer: Tim Marston
  • Date: 2014-03-02 11:03:07 UTC
  • Revision ID: tim@ed.am-20140302110307-nnrn9dhfnjg06lve
removed some unused code, fixed locale warnings and made showContinueOrAbort()
abort implicitly (rather than return false); added check for unidentifiable
contacts; fixed spelling mistake

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * Exporter.java
3
3
 *
4
 
 * Copyright (C) 2011 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2011 to 2013 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Export Contacts program (hereafter referred
7
 
 * to as "this program"). For more information, see
 
7
 * to as "this program").  For more information, see
8
8
 * http://ed.am/dev/android/export-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
151
151
                protected ArrayList< EmailDetail > _emails = null;
152
152
                protected ArrayList< AddressDetail > _addresses = null;
153
153
                protected ArrayList< String > _notes = null;
 
154
                protected String _birthday = null;
154
155
 
155
156
                public void setName( String name )
156
157
                {
226
227
                        return _notes;
227
228
                }
228
229
 
 
230
                public void setBirthday( String birthday )
 
231
                {
 
232
                        _birthday = birthday;
 
233
                }
 
234
 
 
235
                public String getBirthday()
 
236
                {
 
237
                        return _birthday;
 
238
                }
 
239
 
229
240
                public String getPrimaryIdentifier()
230
241
                {
231
242
                        if( _name != null )
285
296
        protected void exportContacts() throws AbortExportException
286
297
        {
287
298
                // set up a contact reader
288
 
                Backend contact_reader = null;
 
299
                Backend backend = null;
289
300
                if( Integer.parseInt( android.os.Build.VERSION.SDK ) >= 5 )
290
 
                        contact_reader = new ContactsContractBackend( _doit, this );
 
301
                        backend = new ContactsContractBackend( _doit, this );
291
302
                else
292
 
                        contact_reader = new ContactsBackend( _doit, this );
 
303
                        backend = new ContactsBackend( _doit, this );
293
304
 
294
305
                // check we have contacts
295
 
                int num_contacts = contact_reader.getNumContacts();
 
306
                int num_contacts = backend.getNumContacts();
296
307
                if( num_contacts == 0 )
297
308
                        showError( R.string.error_nothingtodo );
298
309
 
308
319
                while( true ) {
309
320
                        checkAbort();
310
321
                        ContactData contact = new ContactData();
311
 
                        if( !contact_reader.getNextContact( contact ) )
 
322
                        if( !backend.getNextContact( contact ) )
312
323
                                break;
313
324
 
314
325
                        // export this one
371
382
                finish( ACTION_ABORT );
372
383
        }
373
384
 
374
 
        protected void showFatalError( int res ) throws AbortExportException
375
 
        {
376
 
                showFatalError( _doit.getText( res ).toString() );
377
 
        }
378
 
 
379
 
        synchronized protected void showFatalError( String message )
380
 
                        throws AbortExportException
381
 
        {
382
 
                checkAbort();
383
 
                _doit._handler.sendMessage( Message.obtain(
384
 
                        _doit._handler, Doit.MESSAGE_ERROR, message ) );
385
 
                try {
386
 
                        wait();
387
 
                }
388
 
                catch( InterruptedException e ) { }
389
 
 
390
 
                // no need to check if an abortion happened during the wait, we are
391
 
                // about to finish anyway!
392
 
                finish( ACTION_ABORT );
393
 
        }
394
 
 
395
 
        protected boolean showContinue( int res ) throws AbortExportException
396
 
        {
397
 
                return showContinue( _doit.getText( res ).toString() );
398
 
        }
399
 
 
400
 
        synchronized protected boolean showContinue( String message )
 
385
        protected void showContinueOrAbort( int res ) throws AbortExportException
 
386
        {
 
387
                showContinueOrAbort( _doit.getText( res ).toString() );
 
388
        }
 
389
 
 
390
        synchronized protected void showContinueOrAbort( String message )
401
391
                        throws AbortExportException
402
392
        {
403
393
                checkAbort();
408
398
                }
409
399
                catch( InterruptedException e ) { }
410
400
 
411
 
                // check if an abortion happened during the wait
412
 
                checkAbort();
413
 
 
414
 
                return _response == RESPONSE_POSITIVE;
 
401
                // if we're aborting, there's no need to check if an abortion happened
 
402
                // during the wait
 
403
                if( _response == RESPONSE_NEGATIVE )
 
404
                        finish( ACTION_ABORT );
 
405
                else
 
406
                        checkAbort();
415
407
        }
416
408
 
417
409
        protected void setProgressMessage( int res ) throws AbortExportException
427
419
                checkAbort();
428
420
                _doit._handler.sendMessage( Message.obtain(
429
421
                        _doit._handler, Doit.MESSAGE_SETMAXPROGRESS,
430
 
                        new Integer( max_progress ) ) );
 
422
                        Integer.valueOf( max_progress ) ) );
431
423
        }
432
424
 
433
425
        protected void setTmpProgress( int tmp_progress )
436
428
                checkAbort();
437
429
                _doit._handler.sendMessage( Message.obtain(
438
430
                        _doit._handler, Doit.MESSAGE_SETTMPPROGRESS,
439
 
                        new Integer( tmp_progress ) ) );
 
431
                        Integer.valueOf( tmp_progress ) ) );
440
432
        }
441
433
 
442
434
        protected void setProgress( int progress ) throws AbortExportException
444
436
                checkAbort();
445
437
                _doit._handler.sendMessage( Message.obtain(
446
438
                        _doit._handler, Doit.MESSAGE_SETPROGRESS,
447
 
                        new Integer( progress ) ) );
 
439
                        Integer.valueOf( progress ) ) );
448
440
        }
449
441
 
450
442
        protected void finish( int action ) throws AbortExportException