1
0
mirror of https://github.com/etesync/android synced 2025-06-05 23:58:50 +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"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.bitfire.davdroid" package="at.bitfire.davdroid"
android:versionCode="21" android:versionCode="22"
android:versionName="0.5.3-alpha" > android:versionName="0.5.4-alpha" >
<uses-sdk <uses-sdk
android:minSdkVersion="14" android:minSdkVersion="14"

View File

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

View File

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

View File

@ -55,10 +55,11 @@ public class Contact extends Resource {
PROPERTY_STARRED = "X-DAVDROID-STARRED", PROPERTY_STARRED = "X-DAVDROID-STARRED",
PROPERTY_PHONETIC_FIRST_NAME = "X-PHONETIC-FIRST-NAME", PROPERTY_PHONETIC_FIRST_NAME = "X-PHONETIC-FIRST-NAME",
PROPERTY_PHONETIC_MIDDLE_NAME = "X-PHONETIC-MIDDLE-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"); public final static EmailType EMAIL_TYPE_MOBILE = EmailType.get("X-MOBILE");
public final static TelephoneType public final static TelephoneType
PHONE_TYPE_CALLBACK = TelephoneType.get("X-CALLBACK"), PHONE_TYPE_CALLBACK = TelephoneType.get("X-CALLBACK"),
PHONE_TYPE_COMPANY_MAIN = TelephoneType.get("X-COMPANY_MAIN"), PHONE_TYPE_COMPANY_MAIN = TelephoneType.get("X-COMPANY_MAIN"),
@ -160,7 +161,7 @@ public class Contact extends Resource {
} }
for (Role role : vcard.getRoles()) for (Role role : vcard.getRoles())
this.role = role.getValue(); this.role = role.getValue();
impps = vcard.getImpps(); impps = vcard.getImpps();
Nickname nicknames = vcard.getNickname(); Nickname nicknames = vcard.getNickname();
@ -180,6 +181,10 @@ public class Contact extends Resource {
birthDay = vcard.getBirthday(); birthDay = vcard.getBirthday();
anniversary = vcard.getAnniversary(); 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) for (Email email : emails)
vcard.addEmail(email); vcard.addEmail(email);
if (photo != null)
vcard.addPhoto(new Photo(photo, ImageType.JPEG));
if (organization != null) { if (organization != null) {
Organization org = new Organization(); Organization org = new Organization();
org.addValue(organization); org.addValue(organization);
@ -256,14 +258,17 @@ public class Contact extends Resource {
vcard.setAnniversary(anniversary); vcard.setAnniversary(anniversary);
if (birthDay != null) if (birthDay != null)
vcard.setBirthday(birthDay); vcard.setBirthday(birthDay);
if (photo != null)
vcard.addPhoto(new Photo(photo, ImageType.JPEG));
vcard.setRevision(Revision.now()); vcard.setRevision(Revision.now());
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
Ezvcard Ezvcard
.write(vcard) .write(vcard)
.version(VCardVersion.V3_0) .version(VCardVersion.V3_0)
.prodId(false) // we provide or own PRODID .prodId(false) // we provide our own PRODID
.go(os); .go(os);
return 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.Organization;
import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Photo; import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.CommonDataKinds.SipAddress;
import android.provider.ContactsContract.CommonDataKinds.StructuredName; import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.provider.ContactsContract.CommonDataKinds.Website; import android.provider.ContactsContract.CommonDataKinds.Website;
@ -163,6 +164,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
populatePostalAddresses(c); populatePostalAddresses(c);
populateURLs(c); populateURLs(c);
populateEvents(c); populateEvents(c);
populateSipAddress(c);
} catch(RemoteException ex) { } catch(RemoteException ex) {
throw new LocalStorageException(ex); throw new LocalStorageException(ex);
} }
@ -301,7 +303,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
@Cleanup InputStream is = fd.createInputStream(); @Cleanup InputStream is = fd.createInputStream();
c.setPhoto(IOUtils.toByteArray(is)); c.setPhoto(IOUtils.toByteArray(is));
} catch(IOException ex) { } catch(IOException ex) {
Log.w(TAG, "Couldn't read contact photo", ex); Log.v(TAG, "Couldn't read contact photo", ex);
} }
} }
@ -458,6 +460,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 */ /* content builder methods */
@ -517,8 +542,9 @@ public class LocalAddressBook extends LocalCollection<Contact> {
if (contact.getBirthDay() != null) if (contact.getBirthDay() != null)
queueOperation(buildEvent(newDataInsertBuilder(localID, backrefIdx), contact.getBirthDay(), CommonDataKinds.Event.TYPE_BIRTHDAY)); queueOperation(buildEvent(newDataInsertBuilder(localID, backrefIdx), contact.getBirthDay(), CommonDataKinds.Event.TYPE_BIRTHDAY));
// TODO relation // TODO relations
// TODO SIP address
// SIP address built by buildIMPP
} }
@Override @Override
@ -663,7 +689,7 @@ public class LocalAddressBook extends LocalCollection<Contact> {
typeLabel = xNameToLabel(impp.getTypes().iterator().next().getValue()); typeLabel = xNameToLabel(impp.getTypes().iterator().next().getValue());
} }
int protocolCode; int protocolCode = 0;
String protocolLabel = null; String protocolLabel = null;
String protocol = impp.getProtocol(); String protocol = impp.getProtocol();
@ -672,6 +698,9 @@ public class LocalAddressBook extends LocalCollection<Contact> {
return null; return null;
} }
// SIP addresses are IMPP entries in the VCard but locally stored in SipAddress rather than Im
boolean sipAddress = false;
if (impp.isAim()) if (impp.isAim())
protocolCode = Im.PROTOCOL_AIM; protocolCode = Im.PROTOCOL_AIM;
else if (impp.isMsn()) else if (impp.isMsn())
@ -690,20 +719,31 @@ public class LocalAddressBook extends LocalCollection<Contact> {
protocolCode = Im.PROTOCOL_JABBER; protocolCode = Im.PROTOCOL_JABBER;
else if (protocol.equalsIgnoreCase("netmeeting")) else if (protocol.equalsIgnoreCase("netmeeting"))
protocolCode = Im.PROTOCOL_NETMEETING; protocolCode = Im.PROTOCOL_NETMEETING;
else if (protocol.equalsIgnoreCase("sip"))
sipAddress = true;
else { else {
protocolCode = Im.PROTOCOL_CUSTOM; protocolCode = Im.PROTOCOL_CUSTOM;
protocolLabel = protocol; protocolLabel = protocol;
} }
builder = builder if (sipAddress)
.withValue(Data.MIMETYPE, Im.CONTENT_ITEM_TYPE) // save as SIP address
.withValue(Im.DATA, impp.getHandle()) builder = builder
.withValue(Im.TYPE, typeCode) .withValue(Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE)
.withValue(Im.PROTOCOL, protocolCode); .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 (protocolLabel != null)
builder = builder.withValue(Im.CUSTOM_PROTOCOL, protocolLabel);
}
if (typeLabel != null) if (typeLabel != null)
builder = builder.withValue(Im.LABEL, typeLabel); builder = builder.withValue(Im.LABEL, typeLabel);
if (protocolLabel != null)
builder = builder.withValue(Im.CUSTOM_PROTOCOL, protocolLabel);
return builder; return builder;
} }