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

  • Committer: edam
  • Date: 2012-04-24 09:56:17 UTC
  • Revision ID: tim@ed.am-20120424095617-lsfkkpkrlqk9xthn
updated all URLs, email addresses and package names to ed.am

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * Importer.java
3
3
 *
4
 
 * Copyright (C) 2009 to 2011 Tim Marston <edam@waxworlds.org>
 
4
 * Copyright (C) 2009 to 2011 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Import Contacts program (hereafter referred
7
7
 * to as "this program"). For more information, see
8
 
 * http://www.waxworlds.org/edam/software/android/import-contacts
 
8
 * http://ed.am/dev/android/import-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 org.waxworlds.edam.importcontacts;
 
24
package am.ed.importcontacts;
25
25
 
 
26
import java.util.Arrays;
26
27
import java.util.HashMap;
 
28
import java.util.HashSet;
27
29
import java.util.Iterator;
28
30
import java.util.Set;
29
31
import java.util.regex.Matcher;
35
37
import android.net.Uri;
36
38
import android.os.Message;
37
39
import android.provider.Contacts;
 
40
import android.provider.Contacts.PhonesColumns;
38
41
 
39
42
 
40
43
public class Importer extends Thread
124
127
 
125
128
                protected String _name = null;
126
129
                protected String _primary_organisation = null;
127
 
                protected boolean _primary_organisation_is_preferred = false;
 
130
                protected boolean _primary_organisation_is_preferred;
128
131
                protected String _primary_number = null;
129
 
                protected boolean _primary_number_is_preferred = false;
 
132
                protected int _primary_number_type;
 
133
                protected boolean _primary_number_is_preferred;
130
134
                protected String _primary_email = null;
131
 
                protected boolean _primary_email_is_preferred = false;
 
135
                protected boolean _primary_email_is_preferred;
132
136
                protected HashMap< String, ExtraDetail > _organisations = null;
133
137
                protected HashMap< String, PreferredDetail > _numbers = null;
134
138
                protected HashMap< String, PreferredDetail > _emails = null;
175
179
                                        new ExtraDetail( 0, false, title ) );
176
180
 
177
181
                        // if this is the first organisation added, or it's a preferred
178
 
                        // organisation and a previous organisation wasn't, then remember
179
 
                        // that this is the "primary organisation".
 
182
                        // organisation and the current primary organisation isn't, then
 
183
                        // record this as the primary organisation.
180
184
                        if( _primary_organisation == null ||
181
185
                                ( is_preferred && !_primary_organisation_is_preferred ) )
182
186
                        {
223
227
                                _numbers.put( number,
224
228
                                        new PreferredDetail( type, false ) );
225
229
 
 
230
                        final Set< Integer > non_voice_types = new HashSet< Integer >(
 
231
                                Arrays.asList( PhonesColumns.TYPE_FAX_HOME,
 
232
                                        PhonesColumns.TYPE_FAX_WORK, PhonesColumns.TYPE_PAGER ) );
 
233
 
226
234
                        // if this is the first number added, or it's a preferred number
227
 
                        // and a previous number wasn't, then remember that this is the
228
 
                        // "primary number".
 
235
                        // and the current primary number isn't, or this number is on equal
 
236
                        // standing with the primary number in terms of preference and it is
 
237
                        // a voice number and the primary number isn't, then record this as
 
238
                        // the primary number.
229
239
                        if( _primary_number == null ||
230
 
                                ( is_preferred && !_primary_number_is_preferred ) )
 
240
                                ( is_preferred && !_primary_number_is_preferred ) ||
 
241
                                ( is_preferred == _primary_number_is_preferred &&
 
242
                                        !non_voice_types.contains( type ) &&
 
243
                                        non_voice_types.contains( _primary_number_type ) ) )
231
244
                        {
232
245
                                _primary_number = number;
 
246
                                _primary_number_type = type;
233
247
                                _primary_number_is_preferred = is_preferred;
234
248
                        }
235
249
                }
271
285
                        if( !_emails.containsKey( email ) )
272
286
                                _emails.put( email, new PreferredDetail( type, false ) );
273
287
 
274
 
                        // if this is the first email added, or it's a preferred email
275
 
                        // and a previous email wasn't, then remember that this is the
276
 
                        // "primary email".
 
288
                        // if this is the first email added, or it's a preferred email and
 
289
                        // the current primary organisation isn't, then record this as the
 
290
                        // primary email.
277
291
                        if( _primary_email == null ||
278
292
                                ( is_preferred && !_primary_email_is_preferred ) )
279
293
                        {