Merge the change in cupcake_dcm so that Contacts app is able to use it.

This commit is contained in:
Daisuke Miyakawa
2009-06-22 13:37:03 +09:00
parent 77c5c40548
commit 3e3324bae4

View File

@@ -37,6 +37,7 @@ import android.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@@ -180,6 +181,34 @@ public class ContactStruct {
organizationList.add(organizationData); organizationList.add(organizationData);
} }
/**
* Set "position" value to the appropriate data. If there's more than one
* OrganizationData objects, the value is set to the last one. If there's no
* OrganizationData object, a new OrganizationData is created, whose company name is
* empty.
*
* TODO: incomplete logic. fix this:
*
* e.g. This assumes ORG comes earlier, but TITLE may come earlier like this, though we do not
* know how to handle it in general cases...
* ----
* TITLE:Software Engineer
* ORG:Google
* ----
*/
public void setPosition(String positionValue) {
if (organizationList == null) {
organizationList = new ArrayList<OrganizationData>();
}
int size = organizationList.size();
if (size == 0) {
addOrganization(Contacts.OrganizationColumns.TYPE_OTHER, "", null, false);
size = 1;
}
OrganizationData lastData = organizationList.get(size - 1);
lastData.positionName = positionValue;
}
public void addExtension(PropertyNode propertyNode) { public void addExtension(PropertyNode propertyNode) {
if (propertyNode.propValue.length() == 0) { if (propertyNode.propValue.length() == 0) {
return; return;
@@ -426,8 +455,6 @@ public class ContactStruct {
} else if (name.equals("ORG")) { } else if (name.equals("ORG")) {
// vCard specification does not specify other types. // vCard specification does not specify other types.
int type = Contacts.OrganizationColumns.TYPE_WORK; int type = Contacts.OrganizationColumns.TYPE_WORK;
String companyName = "";
String positionName = "";
boolean isPrimary = false; boolean isPrimary = false;
for (String typeString : propertyNode.paramMap_TYPE) { for (String typeString : propertyNode.paramMap_TYPE) {
@@ -442,28 +469,19 @@ public class ContactStruct {
List<String> list = propertyNode.propValue_vector; List<String> list = propertyNode.propValue_vector;
int size = list.size(); int size = list.size();
if (size > 1) {
companyName = list.get(0);
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (int i = 1; i < size; i++) { for (Iterator<String> iter = list.iterator(); iter.hasNext();) {
builder.append(list.get(1)); builder.append(iter.next());
if (i != size - 1) { if (iter.hasNext()) {
builder.append(", "); builder.append(' ');
} }
} }
positionName = builder.toString();
} else if (size == 1) { contact.addOrganization(type, builder.toString(), "", isPrimary);
companyName = propertyNode.propValue;
positionName = "";
}
contact.addOrganization(type, companyName, positionName, isPrimary);
} else if (name.equals("TITLE")) { } else if (name.equals("TITLE")) {
contact.title = propertyNode.propValue; contact.setPosition(propertyNode.propValue);
// XXX: What to do this? Isn't ORG enough?
contact.addExtension(propertyNode);
} else if (name.equals("ROLE")) { } else if (name.equals("ROLE")) {
// XXX: What to do this? Isn't ORG enough? contact.setPosition(propertyNode.propValue);
contact.addExtension(propertyNode);
} else if (name.equals("PHOTO")) { } else if (name.equals("PHOTO")) {
// We prefer PHOTO to LOGO. // We prefer PHOTO to LOGO.
String valueType = propertyNode.paramMap.getAsString("VALUE"); String valueType = propertyNode.paramMap.getAsString("VALUE");