diff --git a/framework/assets/js/contact.js b/framework/assets/js/contact.js index 1ebe89a7..2d735027 100644 --- a/framework/assets/js/contact.js +++ b/framework/assets/js/contact.js @@ -94,10 +94,7 @@ var Contacts = function() { } Contacts.prototype.find = function(fields, win, fail, options) { - this.win = win; - this.fail = fail; - - PhoneGap.execAsync(null, null, "Contacts", "search", [fields, options]); + PhoneGap.execAsync(win, fail, "Contacts", "search", [fields, options]); }; //This function does not create a new contact in the db. diff --git a/framework/assets/www/phonegap.js b/framework/assets/www/phonegap.js index 839ba758..8aa92570 100644 --- a/framework/assets/www/phonegap.js +++ b/framework/assets/www/phonegap.js @@ -1043,10 +1043,7 @@ var Contacts = function() { } Contacts.prototype.find = function(fields, win, fail, options) { - this.win = win; - this.fail = fail; - - PhoneGap.execAsync(null, null, "Contacts", "search", [fields, options]); + PhoneGap.execAsync(win, fail, "Contacts", "search", [fields, options]); }; //This function does not create a new contact in the db. diff --git a/framework/src/com/phonegap/ContactAccessor.java b/framework/src/com/phonegap/ContactAccessor.java index 0fc02b41..5e7ccde9 100644 --- a/framework/src/com/phonegap/ContactAccessor.java +++ b/framework/src/com/phonegap/ContactAccessor.java @@ -91,7 +91,7 @@ public abstract class ContactAccessor { /** * Handles searching through SDK-specific contacts API. */ - public abstract void search(JSONArray filter, JSONObject options); + public abstract JSONArray search(JSONArray filter, JSONObject options); /** * Handles removing a contact from the database. diff --git a/framework/src/com/phonegap/ContactAccessorSdk3_4.java b/framework/src/com/phonegap/ContactAccessorSdk3_4.java index 7e43ec2a..9feeba7c 100644 --- a/framework/src/com/phonegap/ContactAccessorSdk3_4.java +++ b/framework/src/com/phonegap/ContactAccessorSdk3_4.java @@ -31,7 +31,6 @@ import android.app.Activity; import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; -import android.provider.ContactsContract; import android.provider.Contacts.ContactMethods; import android.provider.Contacts.ContactMethodsColumns; import android.provider.Contacts.Organizations; @@ -80,7 +79,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor { } @Override - public void search(JSONArray filter, JSONObject options) { + public JSONArray search(JSONArray filter, JSONObject options) { String searchTerm = ""; int limit = Integer.MAX_VALUE; boolean multiple = true; @@ -152,7 +151,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor { } contacts.put(contact); } - mView.loadUrl("javascript:navigator.service.contacts.droidDone('" + contacts.toString() + "');"); + return contacts; } private Set buildSetOfContactIds(JSONArray filter, String searchTerm) { diff --git a/framework/src/com/phonegap/ContactAccessorSdk5.java b/framework/src/com/phonegap/ContactAccessorSdk5.java index a99a6d7e..58639cdc 100644 --- a/framework/src/com/phonegap/ContactAccessorSdk5.java +++ b/framework/src/com/phonegap/ContactAccessorSdk5.java @@ -114,7 +114,7 @@ public class ContactAccessorSdk5 extends ContactAccessor { } @Override - public void search(JSONArray filter, JSONObject options) { + public JSONArray search(JSONArray filter, JSONObject options) { String searchTerm = ""; int limit = Integer.MAX_VALUE; boolean multiple = true; @@ -166,11 +166,12 @@ public class ContactAccessorSdk5 extends ContactAccessor { } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } + Log.d(LOG_TAG, "putting in contact ID = " + contactId); contacts.put(contact); pos++; - } - mView.loadUrl("javascript:navigator.service.contacts.droidDone('" + contacts.toString() + "');"); + } + return contacts; } private Set buildSetOfContactIds(JSONArray filter, String searchTerm) { diff --git a/framework/src/com/phonegap/ContactManager.java b/framework/src/com/phonegap/ContactManager.java index 38cc899e..7f35056d 100755 --- a/framework/src/com/phonegap/ContactManager.java +++ b/framework/src/com/phonegap/ContactManager.java @@ -61,7 +61,8 @@ public class ContactManager implements Plugin { try { if (action.equals("search")) { - contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1)); + JSONArray res = contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1)); + return new PluginResult(status, res); } else if (action.equals("create")) { // TODO Coming soon! diff --git a/framework/src/com/phonegap/api/PluginResult.java b/framework/src/com/phonegap/api/PluginResult.java index 777f2605..7523bfe7 100755 --- a/framework/src/com/phonegap/api/PluginResult.java +++ b/framework/src/com/phonegap/api/PluginResult.java @@ -1,5 +1,6 @@ package com.phonegap.api; +import org.json.JSONArray; import org.json.JSONObject; public class PluginResult { @@ -16,6 +17,11 @@ public class PluginResult { this.message = "'" + message + "'"; } + public PluginResult(Status status, JSONArray message) { + this.status = status.ordinal(); + this.message = message.toString(); + } + public PluginResult(Status status, JSONObject message) { this.status = status.ordinal(); this.message = message.toString();