/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/org/waxworlds/edam/exportcontacts/Exporter.java

  • Committer: edam
  • Date: 2011-06-11 12:18:58 UTC
  • Revision ID: edam@waxworlds.org-20110611121858-qsnx7bgi583m6qe8
- changed "written" to "exported"

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 <edam@waxworlds.org>
5
5
 *
6
6
 * This file is part of the Export Contacts program (hereafter referred
7
 
 * to as "this program").  For more information, see
8
 
 * http://ed.am/dev/android/export-contacts
 
7
 * to as "this program"). For more information, see
 
8
 * http://www.waxworlds.org/edam/software/android/export-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.exportcontacts;
 
24
package org.waxworlds.edam.exportcontacts;
25
25
 
26
26
import java.util.ArrayList;
27
27
 
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
 
 
60
53
                class OrganisationDetail
61
54
                {
62
55
                        protected String _org;
150
143
                protected ArrayList< NumberDetail > _numbers = null;
151
144
                protected ArrayList< EmailDetail > _emails = null;
152
145
                protected ArrayList< AddressDetail > _addresses = null;
153
 
                protected ArrayList< String > _notes = null;
154
 
                protected String _birthday = null;
155
146
 
156
147
                public void setName( String name )
157
148
                {
215
206
                        return _addresses;
216
207
                }
217
208
 
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
 
 
240
209
                public String getPrimaryIdentifier()
241
210
                {
242
211
                        if( _name != null )
296
265
        protected void exportContacts() throws AbortExportException
297
266
        {
298
267
                // set up a contact reader
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();
 
268
                ContactReader contact_reader = new ContactsContactReader( _doit, this );
 
269
                int num_contacts = contact_reader.getNumContacts();
307
270
                if( num_contacts == 0 )
308
271
                        showError( R.string.error_nothingtodo );
309
272
 
319
282
                while( true ) {
320
283
                        checkAbort();
321
284
                        ContactData contact = new ContactData();
322
 
                        if( !backend.getNextContact( contact ) )
 
285
                        if( !contact_reader.getNextContact( contact ) )
323
286
                                break;
324
287
 
325
288
                        // export this one
382
345
                finish( ACTION_ABORT );
383
346
        }
384
347
 
385
 
        protected void showContinueOrAbort( int res ) throws AbortExportException
386
 
        {
387
 
                showContinueOrAbort( _doit.getText( res ).toString() );
388
 
        }
389
 
 
390
 
        synchronized protected void showContinueOrAbort( String message )
 
348
        protected void showFatalError( int res ) throws AbortExportException
 
349
        {
 
350
                showFatalError( _doit.getText( res ).toString() );
 
351
        }
 
352
 
 
353
        synchronized protected void showFatalError( String message )
 
354
                        throws AbortExportException
 
355
        {
 
356
                checkAbort();
 
357
                _doit._handler.sendMessage( Message.obtain(
 
358
                        _doit._handler, Doit.MESSAGE_ERROR, message ) );
 
359
                try {
 
360
                        wait();
 
361
                }
 
362
                catch( InterruptedException e ) { }
 
363
 
 
364
                // no need to check if an abortion happened during the wait, we are
 
365
                // about to finish anyway!
 
366
                finish( ACTION_ABORT );
 
367
        }
 
368
 
 
369
        protected boolean showContinue( int res ) throws AbortExportException
 
370
        {
 
371
                return showContinue( _doit.getText( res ).toString() );
 
372
        }
 
373
 
 
374
        synchronized protected boolean showContinue( String message )
391
375
                        throws AbortExportException
392
376
        {
393
377
                checkAbort();
398
382
                }
399
383
                catch( InterruptedException e ) { }
400
384
 
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();
 
385
                // check if an abortion happened during the wait
 
386
                checkAbort();
 
387
 
 
388
                return _response == RESPONSE_POSITIVE;
407
389
        }
408
390
 
409
391
        protected void setProgressMessage( int res ) throws AbortExportException
419
401
                checkAbort();
420
402
                _doit._handler.sendMessage( Message.obtain(
421
403
                        _doit._handler, Doit.MESSAGE_SETMAXPROGRESS,
422
 
                        Integer.valueOf( max_progress ) ) );
 
404
                        new Integer( max_progress ) ) );
423
405
        }
424
406
 
425
407
        protected void setTmpProgress( int tmp_progress )
428
410
                checkAbort();
429
411
                _doit._handler.sendMessage( Message.obtain(
430
412
                        _doit._handler, Doit.MESSAGE_SETTMPPROGRESS,
431
 
                        Integer.valueOf( tmp_progress ) ) );
 
413
                        new Integer( tmp_progress ) ) );
432
414
        }
433
415
 
434
416
        protected void setProgress( int progress ) throws AbortExportException
436
418
                checkAbort();
437
419
                _doit._handler.sendMessage( Message.obtain(
438
420
                        _doit._handler, Doit.MESSAGE_SETPROGRESS,
439
 
                        Integer.valueOf( progress ) ) );
 
421
                        new Integer( progress ) ) );
440
422
        }
441
423
 
442
424
        protected void finish( int action ) throws AbortExportException