96
96
// if this is an organisation name for a contact for whom we
97
97
// have not added a lookup, add a lookup for the contact id
99
if( unadded.contains( id ) ) {
99
if( unadded_ids.contains( id ) ) {
100
100
cache.addLookup( new CacheIdentifier(
101
101
CacheIdentifier.Type.ORGANISATION, organisation ), id );
102
unadded.remove( id );
102
unadded_ids.remove( id );
105
105
// add associated data
124
124
// if this is a number for a contact for whom we have not
125
125
// added a lookup, add a lookup for the contact id by phone
127
if( unadded.contains( id ) ) {
127
if( unadded_ids.contains( id ) ) {
128
128
cache.addLookup( new CacheIdentifier(
129
129
CacheIdentifier.Type.PRIMARY_NUMBER, number ), id );
130
unadded.remove( id );
130
unadded_ids.remove( id );
133
133
// add associated data
141
141
Contacts.ContactMethods.PERSON_ID,
142
142
Contacts.ContactMethods.DATA,
143
143
Contacts.ContactMethods.KIND,
144
}, Contacts.ContactMethods.KIND + " IN( ?, ? )", new String[] {
144
}, Contacts.ContactMethods.KIND + " IN( ?, ? )",
145
146
"" + Contacts.KIND_EMAIL,
146
147
"" + Contacts.KIND_POSTAL,
147
148
}, Contacts.ContactMethods.ISPRIMARY + " DESC" );
160
161
// if this is an email address for a contact for whom we
161
162
// have not added a lookup, add a lookup for the contact
162
163
// id by email address
163
if( unadded.contains( id ) ) {
164
if( unadded_ids.contains( id ) ) {
164
165
cache.addLookup( new CacheIdentifier(
165
166
CacheIdentifier.Type.PRIMARY_EMAIL, email ), id );
166
unadded.remove( id );
167
unadded_ids.remove( id );
169
170
// add associated data
196
public Long addContact( String name )
197
public Long addContact( String name ) throws ContactCreationException
198
199
ContentValues values = new ContentValues();
199
values.put( Contacts.People.NAME, name );
201
values.put( Contacts.People.NAME, name );
200
202
Uri contact_uri = _activity.getContentResolver().insert(
201
203
Contacts.People.CONTENT_URI, values );
202
204
Long id = ContentUris.parseId( contact_uri );
206
throw new ContactCreationException();
204
208
// try to add them to the "My Contacts" group
205
if( id != null && id > 0 ) {
207
Contacts.People.addToMyContactsGroup(
208
_activity.getContentResolver(), id );
210
catch( IllegalStateException e ) {
211
// ignore any failure
215
return id == null? 0 : id;
210
Contacts.People.addToMyContactsGroup(
211
_activity.getContentResolver(), id );
213
catch( IllegalStateException e ) {
214
// ignore any failure
220
private int convertTypeToBackendType( Class< ? > cls, int type )
221
throws ContactCreationException
223
if( cls == Contacts.Phones.class )
227
case ContactData.TYPE_HOME:
228
return Contacts.Phones.TYPE_HOME;
229
case ContactData.TYPE_WORK:
230
return Contacts.Phones.TYPE_WORK;
231
case ContactData.TYPE_MOBILE:
232
return Contacts.Phones.TYPE_MOBILE;
233
case ContactData.TYPE_FAX_HOME:
234
return Contacts.Phones.TYPE_FAX_HOME;
235
case ContactData.TYPE_FAX_WORK:
236
return Contacts.Phones.TYPE_FAX_WORK;
237
case ContactData.TYPE_PAGER:
238
return Contacts.Phones.TYPE_PAGER;
241
else if( cls == Contacts.ContactMethods.class )
245
case ContactData.TYPE_HOME:
246
return Contacts.ContactMethods.TYPE_HOME;
247
case ContactData.TYPE_WORK:
248
return Contacts.ContactMethods.TYPE_WORK;
253
throw new ContactCreationException();
219
257
public void addContactPhone( Long id, String number,
220
ContactData.PreferredDetail data )
258
ContactData.PreferredDetail data ) throws ContactCreationException
222
260
Uri contact_phones_uri = Uri.withAppendedPath(
223
261
ContentUris.withAppendedId( Contacts.People.CONTENT_URI, id ),
224
262
Contacts.People.Phones.CONTENT_DIRECTORY );
226
264
ContentValues values = new ContentValues();
227
values.put( Contacts.Phones.TYPE, data.getType() );
265
values.put( Contacts.Phones.TYPE,
266
convertTypeToBackendType( Contacts.Phones.class,
228
268
values.put( Contacts.Phones.NUMBER, number );
229
269
if( data.isPreferred() )
230
270
values.put( Contacts.Phones.ISPRIMARY, 1 );
243
283
ContentValues values = new ContentValues();
244
284
values.put( Contacts.ContactMethods.KIND, Contacts.KIND_EMAIL );
245
285
values.put( Contacts.ContactMethods.DATA, email );
246
values.put( Contacts.ContactMethods.TYPE, data.getType() );
286
values.put( Contacts.ContactMethods.TYPE,
287
convertTypeToBackendType( Contacts.ContactMethods.class,
247
289
if( data.isPreferred() )
248
290
values.put( Contacts.ContactMethods.ISPRIMARY, 1 );
262
304
ContentValues values = new ContentValues();
263
305
values.put( Contacts.ContactMethods.KIND, Contacts.KIND_POSTAL );
264
306
values.put( Contacts.ContactMethods.DATA, address );
265
values.put( Contacts.ContactMethods.TYPE, data.getType() );
307
values.put( Contacts.ContactMethods.TYPE,
308
convertTypeToBackendType( Contacts.ContactMethods.class,
267
311
_activity.getContentResolver().insert( contact_contact_methods_uri,