Cleaning up some accessor code

This commit is contained in:
macdonst 2010-09-24 11:43:10 -04:00
parent 4e4207f294
commit a9f057c278
6 changed files with 104 additions and 118 deletions

View File

@ -2,69 +2,69 @@
var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, addresses, var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, addresses,
ims, organizations, published, updated, birthday, anniversary, gender, note, ims, organizations, published, updated, birthday, anniversary, gender, note,
preferredUsername, photos, tags, relationships, urls, accounts, utcOffset, connected) { preferredUsername, photos, tags, relationships, urls, accounts, utcOffset, connected) {
this.id = id || ''; this.id = id || null;
this.displayName = displayName || ''; this.displayName = displayName || null;
this.name = name || null; // ContactName this.name = name || null; // ContactName
this.nickname = nickname || ''; this.nickname = nickname || null;
this.phoneNumbers = phoneNumbers || null; // ContactField[] this.phoneNumbers = phoneNumbers || null; // ContactField[]
this.emails = emails || null; // ContactField[] this.emails = emails || null; // ContactField[]
this.addresses = addresses || null; // ContactAddress[] this.addresses = addresses || null; // ContactAddress[]
this.ims = ims || null; // ContactField[] this.ims = ims || null; // ContactField[]
this.organizations = organizations || null; // ContactOrganization[] this.organizations = organizations || null; // ContactOrganization[]
this.published = published || ''; this.published = published || null;
this.updated = updated || ''; this.updated = updated || null;
this.birthday = birthday || ''; this.birthday = birthday || null;
this.anniversary = anniversary || ''; this.anniversary = anniversary || null;
this.gender = gender || ''; this.gender = gender || null;
this.note = note || ''; this.note = note || null;
this.preferredUsername = preferredUsername || ''; this.preferredUsername = preferredUsername || null;
this.photos = photos || null; // ContactField[] this.photos = photos || null; // ContactField[]
this.tags = tags || null; // ContactField[] this.tags = tags || null; // ContactField[]
this.relationships = relationships || null; // ContactField[] this.relationships = relationships || null; // ContactField[]
this.urls = urls || null; // ContactField[] this.urls = urls || null; // ContactField[]
this.accounts = accounts || null; // ContactAccount[] this.accounts = accounts || null; // ContactAccount[]
this.utcOffset = utcOffset || ''; this.utcOffset = utcOffset || null;
this.connected = connected || ''; this.connected = connected || null;
}; };
var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) { var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) {
this.formatted = formatted || ''; this.formatted = formatted || null;
this.familyName = familyName || ''; this.familyName = familyName || null;
this.givenName = givenName || ''; this.givenName = givenName || null;
this.middleName = middle || ''; this.middleName = middle || null;
this.honorificPrefix = prefix || ''; this.honorificPrefix = prefix || null;
this.honorificSuffix = suffix || ''; this.honorificSuffix = suffix || null;
}; };
var ContactField = function(type, value, primary) { var ContactField = function(type, value, primary) {
this.type = type || ''; this.type = type || null;
this.value = value || ''; this.value = value || null;
this.primary = primary || ''; this.primary = primary || null;
}; };
var ContactAddress = function(formatted, streetAddress, locality, region, postalCode, country) { var ContactAddress = function(formatted, streetAddress, locality, region, postalCode, country) {
this.formatted = formatted || ''; this.formatted = formatted || null;
this.streetAddress = streetAddress || ''; this.streetAddress = streetAddress || null;
this.locality = locality || ''; this.locality = locality || null;
this.region = region || ''; this.region = region || null;
this.postalCode = postalCode || ''; this.postalCode = postalCode || null;
this.country = country || ''; this.country = country || null;
}; };
var ContactOrganization = function(name, dept, title, startDate, endDate, location, desc) { var ContactOrganization = function(name, dept, title, startDate, endDate, location, desc) {
this.name = name || ''; this.name = name || null;
this.department = dept || ''; this.department = dept || null;
this.title = title || ''; this.title = title || null;
this.startDate = startDate || ''; this.startDate = startDate || null;
this.endDate = endDate || ''; this.endDate = endDate || null;
this.location = location || ''; this.location = location || null;
this.description = desc || ''; this.description = desc || null;
}; };
var ContactAccount = function(domain, username, userid) { var ContactAccount = function(domain, username, userid) {
this.domain = domain || ''; this.domain = domain || null;
this.username = username || ''; this.username = username || null;
this.userid = userid || ''; this.userid = userid || null;
} }
var Contacts = function() { var Contacts = function() {

View File

@ -830,69 +830,69 @@ PhoneGap.addConstructor(function() {
var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, addresses, var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, addresses,
ims, organizations, published, updated, birthday, anniversary, gender, note, ims, organizations, published, updated, birthday, anniversary, gender, note,
preferredUsername, photos, tags, relationships, urls, accounts, utcOffset, connected) { preferredUsername, photos, tags, relationships, urls, accounts, utcOffset, connected) {
this.id = id || ''; this.id = id || null;
this.displayName = displayName || ''; this.displayName = displayName || null;
this.name = name || null; // ContactName this.name = name || null; // ContactName
this.nickname = nickname || ''; this.nickname = nickname || null;
this.phoneNumbers = phoneNumbers || null; // ContactField[] this.phoneNumbers = phoneNumbers || null; // ContactField[]
this.emails = emails || null; // ContactField[] this.emails = emails || null; // ContactField[]
this.addresses = addresses || null; // ContactAddress[] this.addresses = addresses || null; // ContactAddress[]
this.ims = ims || null; // ContactField[] this.ims = ims || null; // ContactField[]
this.organizations = organizations || null; // ContactOrganization[] this.organizations = organizations || null; // ContactOrganization[]
this.published = published || ''; this.published = published || null;
this.updated = updated || ''; this.updated = updated || null;
this.birthday = birthday || ''; this.birthday = birthday || null;
this.anniversary = anniversary || ''; this.anniversary = anniversary || null;
this.gender = gender || ''; this.gender = gender || null;
this.note = note || ''; this.note = note || null;
this.preferredUsername = preferredUsername || ''; this.preferredUsername = preferredUsername || null;
this.photos = photos || null; // ContactField[] this.photos = photos || null; // ContactField[]
this.tags = tags || null; // ContactField[] this.tags = tags || null; // ContactField[]
this.relationships = relationships || null; // ContactField[] this.relationships = relationships || null; // ContactField[]
this.urls = urls || null; // ContactField[] this.urls = urls || null; // ContactField[]
this.accounts = accounts || null; // ContactAccount[] this.accounts = accounts || null; // ContactAccount[]
this.utcOffset = utcOffset || ''; this.utcOffset = utcOffset || null;
this.connected = connected || ''; this.connected = connected || null;
}; };
var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) { var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) {
this.formatted = formatted || ''; this.formatted = formatted || null;
this.familyName = familyName || ''; this.familyName = familyName || null;
this.givenName = givenName || ''; this.givenName = givenName || null;
this.middleName = middle || ''; this.middleName = middle || null;
this.honorificPrefix = prefix || ''; this.honorificPrefix = prefix || null;
this.honorificSuffix = suffix || ''; this.honorificSuffix = suffix || null;
}; };
var ContactField = function(type, value, primary) { var ContactField = function(type, value, primary) {
this.type = type || ''; this.type = type || null;
this.value = value || ''; this.value = value || null;
this.primary = primary || ''; this.primary = primary || null;
}; };
var ContactAddress = function(formatted, streetAddress, locality, region, postalCode, country) { var ContactAddress = function(formatted, streetAddress, locality, region, postalCode, country) {
this.formatted = formatted || ''; this.formatted = formatted || null;
this.streetAddress = streetAddress || ''; this.streetAddress = streetAddress || null;
this.locality = locality || ''; this.locality = locality || null;
this.region = region || ''; this.region = region || null;
this.postalCode = postalCode || ''; this.postalCode = postalCode || null;
this.country = country || ''; this.country = country || null;
}; };
var ContactOrganization = function(name, dept, title, startDate, endDate, location, desc) { var ContactOrganization = function(name, dept, title, startDate, endDate, location, desc) {
this.name = name || ''; this.name = name || null;
this.department = dept || ''; this.department = dept || null;
this.title = title || ''; this.title = title || null;
this.startDate = startDate || ''; this.startDate = startDate || null;
this.endDate = endDate || ''; this.endDate = endDate || null;
this.location = location || ''; this.location = location || null;
this.description = desc || ''; this.description = desc || null;
}; };
var ContactAccount = function(domain, username, userid) { var ContactAccount = function(domain, username, userid) {
this.domain = domain || ''; this.domain = domain || null;
this.username = username || ''; this.username = username || null;
this.userid = userid || ''; this.userid = userid || null;
} }
var Contacts = function() { var Contacts = function() {

View File

@ -35,13 +35,6 @@ import org.json.JSONObject;
*/ */
public abstract class ContactAccessor { public abstract class ContactAccessor {
public class ContactTriplet
{
public String name = "";
public String email = "";
public String phone = "";
}
/** /**
* Static singleton instance of {@link ContactAccessor} holding the * Static singleton instance of {@link ContactAccessor} holding the
* SDK-specific implementation of the class. * SDK-specific implementation of the class.

View File

@ -100,7 +100,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
// ims // ims
contact.put("ims", imQuery(cr, contactId)); contact.put("ims", imQuery(cr, contactId));
// note // note
cur.getString(cur.getColumnIndex(People.NOTES)); contact.put("note", cur.getString(cur.getColumnIndex(People.NOTES)));
// nickname // nickname
// urls // urls
// relationship // relationship
@ -128,6 +128,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
im = new JSONObject(); im = new JSONObject();
try{ try{
im.put("primary", false);
im.put("value", cursor.getString( im.put("value", cursor.getString(
cursor.getColumnIndex(ContactMethodsColumns.DATA))); cursor.getColumnIndex(ContactMethodsColumns.DATA)));
im.put("type", cursor.getString( im.put("type", cursor.getString(
@ -198,6 +199,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
phone = new JSONObject(); phone = new JSONObject();
try{ try{
phone.put("primary", false);
phone.put("value", cursor.getString(cursor.getColumnIndex(Phones.NUMBER))); phone.put("value", cursor.getString(cursor.getColumnIndex(Phones.NUMBER)));
phone.put("type", cursor.getString(cursor.getColumnIndex(Phones.TYPE))); phone.put("type", cursor.getString(cursor.getColumnIndex(Phones.TYPE)));
phones.put(phone); phones.put(phone);
@ -219,7 +221,9 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
email = new JSONObject(); email = new JSONObject();
try{ try{
email.put("primary", false);
email.put("value", cursor.getString(cursor.getColumnIndex(ContactMethods.DATA))); email.put("value", cursor.getString(cursor.getColumnIndex(ContactMethods.DATA)));
// TODO Find out why adding an email type throws and exception
//email.put("type", cursor.getString(cursor.getColumnIndex(ContactMethods.TYPE))); //email.put("type", cursor.getString(cursor.getColumnIndex(ContactMethods.TYPE)));
emails.put(email); emails.put(email);
} catch (JSONException e) { } catch (JSONException e) {

View File

@ -48,6 +48,8 @@ import android.webkit.WebView;
*/ */
public class ContactAccessorSdk5 extends ContactAccessor { public class ContactAccessorSdk5 extends ContactAccessor {
private static final String WHERE_STRING = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
public ContactAccessorSdk5(WebView view, Activity app) public ContactAccessorSdk5(WebView view, Activity app)
{ {
mApp = app; mApp = app;
@ -90,10 +92,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
if (contactName.trim().length() == 0) continue; if (contactName.trim().length() == 0) continue;
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
//String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
//if (Boolean.parseBoolean(hasPhone)) {
//}
try { try {
contact.put("id", contactId);
contact.put("displayName", contactName); contact.put("displayName", contactName);
contact.put("name", nameQuery(cr, contactId)); contact.put("name", nameQuery(cr, contactId));
contact.put("phoneNumbers", phoneQuery(cr, contactId)); contact.put("phoneNumbers", phoneQuery(cr, contactId));
@ -119,11 +119,10 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
private JSONArray organizationQuery(ContentResolver cr, String contactId) { private JSONArray organizationQuery(ContentResolver cr, String contactId) {
String orgWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] orgWhereParams = new String[]{contactId, String[] orgWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE}; ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
null, orgWhere, orgWhereParams, null); null, WHERE_STRING, orgWhereParams, null);
JSONArray organizations = new JSONArray(); JSONArray organizations = new JSONArray();
JSONObject organization = new JSONObject(); JSONObject organization = new JSONObject();
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
@ -147,11 +146,10 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
private JSONArray addressQuery(ContentResolver cr, String contactId) { private JSONArray addressQuery(ContentResolver cr, String contactId) {
String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] addrWhereParams = new String[]{contactId, String[] addrWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE}; ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
null, addrWhere, addrWhereParams, null); null, WHERE_STRING, addrWhereParams, null);
JSONArray addresses = new JSONArray(); JSONArray addresses = new JSONArray();
JSONObject address = new JSONObject(); JSONObject address = new JSONObject();
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
@ -172,11 +170,10 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
private JSONObject nameQuery(ContentResolver cr, String contactId) { private JSONObject nameQuery(ContentResolver cr, String contactId) {
String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] addrWhereParams = new String[]{contactId, String[] addrWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE}; ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE};
Cursor name = cr.query(ContactsContract.Data.CONTENT_URI, Cursor name = cr.query(ContactsContract.Data.CONTENT_URI,
null, addrWhere, addrWhereParams, null); null, WHERE_STRING, addrWhereParams, null);
JSONObject contactName = new JSONObject(); JSONObject contactName = new JSONObject();
if (name.moveToFirst()) { if (name.moveToFirst()) {
try { try {
@ -240,7 +237,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
JSONObject email = new JSONObject(); JSONObject email = new JSONObject();
while (emails.moveToNext()) { while (emails.moveToNext()) {
try { try {
email.put("primary", false); email.put("primary", false); // Android does not store primary attribute
email.put("value", emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA))); email.put("value", emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)));
email.put("type", emails.getInt(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE))); email.put("type", emails.getInt(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)));
emailAddresses.put(email); emailAddresses.put(email);
@ -253,16 +250,15 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
private JSONArray imQuery(ContentResolver cr, String contactId) { private JSONArray imQuery(ContentResolver cr, String contactId) {
String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] addrWhereParams = new String[]{contactId, String[] addrWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE}; ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
null, addrWhere, addrWhereParams, null); null, WHERE_STRING, addrWhereParams, null);
JSONArray ims = new JSONArray(); JSONArray ims = new JSONArray();
JSONObject im = new JSONObject(); JSONObject im = new JSONObject();
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
try { try {
im.put("primary", false); im.put("primary", false); // Android does not store primary attribute
im.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA))); im.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
im.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.TYPE))); im.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.TYPE)));
ims.put(im); ims.put(im);
@ -275,11 +271,10 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
private String noteQuery(ContentResolver cr, String contactId) { private String noteQuery(ContentResolver cr, String contactId) {
String noteWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] noteWhereParams = new String[]{contactId, String[] noteWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE}; ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
null, noteWhere, noteWhereParams, null); null, WHERE_STRING, noteWhereParams, null);
String note = new String(""); String note = new String("");
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
note = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE)); note = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
@ -289,11 +284,10 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
private String nicknameQuery(ContentResolver cr, String contactId) { private String nicknameQuery(ContentResolver cr, String contactId) {
String nicknameWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] nicknameWhereParams = new String[]{contactId, String[] nicknameWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE}; ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
null, nicknameWhere, nicknameWhereParams, null); null, WHERE_STRING, nicknameWhereParams, null);
String nickname = new String(""); String nickname = new String("");
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
nickname = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME)); nickname = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME));
@ -303,16 +297,15 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
private JSONArray websiteQuery(ContentResolver cr, String contactId) { private JSONArray websiteQuery(ContentResolver cr, String contactId) {
String websiteWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] websiteWhereParams = new String[]{contactId, String[] websiteWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE}; ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
null, websiteWhere, websiteWhereParams, null); null, WHERE_STRING, websiteWhereParams, null);
JSONArray websites = new JSONArray(); JSONArray websites = new JSONArray();
JSONObject website = new JSONObject(); JSONObject website = new JSONObject();
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
try { try {
website.put("primary", false); website.put("primary", false); // Android does not store primary attribute
website.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.URL))); website.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.URL)));
website.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.TYPE))); website.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.TYPE)));
websites.put(website); websites.put(website);
@ -325,16 +318,15 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
private JSONArray relationshipQuery(ContentResolver cr, String contactId) { private JSONArray relationshipQuery(ContentResolver cr, String contactId) {
String relationshipWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] relationshipWhereParams = new String[]{contactId, String[] relationshipWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Relation.CONTENT_ITEM_TYPE}; ContactsContract.CommonDataKinds.Relation.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
null, relationshipWhere, relationshipWhereParams, null); null, WHERE_STRING, relationshipWhereParams, null);
JSONArray relationships = new JSONArray(); JSONArray relationships = new JSONArray();
JSONObject relationship = new JSONObject(); JSONObject relationship = new JSONObject();
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
try { try {
relationship.put("primary", false); relationship.put("primary", false); // Android does not store primary attribute
relationship.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Relation.NAME))); relationship.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Relation.NAME)));
relationship.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Relation.TYPE))); relationship.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Relation.TYPE)));
relationships.put(relationship); relationships.put(relationship);
@ -361,10 +353,9 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
private String conditionalStringQuery(ContentResolver cr, String contactId, String dataType, int type, String label, String data) { private String conditionalStringQuery(ContentResolver cr, String contactId, String dataType, int type, String label, String data) {
String where = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] whereParams = new String[]{contactId, dataType}; String[] whereParams = new String[]{contactId, dataType};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
null, where, whereParams, null); null, WHERE_STRING, whereParams, null);
String retVal = new String(""); String retVal = new String("");
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
if (type == cursor.getInt(cursor.getColumnIndex(label))) { if (type == cursor.getInt(cursor.getColumnIndex(label))) {

View File

@ -59,20 +59,18 @@ public class ContactManager implements Plugin {
String result = ""; String result = "";
try { try {
//if (action.equals("getContactsAndSendBack")) {
// contactAccessor.getContactsAndSendBack();
//}
//else if (action.equals("search")) {
if (action.equals("search")) { if (action.equals("search")) {
Log.d(LOG_TAG, "*** Calling search of " + contactAccessor.getClass().getName());
Log.d(LOG_TAG, "what is 0 " + args.get(0).getClass().toString());
Log.d(LOG_TAG, "what is 0 " + args.get(0).toString());
Log.d(LOG_TAG, "what is 1 " + args.get(1).getClass().toString());
Log.d(LOG_TAG, "what is 1 " + args.get(1).toString());
Log.d(LOG_TAG, "Fields = " + args.getJSONArray(0).toString());
Log.d(LOG_TAG, "Options = " + args.getJSONObject(1).toString());
contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1)); contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1));
} }
else if (action.equals("create")) {
// TODO Coming soon!
}
else if (action.equals("save")) {
// TODO Coming soon!
}
else if (action.equals("remove")) {
// TODO Coming soon!
}
return new PluginResult(status, result); return new PluginResult(status, result);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);