1
0
mirror of https://github.com/etesync/android synced 2024-11-22 16:08:13 +00:00

Support for SIP addresses (closes #78)

* support for SIP addresses (always exported as IMPP, imported as IMPP/X-SIP)
* version bump to 0.5.4
This commit is contained in:
rfc2822 2013-12-26 17:23:14 +01:00
parent 558075f1bb
commit df012efe78
5 changed files with 69 additions and 22 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.bitfire.davdroid"
android:versionCode="21"
android:versionName="0.5.3-alpha" >
android:versionCode="22"
android:versionName="0.5.4-alpha" >
<uses-sdk
android:minSdkVersion="14"

View File

@ -94,6 +94,8 @@
yearOptional="false" />
<Type type="anniversary" />
</DataKind>
<DataKind kind="sip_address" maxOccurs="1" />
</EditSchema>
</ContactsAccountType>

View File

@ -9,7 +9,7 @@ package at.bitfire.davdroid;
public class Constants {
public static final String
APP_VERSION = "0.5.2-alpha",
APP_VERSION = "0.5.4-alpha",
ACCOUNT_TYPE = "bitfire.at.davdroid",

View File

@ -55,7 +55,8 @@ public class Contact extends Resource {
PROPERTY_STARRED = "X-DAVDROID-STARRED",
PROPERTY_PHONETIC_FIRST_NAME = "X-PHONETIC-FIRST-NAME",
PROPERTY_PHONETIC_MIDDLE_NAME = "X-PHONETIC-MIDDLE-NAME",
PROPERTY_PHONETIC_LAST_NAME = "X-PHONETIC-LAST-NAME";
PROPERTY_PHONETIC_LAST_NAME = "X-PHONETIC-LAST-NAME",
PROPERTY_SIP = "X-SIP";
public final static EmailType EMAIL_TYPE_MOBILE = EmailType.get("X-MOBILE");
@ -180,6 +181,10 @@ public class Contact extends Resource {
birthDay = vcard.getBirthday();
anniversary = vcard.getAnniversary();
// get X-SIP and import as IMPP
for (RawProperty sip : vcard.getExtendedProperties(PROPERTY_SIP))
impps.add(new Impp("sip", sip.getValue()));
}
@ -226,9 +231,6 @@ public class Contact extends Resource {
for (Email email : emails)
vcard.addEmail(email);
if (photo != null)
vcard.addPhoto(new Photo(photo, ImageType.JPEG));
if (organization != null) {
Organization org = new Organization();
org.addValue(organization);
@ -257,13 +259,16 @@ public class Contact extends Resource {
if (birthDay != null)
vcard.setBirthday(birthDay);
if (photo != null)
vcard.addPhoto(new Photo(photo, ImageType.JPEG));
vcard.setRevision(Revision.now());
ByteArrayOutputStream os = new ByteArrayOutputStream();
Ezvcard
.write(vcard)
.version(VCardVersion.V3_0)
.prodId(false) // we provide or own PRODID
.prodId(false) // we provide our own PRODID
.go(os);
return os;
}

View File

@ -42,6 +42,7 @@ import android.provider.ContactsContract.CommonDataKinds.Note;
import android.provider.ContactsContract.CommonDataKinds.Organization;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.CommonDataKinds.SipAddress;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.provider.ContactsContract.CommonDataKinds.Website;
@ -163,6 +164,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
populatePostalAddresses(c);
populateURLs(c);
populateEvents(c);
populateSipAddress(c);
} catch(RemoteException ex) {
throw new LocalStorageException(ex);
}
@ -301,7 +303,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
@Cleanup InputStream is = fd.createInputStream();
c.setPhoto(IOUtils.toByteArray(is));
} catch(IOException ex) {
Log.w(TAG, "Couldn't read contact photo", ex);
Log.v(TAG, "Couldn't read contact photo", ex);
}
}
@ -459,6 +461,29 @@ public class LocalAddressBook extends LocalCollection<Contact> {
}
}
protected void populateSipAddress(Contact c) throws RemoteException {
@Cleanup Cursor cursor = providerClient.query(dataURI(),
new String[] { CommonDataKinds.SipAddress.SIP_ADDRESS, CommonDataKinds.SipAddress.TYPE, CommonDataKinds.SipAddress.LABEL },
Website.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
new String[] { String.valueOf(c.getLocalID()), CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE }, null);
if (cursor != null && cursor.moveToNext()) {
Impp impp = new Impp("sip:" + cursor.getString(0));
switch (cursor.getInt(1)) {
case Im.TYPE_HOME:
impp.addType(ImppType.HOME);
break;
case Im.TYPE_WORK:
impp.addType(ImppType.WORK);
break;
case Im.TYPE_CUSTOM:
String customType = cursor.getString(2);
if (customType != null && !customType.isEmpty())
impp.addType(ImppType.get(labelToXName(customType)));
}
c.getImpps().add(impp);
}
}
/* content builder methods */
@ -517,8 +542,9 @@ public class LocalAddressBook extends LocalCollection<Contact> {
if (contact.getBirthDay() != null)
queueOperation(buildEvent(newDataInsertBuilder(localID, backrefIdx), contact.getBirthDay(), CommonDataKinds.Event.TYPE_BIRTHDAY));
// TODO relation
// TODO SIP address
// TODO relations
// SIP address built by buildIMPP
}
@Override
@ -663,7 +689,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
typeLabel = xNameToLabel(impp.getTypes().iterator().next().getValue());
}
int protocolCode;
int protocolCode = 0;
String protocolLabel = null;
String protocol = impp.getProtocol();
@ -672,6 +698,9 @@ public class LocalAddressBook extends LocalCollection<Contact> {
return null;
}
// SIP addresses are IMPP entries in the VCard but locally stored in SipAddress rather than Im
boolean sipAddress = false;
if (impp.isAim())
protocolCode = Im.PROTOCOL_AIM;
else if (impp.isMsn())
@ -690,20 +719,31 @@ public class LocalAddressBook extends LocalCollection<Contact> {
protocolCode = Im.PROTOCOL_JABBER;
else if (protocol.equalsIgnoreCase("netmeeting"))
protocolCode = Im.PROTOCOL_NETMEETING;
else if (protocol.equalsIgnoreCase("sip"))
sipAddress = true;
else {
protocolCode = Im.PROTOCOL_CUSTOM;
protocolLabel = protocol;
}
if (sipAddress)
// save as SIP address
builder = builder
.withValue(Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE)
.withValue(Im.DATA, impp.getHandle())
.withValue(Im.TYPE, typeCode);
else {
// save as IM address
builder = builder
.withValue(Data.MIMETYPE, Im.CONTENT_ITEM_TYPE)
.withValue(Im.DATA, impp.getHandle())
.withValue(Im.TYPE, typeCode)
.withValue(Im.PROTOCOL, protocolCode);
if (typeLabel != null)
builder = builder.withValue(Im.LABEL, typeLabel);
if (protocolLabel != null)
builder = builder.withValue(Im.CUSTOM_PROTOCOL, protocolLabel);
}
if (typeLabel != null)
builder = builder.withValue(Im.LABEL, typeLabel);
return builder;
}