/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: edam
  • Date: 2012-12-21 15:53:30 UTC
  • Revision ID: tim@ed.am-20121221155330-j2zt31mh1b55mdty
added thank you message to intro

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * Exporter.java
3
3
 *
4
 
 * Copyright (C) 2011 to 2013 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2011 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;
155
154
 
156
155
                public void setName( String name )
157
156
                {
227
226
                        return _notes;
228
227
                }
229
228
 
230
 
                public void setBirthday( String birthday )
231
 
                {
232
 
                        _birthday = birthday;
233
 
                }
234
 
 
235
 
                public String getBirthday()
236
 
                {
237
 
                        return _birthday;
238
 
                }
239
 
 
240
229
                public String getPrimaryIdentifier()
241
230
                {
242
231
                        if( _name != null )
296
285
        protected void exportContacts() throws AbortExportException
297
286
        {
298
287
                // set up a contact reader
299
 
                Backend backend = null;
 
288
                Backend contact_reader = null;
300
289
                if( Integer.parseInt( android.os.Build.VERSION.SDK ) >= 5 )
301
 
                        backend = new ContactsContractBackend( _doit, this );
 
290
                        contact_reader = new ContactsContractBackend( _doit, this );
302
291
                else
303
 
                        backend = new ContactsBackend( _doit, this );
 
292
                        contact_reader = new ContactsBackend( _doit, this );
304
293
 
305
294
                // check we have contacts
306
 
                int num_contacts = backend.getNumContacts();
 
295
                int num_contacts = contact_reader.getNumContacts();
307
296
                if( num_contacts == 0 )
308
297
                        showError( R.string.error_nothingtodo );
309
298
 
319
308
                while( true ) {
320
309
                        checkAbort();
321
310
                        ContactData contact = new ContactData();
322
 
                        if( !backend.getNextContact( contact ) )
 
311
                        if( !contact_reader.getNextContact( contact ) )
323
312
                                break;
324
313
 
325
314
                        // export this one
382
371
                finish( ACTION_ABORT );
383
372
        }
384
373
 
385
 
        protected void showContinueOrAbort( int res ) throws AbortExportException
386
 
        {
387
 
                showContinueOrAbort( _doit.getText( res ).toString() );
388
 
        }
389
 
 
390
 
        synchronized protected void showContinueOrAbort( String message )
 
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 )
391
401
                        throws AbortExportException
392
402
        {
393
403
                checkAbort();
398
408
                }
399
409
                catch( InterruptedException e ) { }
400
410
 
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();
 
411
                // check if an abortion happened during the wait
 
412
                checkAbort();
 
413
 
 
414
                return _response == RESPONSE_POSITIVE;
407
415
        }
408
416
 
409
417
        protected void setProgressMessage( int res ) throws AbortExportException
419
427
                checkAbort();
420
428
                _doit._handler.sendMessage( Message.obtain(
421
429
                        _doit._handler, Doit.MESSAGE_SETMAXPROGRESS,
422
 
                        Integer.valueOf( max_progress ) ) );
 
430
                        new Integer( max_progress ) ) );
423
431
        }
424
432
 
425
433
        protected void setTmpProgress( int tmp_progress )
428
436
                checkAbort();
429
437
                _doit._handler.sendMessage( Message.obtain(
430
438
                        _doit._handler, Doit.MESSAGE_SETTMPPROGRESS,
431
 
                        Integer.valueOf( tmp_progress ) ) );
 
439
                        new Integer( tmp_progress ) ) );
432
440
        }
433
441
 
434
442
        protected void setProgress( int progress ) throws AbortExportException
436
444
                checkAbort();
437
445
                _doit._handler.sendMessage( Message.obtain(
438
446
                        _doit._handler, Doit.MESSAGE_SETPROGRESS,
439
 
                        Integer.valueOf( progress ) ) );
 
447
                        new Integer( progress ) ) );
440
448
        }
441
449
 
442
450
        protected void finish( int action ) throws AbortExportException