/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:04:33 UTC
  • Revision ID: tim@ed.am-20140302110433-9crgerrfbh30bs39
bump version to 1.0.3

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
50
50
         */
51
51
        public class ContactData
52
52
        {
 
53
                public final static int TYPE_HOME = 0;
 
54
                public final static int TYPE_WORK = 1;
 
55
                public final static int TYPE_MOBILE = 2;        // only used with phones
 
56
                public final static int TYPE_FAX_HOME = 3;      // only used with phones
 
57
                public final static int TYPE_FAX_WORK = 4;      // only used with phones
 
58
                public final static int TYPE_PAGER = 5;         // only used with phones
 
59
 
53
60
                class OrganisationDetail
54
61
                {
55
62
                        protected String _org;
143
150
                protected ArrayList< NumberDetail > _numbers = null;
144
151
                protected ArrayList< EmailDetail > _emails = null;
145
152
                protected ArrayList< AddressDetail > _addresses = null;
 
153
                protected ArrayList< String > _notes = null;
 
154
                protected String _birthday = null;
146
155
 
147
156
                public void setName( String name )
148
157
                {
206
215
                        return _addresses;
207
216
                }
208
217
 
 
218
                public void addNote( String note )
 
219
                {
 
220
                        if( _notes == null )
 
221
                                _notes = new ArrayList< String >();
 
222
                        _notes.add( note );
 
223
                }
 
224
 
 
225
                public ArrayList< String > getNotes()
 
226
                {
 
227
                        return _notes;
 
228
                }
 
229
 
 
230
                public void setBirthday( String birthday )
 
231
                {
 
232
                        _birthday = birthday;
 
233
                }
 
234
 
 
235
                public String getBirthday()
 
236
                {
 
237
                        return _birthday;
 
238
                }
 
239
 
209
240
                public String getPrimaryIdentifier()
210
241
                {
211
242
                        if( _name != null )
265
296
        protected void exportContacts() throws AbortExportException
266
297
        {
267
298
                // set up a contact reader
268
 
                ContactAccessor contact_reader =
269
 
                        new ContactsContactAccessor( _doit, this );
270
 
                int num_contacts = contact_reader.getNumContacts();
 
299
                Backend backend = null;
 
300
                if( Integer.parseInt( android.os.Build.VERSION.SDK ) >= 5 )
 
301
                        backend = new ContactsContractBackend( _doit, this );
 
302
                else
 
303
                        backend = new ContactsBackend( _doit, this );
 
304
 
 
305
                // check we have contacts
 
306
                int num_contacts = backend.getNumContacts();
271
307
                if( num_contacts == 0 )
272
308
                        showError( R.string.error_nothingtodo );
273
309
 
283
319
                while( true ) {
284
320
                        checkAbort();
285
321
                        ContactData contact = new ContactData();
286
 
                        if( !contact_reader.getNextContact( contact ) )
 
322
                        if( !backend.getNextContact( contact ) )
287
323
                                break;
288
324
 
289
325
                        // export this one
346
382
                finish( ACTION_ABORT );
347
383
        }
348
384
 
349
 
        protected void showFatalError( int res ) throws AbortExportException
350
 
        {
351
 
                showFatalError( _doit.getText( res ).toString() );
352
 
        }
353
 
 
354
 
        synchronized protected void showFatalError( String message )
355
 
                        throws AbortExportException
356
 
        {
357
 
                checkAbort();
358
 
                _doit._handler.sendMessage( Message.obtain(
359
 
                        _doit._handler, Doit.MESSAGE_ERROR, message ) );
360
 
                try {
361
 
                        wait();
362
 
                }
363
 
                catch( InterruptedException e ) { }
364
 
 
365
 
                // no need to check if an abortion happened during the wait, we are
366
 
                // about to finish anyway!
367
 
                finish( ACTION_ABORT );
368
 
        }
369
 
 
370
 
        protected boolean showContinue( int res ) throws AbortExportException
371
 
        {
372
 
                return showContinue( _doit.getText( res ).toString() );
373
 
        }
374
 
 
375
 
        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 )
376
391
                        throws AbortExportException
377
392
        {
378
393
                checkAbort();
383
398
                }
384
399
                catch( InterruptedException e ) { }
385
400
 
386
 
                // check if an abortion happened during the wait
387
 
                checkAbort();
388
 
 
389
 
                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();
390
407
        }
391
408
 
392
409
        protected void setProgressMessage( int res ) throws AbortExportException
402
419
                checkAbort();
403
420
                _doit._handler.sendMessage( Message.obtain(
404
421
                        _doit._handler, Doit.MESSAGE_SETMAXPROGRESS,
405
 
                        new Integer( max_progress ) ) );
 
422
                        Integer.valueOf( max_progress ) ) );
406
423
        }
407
424
 
408
425
        protected void setTmpProgress( int tmp_progress )
411
428
                checkAbort();
412
429
                _doit._handler.sendMessage( Message.obtain(
413
430
                        _doit._handler, Doit.MESSAGE_SETTMPPROGRESS,
414
 
                        new Integer( tmp_progress ) ) );
 
431
                        Integer.valueOf( tmp_progress ) ) );
415
432
        }
416
433
 
417
434
        protected void setProgress( int progress ) throws AbortExportException
419
436
                checkAbort();
420
437
                _doit._handler.sendMessage( Message.obtain(
421
438
                        _doit._handler, Doit.MESSAGE_SETPROGRESS,
422
 
                        new Integer( progress ) ) );
 
439
                        Integer.valueOf( progress ) ) );
423
440
        }
424
441
 
425
442
        protected void finish( int action ) throws AbortExportException