/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/Importer.java

  • Committer: edam
  • Date: 2010-07-04 14:44:48 UTC
  • Revision ID: edam@waxworlds.org-20100704144448-1m30v811opup20fs
- got rid of the pretend ImportContacts activity alltogether (and made the Intro activity the startup one)
- massively simplified the WizzardActivity class so it works propperly
- moved all code to org.waxworlds.edam
- added an "aborted" message when the importion is aborted
- simplified the 3 actions the worker thread can take when stopping (only 2 were actualy used) to "aborted" or "alldone"
- changed intro message to match website
- bugfix: don't blow up when the My Contacts group is missing

Show diffs side-by-side

added added

removed removed

21
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 */
23
23
 
24
 
package org.waxworlds.importcontacts;
 
24
package org.waxworlds.edam.importcontacts;
25
25
 
26
26
import java.util.HashMap;
27
27
import java.util.HashSet;
40
40
 
41
41
public class Importer extends Thread
42
42
{
43
 
        public final static int ACTION_GOBACK = 0;
44
43
        public final static int ACTION_ABORT = 1;
45
44
        public final static int ACTION_ALLDONE = 2;
46
45
 
143
142
                }
144
143
        }
145
144
 
 
145
        @SuppressWarnings("serial")
146
146
        protected class AbortImportException extends Exception { };
147
147
 
148
148
        public Importer( Doit doit )
230
230
                        wait();
231
231
                }
232
232
                catch( InterruptedException e ) { }
 
233
 
233
234
                // no need to check if an abortion happened during the wait, we are
234
235
                // about to finish anyway!
235
236
                finish( ACTION_ABORT );
250
251
                        wait();
251
252
                }
252
253
                catch( InterruptedException e ) { }
 
254
 
253
255
                // no need to check if an abortion happened during the wait, we are
254
256
                // about to finish anyway!
255
257
                finish( ACTION_ABORT );
315
317
                int message;
316
318
                switch( action )
317
319
                {
318
 
                case ACTION_GOBACK:             message = Doit.MESSAGE_FINISHED_GOBACK; break;
319
 
                case ACTION_ALLDONE:    message = Doit.MESSAGE_FINISHED_ALLDONE; break;
 
320
                case ACTION_ALLDONE:    message = Doit.MESSAGE_ALLDONE; break;
320
321
                default:        // fall through
321
 
                case ACTION_ABORT:              message = Doit.MESSAGE_FINISHED; break;
 
322
                case ACTION_ABORT:              message = Doit.MESSAGE_ABORT; break;
322
323
                }
323
324
                _doit._handler.sendEmptyMessage( message );
324
325
 
433
434
                        id = ContentUris.parseId( contactUri );
434
435
                        if( id <= 0 ) return;   // shouldn't happen!
435
436
 
436
 
                        // add them to the "My Contacts" group
437
 
                        Contacts.People.addToMyContactsGroup(
 
437
                        // try to add them to the "My Contacts" group
 
438
                        try {
 
439
                                Contacts.People.addToMyContactsGroup(
438
440
                                        _doit.getContentResolver(), id );
 
441
                        }
 
442
                        catch( IllegalStateException e ) { }
439
443
 
440
444
                        // update cache
441
445
                        _contacts.put( contact._name, id );
464
468
                Long contactId = ContentUris.parseId( contactUri );
465
469
                Uri contactPhonesUri = Uri.withAppendedPath( contactUri,
466
470
                                Contacts.People.Phones.CONTENT_DIRECTORY );
467
 
                Set phonesKeys = phones.keySet();
 
471
                Set< String > phonesKeys = phones.keySet();
468
472
 
469
473
                // add phone numbers
470
 
                Iterator i = phonesKeys.iterator();
 
474
                Iterator< String > i = phonesKeys.iterator();
471
475
                while( i.hasNext() ) {
472
476
                        ContactData.PhoneData phone = phones.get( i.next() );
473
477
 
515
519
                Long contactId = ContentUris.parseId( contactUri );
516
520
                Uri contactContactMethodsUri = Uri.withAppendedPath( contactUri,
517
521
                                Contacts.People.ContactMethods.CONTENT_DIRECTORY );
518
 
                Set emailsKeys = emails.keySet();
 
522
                Set< String > emailsKeys = emails.keySet();
519
523
 
520
524
                // add email addresses
521
 
                Iterator i = emailsKeys.iterator();
 
525
                Iterator< String > i = emailsKeys.iterator();
522
526
                while( i.hasNext() ) {
523
527
                        ContactData.EmailData email = emails.get( i.next() );
524
528