/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 13:16:20 UTC
  • Revision ID: edam@waxworlds.org-20110604131620-hean9j66r3f5i72h
- fix UTF-8 unencoding by default on v3.0 vCards
- proper unescaping of strings in v3.0 vCards (also works for v2.1, although the 2.1 specs don't mention it)

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;
27
26
import java.util.HashMap;
28
 
import java.util.HashSet;
29
27
import java.util.Iterator;
30
28
import java.util.Set;
31
29
import java.util.regex.Matcher;
37
35
import android.net.Uri;
38
36
import android.os.Message;
39
37
import android.provider.Contacts;
40
 
import android.provider.Contacts.PhonesColumns;
41
38
 
42
39
 
43
40
public class Importer extends Thread
127
124
 
128
125
                protected String _name = null;
129
126
                protected String _primary_organisation = null;
130
 
                protected boolean _primary_organisation_is_preferred;
 
127
                protected boolean _primary_organisation_is_preferred = false;
131
128
                protected String _primary_number = null;
132
 
                protected int _primary_number_type;
133
 
                protected boolean _primary_number_is_preferred;
 
129
                protected boolean _primary_number_is_preferred = false;
134
130
                protected String _primary_email = null;
135
 
                protected boolean _primary_email_is_preferred;
 
131
                protected boolean _primary_email_is_preferred = false;
136
132
                protected HashMap< String, ExtraDetail > _organisations = null;
137
133
                protected HashMap< String, PreferredDetail > _numbers = null;
138
134
                protected HashMap< String, PreferredDetail > _emails = null;
179
175
                                        new ExtraDetail( 0, false, title ) );
180
176
 
181
177
                        // if this is the first organisation added, or it's a preferred
182
 
                        // organisation and the current primary organisation isn't, then
183
 
                        // record this as the primary organisation.
 
178
                        // organisation and a previous organisation wasn't, then remember
 
179
                        // that this is the "primary organisation".
184
180
                        if( _primary_organisation == null ||
185
181
                                ( is_preferred && !_primary_organisation_is_preferred ) )
186
182
                        {
227
223
                                _numbers.put( number,
228
224
                                        new PreferredDetail( type, false ) );
229
225
 
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
 
 
234
226
                        // if this is the first number added, or it's a preferred 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.
 
227
                        // and a previous number wasn't, then remember that this is the
 
228
                        // "primary number".
239
229
                        if( _primary_number == null ||
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 ) ) )
 
230
                                ( is_preferred && !_primary_number_is_preferred ) )
244
231
                        {
245
232
                                _primary_number = number;
246
 
                                _primary_number_type = type;
247
233
                                _primary_number_is_preferred = is_preferred;
248
234
                        }
249
235
                }
285
271
                        if( !_emails.containsKey( email ) )
286
272
                                _emails.put( email, new PreferredDetail( type, false ) );
287
273
 
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.
 
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".
291
277
                        if( _primary_email == null ||
292
278
                                ( is_preferred && !_primary_email_is_preferred ) )
293
279
                        {