mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
Fixing Contacts.find to use PluginResult
This commit is contained in:
parent
c80397ad68
commit
2bbf62c489
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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<String> buildSetOfContactIds(JSONArray filter, String searchTerm) {
|
||||
|
@ -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<String> buildSetOfContactIds(JSONArray filter, String searchTerm) {
|
||||
|
@ -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!
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user