diff --git a/example/index.html b/example/index.html index bdfee7c3..ecf05ee7 100644 --- a/example/index.html +++ b/example/index.html @@ -104,6 +104,7 @@ var obj = new ContactFindOptions(); obj.filter=""; obj.multiple=true; + obj.limit=5; navigator.service.contacts.find(["displayName", "phoneNumbers", "emails"], count_contacts, fail, obj); } diff --git a/framework/src/com/phonegap/ContactAccessor.java b/framework/src/com/phonegap/ContactAccessor.java index 5e7ccde9..b2a1843c 100644 --- a/framework/src/com/phonegap/ContactAccessor.java +++ b/framework/src/com/phonegap/ContactAccessor.java @@ -86,7 +86,7 @@ public abstract class ContactAccessor { /** * Handles adding a JSON Contact object into the database. */ - public abstract void save(); + public abstract void save(JSONObject contact); /** * Handles searching through SDK-specific contacts API. diff --git a/framework/src/com/phonegap/ContactAccessorSdk3_4.java b/framework/src/com/phonegap/ContactAccessorSdk3_4.java index 9feeba7c..c64d105b 100644 --- a/framework/src/com/phonegap/ContactAccessorSdk3_4.java +++ b/framework/src/com/phonegap/ContactAccessorSdk3_4.java @@ -361,7 +361,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor { } @Override - public void save() { + public void save(JSONObject contact) { // TODO Auto-generated method stub } diff --git a/framework/src/com/phonegap/ContactAccessorSdk5.java b/framework/src/com/phonegap/ContactAccessorSdk5.java index 58639cdc..fa2047ad 100644 --- a/framework/src/com/phonegap/ContactAccessorSdk5.java +++ b/framework/src/com/phonegap/ContactAccessorSdk5.java @@ -107,14 +107,17 @@ public class ContactAccessorSdk5 extends ContactAccessor { //dbMap.put("connected", null); } - public ContactAccessorSdk5(WebView view, Activity app) - { + public ContactAccessorSdk5(WebView view, Activity app) { mApp = app; mView = view; } @Override public JSONArray search(JSONArray filter, JSONObject options) { + long totalEnd; + long totalStart = System.currentTimeMillis(); + long start = System.currentTimeMillis(); + long stop; String searchTerm = ""; int limit = Integer.MAX_VALUE; boolean multiple = true; @@ -133,11 +136,19 @@ public class ContactAccessorSdk5 extends ContactAccessor { } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } + stop = System.currentTimeMillis(); + Log.d(LOG_TAG, "Parsing parameters took = " + (stop-start)); + start = System.currentTimeMillis(); + // Get a cursor by creating the query. ContentResolver cr = mApp.getContentResolver(); Set contactIds = buildSetOfContactIds(filter, searchTerm); + stop = System.currentTimeMillis(); + Log.d(LOG_TAG, "Building contact ID's took = " + (stop-start)); + start = System.currentTimeMillis(); + Iterator it = contactIds.iterator(); JSONArray contacts = new JSONArray(); @@ -171,12 +182,28 @@ public class ContactAccessorSdk5 extends ContactAccessor { contacts.put(contact); pos++; } + stop = System.currentTimeMillis(); + totalEnd = System.currentTimeMillis(); + Log.d(LOG_TAG, "Populating contact Array took = " + (stop - start)); + Log.d(LOG_TAG, "Total search took = " + (totalEnd - totalStart)); return contacts; } private Set buildSetOfContactIds(JSONArray filter, String searchTerm) { Set contactIds = new HashSet(); + /* + * Special case for when the user wants all the contacts + */ + if ("%".equals(searchTerm)) { + doQuery(searchTerm, contactIds, + ContactsContract.Contacts.CONTENT_URI, + ContactsContract.Contacts._ID, + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?", + new String[] {searchTerm}); + return contactIds; + } + String key; try { for (int i=0; i