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

  • Committer: edam
  • Date: 2009-02-02 07:07:52 UTC
  • Revision ID: edam@waxworlds.org-20090202070752-2lp8igdsdjyu9fic
- bugfix: add contacts to the "my contacts" group didn't actually work on a real device. So we're doing it a different way.
- updated todo list

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.edam.importcontacts;
 
24
package org.waxworlds.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;
43
44
        public final static int ACTION_ABORT = 1;
44
45
        public final static int ACTION_ALLDONE = 2;
45
46
 
142
143
                }
143
144
        }
144
145
 
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
 
 
234
233
                // no need to check if an abortion happened during the wait, we are
235
234
                // about to finish anyway!
236
235
                finish( ACTION_ABORT );
251
250
                        wait();
252
251
                }
253
252
                catch( InterruptedException e ) { }
254
 
 
255
253
                // no need to check if an abortion happened during the wait, we are
256
254
                // about to finish anyway!
257
255
                finish( ACTION_ABORT );
317
315
                int message;
318
316
                switch( action )
319
317
                {
320
 
                case ACTION_ALLDONE:    message = Doit.MESSAGE_ALLDONE; break;
 
318
                case ACTION_GOBACK:             message = Doit.MESSAGE_FINISHED_GOBACK; break;
 
319
                case ACTION_ALLDONE:    message = Doit.MESSAGE_FINISHED_ALLDONE; break;
321
320
                default:        // fall through
322
 
                case ACTION_ABORT:              message = Doit.MESSAGE_ABORT; break;
 
321
                case ACTION_ABORT:              message = Doit.MESSAGE_FINISHED; break;
323
322
                }
324
323
                _doit._handler.sendEmptyMessage( message );
325
324
 
434
433
                        id = ContentUris.parseId( contactUri );
435
434
                        if( id <= 0 ) return;   // shouldn't happen!
436
435
 
437
 
                        // try to add them to the "My Contacts" group
438
 
                        try {
439
 
                                Contacts.People.addToMyContactsGroup(
 
436
                        // add them to the "My Contacts" group
 
437
                        Contacts.People.addToMyContactsGroup(
440
438
                                        _doit.getContentResolver(), id );
441
 
                        }
442
 
                        catch( IllegalStateException e ) { }
443
439
 
444
440
                        // update cache
445
441
                        _contacts.put( contact._name, id );
468
464
                Long contactId = ContentUris.parseId( contactUri );
469
465
                Uri contactPhonesUri = Uri.withAppendedPath( contactUri,
470
466
                                Contacts.People.Phones.CONTENT_DIRECTORY );
471
 
                Set< String > phonesKeys = phones.keySet();
 
467
                Set phonesKeys = phones.keySet();
472
468
 
473
469
                // add phone numbers
474
 
                Iterator< String > i = phonesKeys.iterator();
 
470
                Iterator i = phonesKeys.iterator();
475
471
                while( i.hasNext() ) {
476
472
                        ContactData.PhoneData phone = phones.get( i.next() );
477
473
 
519
515
                Long contactId = ContentUris.parseId( contactUri );
520
516
                Uri contactContactMethodsUri = Uri.withAppendedPath( contactUri,
521
517
                                Contacts.People.ContactMethods.CONTENT_DIRECTORY );
522
 
                Set< String > emailsKeys = emails.keySet();
 
518
                Set emailsKeys = emails.keySet();
523
519
 
524
520
                // add email addresses
525
 
                Iterator< String > i = emailsKeys.iterator();
 
521
                Iterator i = emailsKeys.iterator();
526
522
                while( i.hasNext() ) {
527
523
                        ContactData.EmailData email = emails.get( i.next() );
528
524