diff --git a/framework/assets/js/contact.js b/framework/assets/js/contact.js index 0dda86e5..1d5eb4c0 100644 --- a/framework/assets/js/contact.js +++ b/framework/assets/js/contact.js @@ -2,69 +2,69 @@ var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, addresses, ims, organizations, published, updated, birthday, anniversary, gender, note, preferredUsername, photos, tags, relationships, urls, accounts, utcOffset, connected) { - this.id = id || ''; - this.displayName = displayName || ''; + this.id = id || null; + this.displayName = displayName || null; this.name = name || null; // ContactName - this.nickname = nickname || ''; + this.nickname = nickname || null; this.phoneNumbers = phoneNumbers || null; // ContactField[] this.emails = emails || null; // ContactField[] this.addresses = addresses || null; // ContactAddress[] this.ims = ims || null; // ContactField[] this.organizations = organizations || null; // ContactOrganization[] - this.published = published || ''; - this.updated = updated || ''; - this.birthday = birthday || ''; - this.anniversary = anniversary || ''; - this.gender = gender || ''; - this.note = note || ''; - this.preferredUsername = preferredUsername || ''; + this.published = published || null; + this.updated = updated || null; + this.birthday = birthday || null; + this.anniversary = anniversary || null; + this.gender = gender || null; + this.note = note || null; + this.preferredUsername = preferredUsername || null; this.photos = photos || null; // ContactField[] this.tags = tags || null; // ContactField[] this.relationships = relationships || null; // ContactField[] this.urls = urls || null; // ContactField[] this.accounts = accounts || null; // ContactAccount[] - this.utcOffset = utcOffset || ''; - this.connected = connected || ''; + this.utcOffset = utcOffset || null; + this.connected = connected || null; }; var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) { - this.formatted = formatted || ''; - this.familyName = familyName || ''; - this.givenName = givenName || ''; - this.middleName = middle || ''; - this.honorificPrefix = prefix || ''; - this.honorificSuffix = suffix || ''; + this.formatted = formatted || null; + this.familyName = familyName || null; + this.givenName = givenName || null; + this.middleName = middle || null; + this.honorificPrefix = prefix || null; + this.honorificSuffix = suffix || null; }; var ContactField = function(type, value, primary) { - this.type = type || ''; - this.value = value || ''; - this.primary = primary || ''; + this.type = type || null; + this.value = value || null; + this.primary = primary || null; }; var ContactAddress = function(formatted, streetAddress, locality, region, postalCode, country) { - this.formatted = formatted || ''; - this.streetAddress = streetAddress || ''; - this.locality = locality || ''; - this.region = region || ''; - this.postalCode = postalCode || ''; - this.country = country || ''; + this.formatted = formatted || null; + this.streetAddress = streetAddress || null; + this.locality = locality || null; + this.region = region || null; + this.postalCode = postalCode || null; + this.country = country || null; }; var ContactOrganization = function(name, dept, title, startDate, endDate, location, desc) { - this.name = name || ''; - this.department = dept || ''; - this.title = title || ''; - this.startDate = startDate || ''; - this.endDate = endDate || ''; - this.location = location || ''; - this.description = desc || ''; + this.name = name || null; + this.department = dept || null; + this.title = title || null; + this.startDate = startDate || null; + this.endDate = endDate || null; + this.location = location || null; + this.description = desc || null; }; var ContactAccount = function(domain, username, userid) { - this.domain = domain || ''; - this.username = username || ''; - this.userid = userid || ''; + this.domain = domain || null; + this.username = username || null; + this.userid = userid || null; } var Contacts = function() { diff --git a/framework/assets/www/phonegap.js b/framework/assets/www/phonegap.js index a98a68c2..609722aa 100644 --- a/framework/assets/www/phonegap.js +++ b/framework/assets/www/phonegap.js @@ -830,69 +830,69 @@ PhoneGap.addConstructor(function() { var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, addresses, ims, organizations, published, updated, birthday, anniversary, gender, note, preferredUsername, photos, tags, relationships, urls, accounts, utcOffset, connected) { - this.id = id || ''; - this.displayName = displayName || ''; + this.id = id || null; + this.displayName = displayName || null; this.name = name || null; // ContactName - this.nickname = nickname || ''; + this.nickname = nickname || null; this.phoneNumbers = phoneNumbers || null; // ContactField[] this.emails = emails || null; // ContactField[] this.addresses = addresses || null; // ContactAddress[] this.ims = ims || null; // ContactField[] this.organizations = organizations || null; // ContactOrganization[] - this.published = published || ''; - this.updated = updated || ''; - this.birthday = birthday || ''; - this.anniversary = anniversary || ''; - this.gender = gender || ''; - this.note = note || ''; - this.preferredUsername = preferredUsername || ''; + this.published = published || null; + this.updated = updated || null; + this.birthday = birthday || null; + this.anniversary = anniversary || null; + this.gender = gender || null; + this.note = note || null; + this.preferredUsername = preferredUsername || null; this.photos = photos || null; // ContactField[] this.tags = tags || null; // ContactField[] this.relationships = relationships || null; // ContactField[] this.urls = urls || null; // ContactField[] this.accounts = accounts || null; // ContactAccount[] - this.utcOffset = utcOffset || ''; - this.connected = connected || ''; + this.utcOffset = utcOffset || null; + this.connected = connected || null; }; var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) { - this.formatted = formatted || ''; - this.familyName = familyName || ''; - this.givenName = givenName || ''; - this.middleName = middle || ''; - this.honorificPrefix = prefix || ''; - this.honorificSuffix = suffix || ''; + this.formatted = formatted || null; + this.familyName = familyName || null; + this.givenName = givenName || null; + this.middleName = middle || null; + this.honorificPrefix = prefix || null; + this.honorificSuffix = suffix || null; }; var ContactField = function(type, value, primary) { - this.type = type || ''; - this.value = value || ''; - this.primary = primary || ''; + this.type = type || null; + this.value = value || null; + this.primary = primary || null; }; var ContactAddress = function(formatted, streetAddress, locality, region, postalCode, country) { - this.formatted = formatted || ''; - this.streetAddress = streetAddress || ''; - this.locality = locality || ''; - this.region = region || ''; - this.postalCode = postalCode || ''; - this.country = country || ''; + this.formatted = formatted || null; + this.streetAddress = streetAddress || null; + this.locality = locality || null; + this.region = region || null; + this.postalCode = postalCode || null; + this.country = country || null; }; var ContactOrganization = function(name, dept, title, startDate, endDate, location, desc) { - this.name = name || ''; - this.department = dept || ''; - this.title = title || ''; - this.startDate = startDate || ''; - this.endDate = endDate || ''; - this.location = location || ''; - this.description = desc || ''; + this.name = name || null; + this.department = dept || null; + this.title = title || null; + this.startDate = startDate || null; + this.endDate = endDate || null; + this.location = location || null; + this.description = desc || null; }; var ContactAccount = function(domain, username, userid) { - this.domain = domain || ''; - this.username = username || ''; - this.userid = userid || ''; + this.domain = domain || null; + this.username = username || null; + this.userid = userid || null; } var Contacts = function() { diff --git a/framework/src/com/phonegap/ContactAccessor.java b/framework/src/com/phonegap/ContactAccessor.java index 867fe5e1..ac03c414 100644 --- a/framework/src/com/phonegap/ContactAccessor.java +++ b/framework/src/com/phonegap/ContactAccessor.java @@ -35,13 +35,6 @@ import org.json.JSONObject; */ public abstract class ContactAccessor { - public class ContactTriplet - { - public String name = ""; - public String email = ""; - public String phone = ""; - } - /** * Static singleton instance of {@link ContactAccessor} holding the * SDK-specific implementation of the class. diff --git a/framework/src/com/phonegap/ContactAccessorSdk3_4.java b/framework/src/com/phonegap/ContactAccessorSdk3_4.java index 2f420963..506e8147 100644 --- a/framework/src/com/phonegap/ContactAccessorSdk3_4.java +++ b/framework/src/com/phonegap/ContactAccessorSdk3_4.java @@ -100,7 +100,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor { // ims contact.put("ims", imQuery(cr, contactId)); // note - cur.getString(cur.getColumnIndex(People.NOTES)); + contact.put("note", cur.getString(cur.getColumnIndex(People.NOTES))); // nickname // urls // relationship @@ -128,6 +128,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor { while (cursor.moveToNext()) { im = new JSONObject(); try{ + im.put("primary", false); im.put("value", cursor.getString( cursor.getColumnIndex(ContactMethodsColumns.DATA))); im.put("type", cursor.getString( @@ -198,6 +199,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor { while (cursor.moveToNext()) { phone = new JSONObject(); try{ + phone.put("primary", false); phone.put("value", cursor.getString(cursor.getColumnIndex(Phones.NUMBER))); phone.put("type", cursor.getString(cursor.getColumnIndex(Phones.TYPE))); phones.put(phone); @@ -219,7 +221,9 @@ public class ContactAccessorSdk3_4 extends ContactAccessor { while (cursor.moveToNext()) { email = new JSONObject(); try{ + email.put("primary", false); 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))); emails.put(email); } catch (JSONException e) { diff --git a/framework/src/com/phonegap/ContactAccessorSdk5.java b/framework/src/com/phonegap/ContactAccessorSdk5.java index ee4d4ee3..f2a0ed96 100644 --- a/framework/src/com/phonegap/ContactAccessorSdk5.java +++ b/framework/src/com/phonegap/ContactAccessorSdk5.java @@ -48,6 +48,8 @@ import android.webkit.WebView; */ 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) { mApp = app; @@ -90,10 +92,8 @@ public class ContactAccessorSdk5 extends ContactAccessor { if (contactName.trim().length() == 0) continue; 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 { + contact.put("id", contactId); contact.put("displayName", contactName); contact.put("name", nameQuery(cr, contactId)); contact.put("phoneNumbers", phoneQuery(cr, contactId)); @@ -119,11 +119,10 @@ public class ContactAccessorSdk5 extends ContactAccessor { } private JSONArray organizationQuery(ContentResolver cr, String contactId) { - String orgWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] orgWhereParams = new String[]{contactId, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE}; Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, - null, orgWhere, orgWhereParams, null); + null, WHERE_STRING, orgWhereParams, null); JSONArray organizations = new JSONArray(); JSONObject organization = new JSONObject(); while (cursor.moveToNext()) { @@ -147,11 +146,10 @@ public class ContactAccessorSdk5 extends ContactAccessor { } private JSONArray addressQuery(ContentResolver cr, String contactId) { - String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] addrWhereParams = new String[]{contactId, ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE}; Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, - null, addrWhere, addrWhereParams, null); + null, WHERE_STRING, addrWhereParams, null); JSONArray addresses = new JSONArray(); JSONObject address = new JSONObject(); while (cursor.moveToNext()) { @@ -172,11 +170,10 @@ public class ContactAccessorSdk5 extends ContactAccessor { } private JSONObject nameQuery(ContentResolver cr, String contactId) { - String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] addrWhereParams = new String[]{contactId, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE}; Cursor name = cr.query(ContactsContract.Data.CONTENT_URI, - null, addrWhere, addrWhereParams, null); + null, WHERE_STRING, addrWhereParams, null); JSONObject contactName = new JSONObject(); if (name.moveToFirst()) { try { @@ -240,7 +237,7 @@ public class ContactAccessorSdk5 extends ContactAccessor { JSONObject email = new JSONObject(); while (emails.moveToNext()) { 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("type", emails.getInt(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE))); emailAddresses.put(email); @@ -253,16 +250,15 @@ public class ContactAccessorSdk5 extends ContactAccessor { } private JSONArray imQuery(ContentResolver cr, String contactId) { - String addrWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] addrWhereParams = new String[]{contactId, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE}; Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, - null, addrWhere, addrWhereParams, null); + null, WHERE_STRING, addrWhereParams, null); JSONArray ims = new JSONArray(); JSONObject im = new JSONObject(); while (cursor.moveToNext()) { 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("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.TYPE))); ims.put(im); @@ -275,11 +271,10 @@ public class ContactAccessorSdk5 extends ContactAccessor { } private String noteQuery(ContentResolver cr, String contactId) { - String noteWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] noteWhereParams = new String[]{contactId, ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE}; Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, - null, noteWhere, noteWhereParams, null); + null, WHERE_STRING, noteWhereParams, null); String note = new String(""); if (cursor.moveToFirst()) { 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) { - String nicknameWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] nicknameWhereParams = new String[]{contactId, ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE}; Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, - null, nicknameWhere, nicknameWhereParams, null); + null, WHERE_STRING, nicknameWhereParams, null); String nickname = new String(""); if (cursor.moveToFirst()) { 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) { - String websiteWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] websiteWhereParams = new String[]{contactId, ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE}; Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, - null, websiteWhere, websiteWhereParams, null); + null, WHERE_STRING, websiteWhereParams, null); JSONArray websites = new JSONArray(); JSONObject website = new JSONObject(); while (cursor.moveToNext()) { 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("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.TYPE))); websites.put(website); @@ -325,16 +318,15 @@ public class ContactAccessorSdk5 extends ContactAccessor { } private JSONArray relationshipQuery(ContentResolver cr, String contactId) { - String relationshipWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] relationshipWhereParams = new String[]{contactId, ContactsContract.CommonDataKinds.Relation.CONTENT_ITEM_TYPE}; Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, - null, relationshipWhere, relationshipWhereParams, null); + null, WHERE_STRING, relationshipWhereParams, null); JSONArray relationships = new JSONArray(); JSONObject relationship = new JSONObject(); while (cursor.moveToNext()) { 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("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Relation.TYPE))); 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) { - String where = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; String[] whereParams = new String[]{contactId, dataType}; Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI, - null, where, whereParams, null); + null, WHERE_STRING, whereParams, null); String retVal = new String(""); while (cursor.moveToNext()) { if (type == cursor.getInt(cursor.getColumnIndex(label))) { diff --git a/framework/src/com/phonegap/ContactManager.java b/framework/src/com/phonegap/ContactManager.java index 2882cb60..9cf6a891 100755 --- a/framework/src/com/phonegap/ContactManager.java +++ b/framework/src/com/phonegap/ContactManager.java @@ -59,20 +59,18 @@ public class ContactManager implements Plugin { String result = ""; try { - //if (action.equals("getContactsAndSendBack")) { - // contactAccessor.getContactsAndSendBack(); - //} - //else 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)); } + 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); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e);