/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: 2011-06-04 16:52:28 UTC
  • Revision ID: edam@waxworlds.org-20110604165228-jam230oo29u1m06u
- properly handle multiple TYPE= params in one entry in a v3.0 vCard
- when deciding which phone number to use as the pimary number, a voice number takes precedence over a non-voice (fax or pager) number of the same standing in terms of being preferred or not.

Show diffs side-by-side

added added

removed removed

23
23
 
24
24
package org.waxworlds.edam.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
                        {