Fixing Contacts.find to use PluginResult

This commit is contained in:
macdonst 2010-10-04 09:47:12 +08:00
parent c80397ad68
commit 2bbf62c489
7 changed files with 17 additions and 16 deletions

View File

@ -94,10 +94,7 @@ var Contacts = function() {
} }
Contacts.prototype.find = function(fields, win, fail, options) { Contacts.prototype.find = function(fields, win, fail, options) {
this.win = win; PhoneGap.execAsync(win, fail, "Contacts", "search", [fields, options]);
this.fail = fail;
PhoneGap.execAsync(null, null, "Contacts", "search", [fields, options]);
}; };
//This function does not create a new contact in the db. //This function does not create a new contact in the db.

View File

@ -1043,10 +1043,7 @@ var Contacts = function() {
} }
Contacts.prototype.find = function(fields, win, fail, options) { Contacts.prototype.find = function(fields, win, fail, options) {
this.win = win; PhoneGap.execAsync(win, fail, "Contacts", "search", [fields, options]);
this.fail = fail;
PhoneGap.execAsync(null, null, "Contacts", "search", [fields, options]);
}; };
//This function does not create a new contact in the db. //This function does not create a new contact in the db.

View File

@ -91,7 +91,7 @@ public abstract class ContactAccessor {
/** /**
* Handles searching through SDK-specific contacts API. * 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. * Handles removing a contact from the database.

View File

@ -31,7 +31,6 @@ import android.app.Activity;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.Contacts.ContactMethods; import android.provider.Contacts.ContactMethods;
import android.provider.Contacts.ContactMethodsColumns; import android.provider.Contacts.ContactMethodsColumns;
import android.provider.Contacts.Organizations; import android.provider.Contacts.Organizations;
@ -80,7 +79,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
} }
@Override @Override
public void search(JSONArray filter, JSONObject options) { public JSONArray search(JSONArray filter, JSONObject options) {
String searchTerm = ""; String searchTerm = "";
int limit = Integer.MAX_VALUE; int limit = Integer.MAX_VALUE;
boolean multiple = true; boolean multiple = true;
@ -152,7 +151,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
} }
contacts.put(contact); contacts.put(contact);
} }
mView.loadUrl("javascript:navigator.service.contacts.droidDone('" + contacts.toString() + "');"); return contacts;
} }
private Set<String> buildSetOfContactIds(JSONArray filter, String searchTerm) { private Set<String> buildSetOfContactIds(JSONArray filter, String searchTerm) {

View File

@ -114,7 +114,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} }
@Override @Override
public void search(JSONArray filter, JSONObject options) { public JSONArray search(JSONArray filter, JSONObject options) {
String searchTerm = ""; String searchTerm = "";
int limit = Integer.MAX_VALUE; int limit = Integer.MAX_VALUE;
boolean multiple = true; boolean multiple = true;
@ -166,11 +166,12 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
} }
Log.d(LOG_TAG, "putting in contact ID = " + contactId);
contacts.put(contact); contacts.put(contact);
pos++; pos++;
} }
mView.loadUrl("javascript:navigator.service.contacts.droidDone('" + contacts.toString() + "');"); return contacts;
} }
private Set<String> buildSetOfContactIds(JSONArray filter, String searchTerm) { private Set<String> buildSetOfContactIds(JSONArray filter, String searchTerm) {

View File

@ -61,7 +61,8 @@ public class ContactManager implements Plugin {
try { try {
if (action.equals("search")) { 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")) { else if (action.equals("create")) {
// TODO Coming soon! // TODO Coming soon!

View File

@ -1,5 +1,6 @@
package com.phonegap.api; package com.phonegap.api;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
public class PluginResult { public class PluginResult {
@ -16,6 +17,11 @@ public class PluginResult {
this.message = "'" + message + "'"; this.message = "'" + message + "'";
} }
public PluginResult(Status status, JSONArray message) {
this.status = status.ordinal();
this.message = message.toString();
}
public PluginResult(Status status, JSONObject message) { public PluginResult(Status status, JSONObject message) {
this.status = status.ordinal(); this.status = status.ordinal();
this.message = message.toString(); this.message = message.toString();