mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 03:53:09 +08:00
Merge branch 'master' of github.com:phonegap/phonegap-android
This commit is contained in:
commit
f8ae11993f
@ -104,6 +104,7 @@
|
|||||||
var obj = new ContactFindOptions();
|
var obj = new ContactFindOptions();
|
||||||
obj.filter="";
|
obj.filter="";
|
||||||
obj.multiple=true;
|
obj.multiple=true;
|
||||||
|
obj.limit=5;
|
||||||
navigator.service.contacts.find(["displayName", "phoneNumbers", "emails"], count_contacts, fail, obj);
|
navigator.service.contacts.find(["displayName", "phoneNumbers", "emails"], count_contacts, fail, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallb
|
|||||||
Accelerometer.prototype.clearWatch = function(id) {
|
Accelerometer.prototype.clearWatch = function(id) {
|
||||||
|
|
||||||
// Stop javascript timer & remove from timer list
|
// Stop javascript timer & remove from timer list
|
||||||
if (id && navigator.accelerometer.timers[id]) {
|
if (id && navigator.accelerometer.timers[id] != undefined) {
|
||||||
clearInterval(navigator.accelerometer.timers[id]);
|
clearInterval(navigator.accelerometer.timers[id]);
|
||||||
delete navigator.accelerometer.timers[id];
|
delete navigator.accelerometer.timers[id];
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,27 @@ var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, ad
|
|||||||
this.connected = connected || null;
|
this.connected = connected || null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Contact.prototype.remove = function(successCB, errorCB) {
|
||||||
|
if (this.id == null) {
|
||||||
|
var errorObj = new ContactError();
|
||||||
|
errorObj.code = ContactError.NOT_FOUND_ERROR;
|
||||||
|
errorCB(errorObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
PhoneGap.execAsync(successCB, errorCB, "Contacts", "remove", [this.id]);
|
||||||
|
};
|
||||||
|
|
||||||
|
Contact.prototype.clone = function() {
|
||||||
|
var clonedContact = PhoneGap.clone(this);
|
||||||
|
clonedContact.id = null;
|
||||||
|
return clonedContact;
|
||||||
|
};
|
||||||
|
|
||||||
|
Contact.prototype.save = function(win, fail) {
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) {
|
var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) {
|
||||||
this.formatted = formatted || null;
|
this.formatted = formatted || null;
|
||||||
this.familyName = familyName || null;
|
this.familyName = familyName || null;
|
||||||
@ -72,30 +93,26 @@ var Contacts = function() {
|
|||||||
this.records = new Array();
|
this.records = new Array();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contacts.prototype.find = function(obj, win, fail) {
|
|
||||||
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.
|
||||||
|
//Must call contact.save() for it to be persisted in the db.
|
||||||
|
Contacts.prototype.create = function(properties) {
|
||||||
|
var contact = new Contact();
|
||||||
|
for (i in properties) {
|
||||||
|
if (contact[i]!='undefined') {
|
||||||
|
contact[i]=properties[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return contact;
|
||||||
};
|
};
|
||||||
|
|
||||||
Contacts.prototype.droidDone = function(contacts) {
|
Contacts.prototype.droidDone = function(contacts) {
|
||||||
this.win(eval('(' + contacts + ')'));
|
this.win(eval('(' + contacts + ')'));
|
||||||
};
|
};
|
||||||
|
|
||||||
Contacts.prototype.remove = function(contact) {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Contacts.prototype.save = function(contact) {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Contacts.prototype.create = function(contact) {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Contacts.prototype.m_foundContacts = function(win, contacts) {
|
Contacts.prototype.m_foundContacts = function(win, contacts) {
|
||||||
this.inProgress = false;
|
this.inProgress = false;
|
||||||
win(contacts);
|
win(contacts);
|
||||||
@ -112,14 +129,14 @@ var ContactError = function() {
|
|||||||
this.code=null;
|
this.code=null;
|
||||||
};
|
};
|
||||||
|
|
||||||
ContactError.INVALID_ARGUMENT_ERROR = 0;
|
ContactError.UNKNOWN_ERROR = 0;
|
||||||
ContactError.IO_ERROR = 1;
|
ContactError.INVALID_ARGUMENT_ERROR = 1;
|
||||||
ContactError.NOT_FOUND_ERROR = 2;
|
ContactError.NOT_FOUND_ERROR = 2;
|
||||||
ContactError.NOT_SUPPORTED_ERROR = 3;
|
ContactError.TIMEOUT_ERROR = 3;
|
||||||
ContactError.PENDING_OPERATION_ERROR = 4;
|
ContactError.PENDING_OPERATION_ERROR = 4;
|
||||||
ContactError.PERMISSION_DENIED_ERROR = 5;
|
ContactError.IO_ERROR = 5;
|
||||||
ContactError.TIMEOUT_ERROR = 6;
|
ContactError.NOT_SUPPORTED_ERROR = 6;
|
||||||
ContactError.UNKNOWN_ERROR = 7;
|
ContactError.PERMISSION_DENIED_ERROR = 20;
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if(typeof navigator.service == "undefined") navigator.service = new Object();
|
if(typeof navigator.service == "undefined") navigator.service = new Object();
|
||||||
|
@ -324,6 +324,42 @@ PhoneGap.stringify = function(args) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does a deep clone of the object.
|
||||||
|
*
|
||||||
|
* @param obj
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PhoneGap.clone = function(obj) {
|
||||||
|
if(!obj) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(obj instanceof Array){
|
||||||
|
var retVal = new Array();
|
||||||
|
for(var i = 0; i < obj.length; ++i){
|
||||||
|
retVal.push(PhoneGap.clone(obj[i]));
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj instanceof Function) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(obj instanceof Object)){
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
retVal = new Object();
|
||||||
|
for(i in obj){
|
||||||
|
if(!(i in retVal) || retVal[i] != obj[i]) {
|
||||||
|
retVal[i] = PhoneGap.clone(obj[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
};
|
||||||
|
|
||||||
PhoneGap.callbackId = 0;
|
PhoneGap.callbackId = 0;
|
||||||
PhoneGap.callbacks = {};
|
PhoneGap.callbacks = {};
|
||||||
|
|
||||||
|
@ -324,6 +324,42 @@ PhoneGap.stringify = function(args) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does a deep clone of the object.
|
||||||
|
*
|
||||||
|
* @param obj
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PhoneGap.clone = function(obj) {
|
||||||
|
if(!obj) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(obj instanceof Array){
|
||||||
|
var retVal = new Array();
|
||||||
|
for(var i = 0; i < obj.length; ++i){
|
||||||
|
retVal.push(PhoneGap.clone(obj[i]));
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj instanceof Function) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(obj instanceof Object)){
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
retVal = new Object();
|
||||||
|
for(i in obj){
|
||||||
|
if(!(i in retVal) || retVal[i] != obj[i]) {
|
||||||
|
retVal[i] = PhoneGap.clone(obj[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
};
|
||||||
|
|
||||||
PhoneGap.callbackId = 0;
|
PhoneGap.callbackId = 0;
|
||||||
PhoneGap.callbacks = {};
|
PhoneGap.callbacks = {};
|
||||||
|
|
||||||
@ -687,7 +723,7 @@ Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallb
|
|||||||
Accelerometer.prototype.clearWatch = function(id) {
|
Accelerometer.prototype.clearWatch = function(id) {
|
||||||
|
|
||||||
// Stop javascript timer & remove from timer list
|
// Stop javascript timer & remove from timer list
|
||||||
if (id && navigator.accelerometer.timers[id]) {
|
if (id && navigator.accelerometer.timers[id] != undefined) {
|
||||||
clearInterval(navigator.accelerometer.timers[id]);
|
clearInterval(navigator.accelerometer.timers[id]);
|
||||||
delete navigator.accelerometer.timers[id];
|
delete navigator.accelerometer.timers[id];
|
||||||
}
|
}
|
||||||
@ -940,6 +976,27 @@ var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, ad
|
|||||||
this.connected = connected || null;
|
this.connected = connected || null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Contact.prototype.remove = function(successCB, errorCB) {
|
||||||
|
if (this.id == null) {
|
||||||
|
var errorObj = new ContactError();
|
||||||
|
errorObj.code = ContactError.NOT_FOUND_ERROR;
|
||||||
|
errorCB(errorObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
PhoneGap.execAsync(successCB, errorCB, "Contacts", "remove", [this.id]);
|
||||||
|
};
|
||||||
|
|
||||||
|
Contact.prototype.clone = function() {
|
||||||
|
var clonedContact = PhoneGap.clone(this);
|
||||||
|
clonedContact.id = null;
|
||||||
|
return clonedContact;
|
||||||
|
};
|
||||||
|
|
||||||
|
Contact.prototype.save = function(win, fail) {
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) {
|
var ContactName = function(formatted, familyName, givenName, middle, prefix, suffix) {
|
||||||
this.formatted = formatted || null;
|
this.formatted = formatted || null;
|
||||||
this.familyName = familyName || null;
|
this.familyName = familyName || null;
|
||||||
@ -985,30 +1042,26 @@ var Contacts = function() {
|
|||||||
this.records = new Array();
|
this.records = new Array();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contacts.prototype.find = function(obj, win, fail) {
|
|
||||||
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.
|
||||||
|
//Must call contact.save() for it to be persisted in the db.
|
||||||
|
Contacts.prototype.create = function(properties) {
|
||||||
|
var contact = new Contact();
|
||||||
|
for (i in properties) {
|
||||||
|
if (contact[i]!='undefined') {
|
||||||
|
contact[i]=properties[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return contact;
|
||||||
};
|
};
|
||||||
|
|
||||||
Contacts.prototype.droidDone = function(contacts) {
|
Contacts.prototype.droidDone = function(contacts) {
|
||||||
this.win(eval('(' + contacts + ')'));
|
this.win(eval('(' + contacts + ')'));
|
||||||
};
|
};
|
||||||
|
|
||||||
Contacts.prototype.remove = function(contact) {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Contacts.prototype.save = function(contact) {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Contacts.prototype.create = function(contact) {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Contacts.prototype.m_foundContacts = function(win, contacts) {
|
Contacts.prototype.m_foundContacts = function(win, contacts) {
|
||||||
this.inProgress = false;
|
this.inProgress = false;
|
||||||
win(contacts);
|
win(contacts);
|
||||||
@ -1025,14 +1078,14 @@ var ContactError = function() {
|
|||||||
this.code=null;
|
this.code=null;
|
||||||
};
|
};
|
||||||
|
|
||||||
ContactError.INVALID_ARGUMENT_ERROR = 0;
|
ContactError.UNKNOWN_ERROR = 0;
|
||||||
ContactError.IO_ERROR = 1;
|
ContactError.INVALID_ARGUMENT_ERROR = 1;
|
||||||
ContactError.NOT_FOUND_ERROR = 2;
|
ContactError.NOT_FOUND_ERROR = 2;
|
||||||
ContactError.NOT_SUPPORTED_ERROR = 3;
|
ContactError.TIMEOUT_ERROR = 3;
|
||||||
ContactError.PENDING_OPERATION_ERROR = 4;
|
ContactError.PENDING_OPERATION_ERROR = 4;
|
||||||
ContactError.PERMISSION_DENIED_ERROR = 5;
|
ContactError.IO_ERROR = 5;
|
||||||
ContactError.TIMEOUT_ERROR = 6;
|
ContactError.NOT_SUPPORTED_ERROR = 6;
|
||||||
ContactError.UNKNOWN_ERROR = 7;
|
ContactError.PERMISSION_DENIED_ERROR = 20;
|
||||||
|
|
||||||
PhoneGap.addConstructor(function() {
|
PhoneGap.addConstructor(function() {
|
||||||
if(typeof navigator.service == "undefined") navigator.service = new Object();
|
if(typeof navigator.service == "undefined") navigator.service = new Object();
|
||||||
|
@ -19,11 +19,14 @@
|
|||||||
package com.phonegap;
|
package com.phonegap;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.util.Log;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,9 +85,78 @@ public abstract class ContactAccessor {
|
|||||||
|
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isRequired(String key, HashMap<String,Boolean> map) {
|
||||||
|
Boolean retVal = map.get(key);
|
||||||
|
return (retVal == null) ? false : retVal.booleanValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected HashMap<String,Boolean> buildPopulationSet(JSONArray filter) {
|
||||||
|
HashMap<String,Boolean> map = new HashMap<String,Boolean>();
|
||||||
|
|
||||||
|
String key;
|
||||||
|
try {
|
||||||
|
for (int i=0; i<filter.length(); i++) {
|
||||||
|
key = filter.getString(i);
|
||||||
|
if (key.startsWith("displayName")) {
|
||||||
|
map.put("displayName", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("name")) {
|
||||||
|
map.put("name", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("nickname")) {
|
||||||
|
map.put("nickname", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("phoneNumbers")) {
|
||||||
|
map.put("phoneNumbers", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("emails")) {
|
||||||
|
map.put("emails", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("addresses")) {
|
||||||
|
map.put("addresses", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("ims")) {
|
||||||
|
map.put("ims", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("organizations")) {
|
||||||
|
map.put("organizations", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("birthday")) {
|
||||||
|
map.put("birthday", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("anniversary")) {
|
||||||
|
map.put("anniversary", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("note")) {
|
||||||
|
map.put("note", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("relationships")) {
|
||||||
|
map.put("relationships", true);
|
||||||
|
}
|
||||||
|
else if (key.startsWith("urls")) {
|
||||||
|
map.put("urls", true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JSONException e) {
|
||||||
|
Log.e(LOG_TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles adding a JSON Contact object into the database.
|
||||||
|
*/
|
||||||
|
public abstract void save(JSONObject contact);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
*/
|
||||||
|
public abstract boolean remove(String id);
|
||||||
}
|
}
|
@ -79,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;
|
||||||
@ -102,7 +102,8 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
ContentResolver cr = mApp.getContentResolver();
|
ContentResolver cr = mApp.getContentResolver();
|
||||||
|
|
||||||
Set<String> contactIds = buildSetOfContactIds(filter, searchTerm);
|
Set<String> contactIds = buildSetOfContactIds(filter, searchTerm);
|
||||||
|
HashMap<String,Boolean> populate = buildPopulationSet(filter);
|
||||||
|
|
||||||
Iterator<String> it = contactIds.iterator();
|
Iterator<String> it = contactIds.iterator();
|
||||||
|
|
||||||
JSONArray contacts = new JSONArray();
|
JSONArray contacts = new JSONArray();
|
||||||
@ -124,20 +125,27 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
null);
|
null);
|
||||||
cur.moveToFirst();
|
cur.moveToFirst();
|
||||||
|
|
||||||
// name
|
if (isRequired("displayName",populate)) {
|
||||||
contact.put("displayName", cur.getString(cur.getColumnIndex(People.DISPLAY_NAME)));
|
contact.put("displayName", cur.getString(cur.getColumnIndex(People.DISPLAY_NAME)));
|
||||||
// phone number
|
}
|
||||||
contact.put("phoneNumbers", phoneQuery(cr, contactId));
|
if (isRequired("phoneNumbers",populate)) {
|
||||||
// email
|
contact.put("phoneNumbers", phoneQuery(cr, contactId));
|
||||||
contact.put("emails", emailQuery(cr, contactId));
|
}
|
||||||
// addresses
|
if (isRequired("emails",populate)) {
|
||||||
contact.put("addresses", addressQuery(cr, contactId));
|
contact.put("emails", emailQuery(cr, contactId));
|
||||||
// organizations
|
}
|
||||||
contact.put("organizations", organizationQuery(cr, contactId));
|
if (isRequired("addresses",populate)) {
|
||||||
// ims
|
contact.put("addresses", addressQuery(cr, contactId));
|
||||||
contact.put("ims", imQuery(cr, contactId));
|
}
|
||||||
// note
|
if (isRequired("organizations",populate)) {
|
||||||
contact.put("note", cur.getString(cur.getColumnIndex(People.NOTES)));
|
contact.put("organizations", organizationQuery(cr, contactId));
|
||||||
|
}
|
||||||
|
if (isRequired("ims",populate)) {
|
||||||
|
contact.put("ims", imQuery(cr, contactId));
|
||||||
|
}
|
||||||
|
if (isRequired("note",populate)) {
|
||||||
|
contact.put("note", cur.getString(cur.getColumnIndex(People.NOTES)));
|
||||||
|
}
|
||||||
// nickname
|
// nickname
|
||||||
// urls
|
// urls
|
||||||
// relationship
|
// relationship
|
||||||
@ -151,7 +159,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) {
|
||||||
@ -359,4 +367,19 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
|||||||
}
|
}
|
||||||
return emails;
|
return emails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(JSONObject contact) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(String id) {
|
||||||
|
int result = mApp.getContentResolver().delete(People.CONTENT_URI,
|
||||||
|
"people._id = ?",
|
||||||
|
new String[] {id});
|
||||||
|
|
||||||
|
return (result > 0) ? true : false;
|
||||||
|
}
|
||||||
}
|
}
|
@ -107,14 +107,13 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
//dbMap.put("connected", null);
|
//dbMap.put("connected", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContactAccessorSdk5(WebView view, Activity app)
|
public ContactAccessorSdk5(WebView view, Activity app) {
|
||||||
{
|
|
||||||
mApp = app;
|
mApp = app;
|
||||||
mView = view;
|
mView = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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;
|
||||||
@ -133,49 +132,90 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a cursor by creating the query.
|
// Get a cursor by creating the query.
|
||||||
ContentResolver cr = mApp.getContentResolver();
|
ContentResolver cr = mApp.getContentResolver();
|
||||||
|
|
||||||
Set<String> contactIds = buildSetOfContactIds(filter, searchTerm);
|
Set<String> contactIds = buildSetOfContactIds(filter, searchTerm);
|
||||||
|
HashMap<String,Boolean> populate = buildPopulationSet(filter);
|
||||||
|
|
||||||
Iterator<String> it = contactIds.iterator();
|
Iterator<String> it = contactIds.iterator();
|
||||||
|
|
||||||
JSONArray contacts = new JSONArray();
|
JSONArray contacts = new JSONArray();
|
||||||
JSONObject contact;
|
JSONObject contact;
|
||||||
String contactId;
|
String contactId;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
String[] events = null;
|
||||||
while (it.hasNext() && (pos < limit)) {
|
while (it.hasNext() && (pos < limit)) {
|
||||||
contact = new JSONObject();
|
contact = new JSONObject();
|
||||||
contactId = it.next();
|
contactId = it.next();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
contact.put("id", contactId);
|
contact.put("id", contactId);
|
||||||
contact.put("displayName", displayNameQuery(cr, contactId));
|
if (isRequired("displayName",populate)) {
|
||||||
contact.put("name", nameQuery(cr, contactId));
|
contact.put("displayName", displayNameQuery(cr, contactId));
|
||||||
contact.put("phoneNumbers", phoneQuery(cr, contactId));
|
}
|
||||||
contact.put("emails", emailQuery(cr, contactId));
|
if (isRequired("name",populate)) {
|
||||||
contact.put("addresses", addressQuery(cr, contactId));
|
contact.put("name", nameQuery(cr, contactId));
|
||||||
contact.put("organizations", organizationQuery(cr, contactId));
|
}
|
||||||
contact.put("ims",imQuery(cr, contactId));
|
if (isRequired("phoneNumbers",populate)) {
|
||||||
contact.put("note",noteQuery(cr, contactId));
|
contact.put("phoneNumbers", phoneQuery(cr, contactId));
|
||||||
contact.put("nickname",nicknameQuery(cr, contactId));
|
}
|
||||||
contact.put("urls",websiteQuery(cr, contactId));
|
if (isRequired("emails",populate)) {
|
||||||
contact.put("relationships",relationshipQuery(cr, contactId));
|
contact.put("emails", emailQuery(cr, contactId));
|
||||||
contact.put("birthday",birthdayQuery(cr, contactId));
|
}
|
||||||
contact.put("anniversary",anniversaryQuery(cr, contactId));
|
if (isRequired("addresses",populate)) {
|
||||||
|
contact.put("addresses", addressQuery(cr, contactId));
|
||||||
|
}
|
||||||
|
if (isRequired("organizations",populate)) {
|
||||||
|
contact.put("organizations", organizationQuery(cr, contactId));
|
||||||
|
}
|
||||||
|
if (isRequired("ims",populate)) {
|
||||||
|
contact.put("ims",imQuery(cr, contactId));
|
||||||
|
}
|
||||||
|
if (isRequired("note",populate)) {
|
||||||
|
contact.put("note",noteQuery(cr, contactId));
|
||||||
|
}
|
||||||
|
if (isRequired("nickname",populate)) {
|
||||||
|
contact.put("nickname",nicknameQuery(cr, contactId));
|
||||||
|
}
|
||||||
|
if (isRequired("urls",populate)) {
|
||||||
|
contact.put("urls",websiteQuery(cr, contactId));
|
||||||
|
}
|
||||||
|
if (isRequired("relationships",populate)) {
|
||||||
|
contact.put("relationships",relationshipQuery(cr, contactId));
|
||||||
|
}
|
||||||
|
if (isRequired("birthday",populate) || isRequired("anniversary",populate)) {
|
||||||
|
events = eventQuery(cr, contactId);
|
||||||
|
contact.put("birthday",events[0]);
|
||||||
|
contact.put("anniversary",events[1]);
|
||||||
|
}
|
||||||
} 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) {
|
||||||
Set<String> contactIds = new HashSet<String>();
|
Set<String> contactIds = new HashSet<String>();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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;
|
String key;
|
||||||
try {
|
try {
|
||||||
for (int i=0; i<filter.length(); i++) {
|
for (int i=0; i<filter.length(); i++) {
|
||||||
@ -307,7 +347,12 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
String[] orgWhereParams = new String[]{contactId,
|
String[] orgWhereParams = new String[]{contactId,
|
||||||
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
|
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
|
||||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||||
null, WHERE_STRING, orgWhereParams, null);
|
new String[] {ContactsContract.CommonDataKinds.Organization.DEPARTMENT,
|
||||||
|
ContactsContract.CommonDataKinds.Organization.JOB_DESCRIPTION,
|
||||||
|
ContactsContract.CommonDataKinds.Organization.OFFICE_LOCATION,
|
||||||
|
ContactsContract.CommonDataKinds.Organization.COMPANY,
|
||||||
|
ContactsContract.CommonDataKinds.Organization.TITLE},
|
||||||
|
WHERE_STRING, orgWhereParams, null);
|
||||||
JSONArray organizations = new JSONArray();
|
JSONArray organizations = new JSONArray();
|
||||||
JSONObject organization = new JSONObject();
|
JSONObject organization = new JSONObject();
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
@ -334,7 +379,13 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
String[] addrWhereParams = new String[]{contactId,
|
String[] addrWhereParams = new String[]{contactId,
|
||||||
ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
|
ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
|
||||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||||
null, WHERE_STRING, addrWhereParams, null);
|
new String[] {ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS,
|
||||||
|
ContactsContract.CommonDataKinds.StructuredPostal.STREET,
|
||||||
|
ContactsContract.CommonDataKinds.StructuredPostal.CITY,
|
||||||
|
ContactsContract.CommonDataKinds.StructuredPostal.REGION,
|
||||||
|
ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE,
|
||||||
|
ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY},
|
||||||
|
WHERE_STRING, addrWhereParams, null);
|
||||||
JSONArray addresses = new JSONArray();
|
JSONArray addresses = new JSONArray();
|
||||||
JSONObject address = new JSONObject();
|
JSONObject address = new JSONObject();
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
@ -358,7 +409,12 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
String[] addrWhereParams = new String[]{contactId,
|
String[] addrWhereParams = new String[]{contactId,
|
||||||
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE};
|
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE};
|
||||||
Cursor name = cr.query(ContactsContract.Data.CONTENT_URI,
|
Cursor name = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||||
null, WHERE_STRING, addrWhereParams, null);
|
new String[] {ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
|
||||||
|
ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,
|
||||||
|
ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME,
|
||||||
|
ContactsContract.CommonDataKinds.StructuredName.PREFIX,
|
||||||
|
ContactsContract.CommonDataKinds.StructuredName.SUFFIX},
|
||||||
|
WHERE_STRING, addrWhereParams, null);
|
||||||
JSONObject contactName = new JSONObject();
|
JSONObject contactName = new JSONObject();
|
||||||
if (name.moveToFirst()) {
|
if (name.moveToFirst()) {
|
||||||
try {
|
try {
|
||||||
@ -393,7 +449,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
private JSONArray phoneQuery(ContentResolver cr, String contactId) {
|
private JSONArray phoneQuery(ContentResolver cr, String contactId) {
|
||||||
Cursor phones = cr.query(
|
Cursor phones = cr.query(
|
||||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
||||||
null,
|
new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.TYPE},
|
||||||
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
|
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
|
||||||
null, null);
|
null, null);
|
||||||
JSONArray phoneNumbers = new JSONArray();
|
JSONArray phoneNumbers = new JSONArray();
|
||||||
@ -415,7 +471,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
private JSONArray emailQuery(ContentResolver cr, String contactId) {
|
private JSONArray emailQuery(ContentResolver cr, String contactId) {
|
||||||
Cursor emails = cr.query(
|
Cursor emails = cr.query(
|
||||||
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
||||||
null,
|
new String[] {ContactsContract.CommonDataKinds.Email.DATA,ContactsContract.CommonDataKinds.Email.TYPE},
|
||||||
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId,
|
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId,
|
||||||
null, null);
|
null, null);
|
||||||
JSONArray emailAddresses = new JSONArray();
|
JSONArray emailAddresses = new JSONArray();
|
||||||
@ -438,7 +494,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
String[] addrWhereParams = new String[]{contactId,
|
String[] addrWhereParams = new String[]{contactId,
|
||||||
ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE};
|
ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE};
|
||||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||||
null, WHERE_STRING, addrWhereParams, null);
|
new String[] {ContactsContract.CommonDataKinds.Im.DATA,ContactsContract.CommonDataKinds.Im.TYPE},
|
||||||
|
WHERE_STRING, addrWhereParams, null);
|
||||||
JSONArray ims = new JSONArray();
|
JSONArray ims = new JSONArray();
|
||||||
JSONObject im = new JSONObject();
|
JSONObject im = new JSONObject();
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
@ -459,7 +516,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
String[] noteWhereParams = new String[]{contactId,
|
String[] noteWhereParams = new String[]{contactId,
|
||||||
ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
|
ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
|
||||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||||
null, WHERE_STRING, noteWhereParams, null);
|
new String[] {ContactsContract.CommonDataKinds.Note.NOTE}, WHERE_STRING, noteWhereParams, null);
|
||||||
String note = new String("");
|
String note = new String("");
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
note = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
|
note = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
|
||||||
@ -472,7 +529,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
String[] nicknameWhereParams = new String[]{contactId,
|
String[] nicknameWhereParams = new String[]{contactId,
|
||||||
ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE};
|
ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE};
|
||||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||||
null, WHERE_STRING, nicknameWhereParams, null);
|
new String[] {ContactsContract.CommonDataKinds.Nickname.NAME}, WHERE_STRING, nicknameWhereParams, null);
|
||||||
String nickname = new String("");
|
String nickname = new String("");
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
nickname = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME));
|
nickname = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME));
|
||||||
@ -485,7 +542,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
String[] websiteWhereParams = new String[]{contactId,
|
String[] websiteWhereParams = new String[]{contactId,
|
||||||
ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE};
|
ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE};
|
||||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||||
null, WHERE_STRING, websiteWhereParams, null);
|
new String[] {ContactsContract.CommonDataKinds.Website.URL,ContactsContract.CommonDataKinds.Website.TYPE},
|
||||||
|
WHERE_STRING, websiteWhereParams, null);
|
||||||
JSONArray websites = new JSONArray();
|
JSONArray websites = new JSONArray();
|
||||||
JSONObject website = new JSONObject();
|
JSONObject website = new JSONObject();
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
@ -506,7 +564,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
String[] relationshipWhereParams = new String[]{contactId,
|
String[] relationshipWhereParams = new String[]{contactId,
|
||||||
ContactsContract.CommonDataKinds.Relation.CONTENT_ITEM_TYPE};
|
ContactsContract.CommonDataKinds.Relation.CONTENT_ITEM_TYPE};
|
||||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||||
null, WHERE_STRING, relationshipWhereParams, null);
|
new String[] {ContactsContract.CommonDataKinds.Relation.NAME,ContactsContract.CommonDataKinds.Relation.TYPE},
|
||||||
|
WHERE_STRING, relationshipWhereParams, null);
|
||||||
JSONArray relationships = new JSONArray();
|
JSONArray relationships = new JSONArray();
|
||||||
JSONObject relationship = new JSONObject();
|
JSONObject relationship = new JSONObject();
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
@ -523,31 +582,34 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
|||||||
return relationships;
|
return relationships;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String birthdayQuery(ContentResolver cr, String contactId) {
|
private String[] eventQuery(ContentResolver cr, String contactId) {
|
||||||
String birthday = conditionalStringQuery(cr, contactId, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,
|
String[] whereParams = new String[]{contactId, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE};
|
||||||
ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY, ContactsContract.CommonDataKinds.Event.TYPE,
|
|
||||||
ContactsContract.CommonDataKinds.Event.START_DATE);
|
|
||||||
return birthday;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String anniversaryQuery(ContentResolver cr, String contactId) {
|
|
||||||
String anniversary = conditionalStringQuery(cr, contactId, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,
|
|
||||||
ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY, ContactsContract.CommonDataKinds.Event.TYPE,
|
|
||||||
ContactsContract.CommonDataKinds.Event.START_DATE);
|
|
||||||
return anniversary;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String conditionalStringQuery(ContentResolver cr, String contactId, String dataType, int type, String label, String data) {
|
|
||||||
String[] whereParams = new String[]{contactId, dataType};
|
|
||||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||||
null, WHERE_STRING, whereParams, null);
|
null, WHERE_STRING, whereParams, null);
|
||||||
String retVal = new String("");
|
String anniversary = null;
|
||||||
|
String birthday = null;
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
if (type == cursor.getInt(cursor.getColumnIndex(label))) {
|
if (ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY == cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE))) {
|
||||||
retVal = cursor.getString(cursor.getColumnIndex(data));
|
anniversary = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
|
||||||
|
}
|
||||||
|
else if (ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY == cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE))) {
|
||||||
|
birthday = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return retVal;
|
return new String[] {anniversary, birthday};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(JSONObject contact) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean remove(String id) {
|
||||||
|
int result = mApp.getContentResolver().delete(ContactsContract.Data.CONTENT_URI,
|
||||||
|
ContactsContract.Data.CONTACT_ID + " = ?",
|
||||||
|
new String[] {id});
|
||||||
|
return (result > 0) ? true : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,6 +2,7 @@ package com.phonegap;
|
|||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import com.phonegap.api.Plugin;
|
import com.phonegap.api.Plugin;
|
||||||
import com.phonegap.api.PluginResult;
|
import com.phonegap.api.PluginResult;
|
||||||
@ -60,16 +61,21 @@ 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")) {
|
|
||||||
// TODO Coming soon!
|
|
||||||
}
|
}
|
||||||
else if (action.equals("save")) {
|
else if (action.equals("save")) {
|
||||||
// TODO Coming soon!
|
// TODO Coming soon!
|
||||||
}
|
}
|
||||||
else if (action.equals("remove")) {
|
else if (action.equals("remove")) {
|
||||||
// TODO Coming soon!
|
if (contactAccessor.remove(args.getString(0))) {
|
||||||
|
return new PluginResult(status, result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JSONObject r = new JSONObject();
|
||||||
|
r.put("code", 2);
|
||||||
|
return new PluginResult(PluginResult.Status.ERROR, r);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new PluginResult(status, result);
|
return new PluginResult(status, result);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user