mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +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();
|
||||
obj.filter="";
|
||||
obj.multiple=true;
|
||||
obj.limit=5;
|
||||
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) {
|
||||
|
||||
// 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]);
|
||||
delete navigator.accelerometer.timers[id];
|
||||
}
|
||||
|
@ -27,6 +27,27 @@ var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, ad
|
||||
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) {
|
||||
this.formatted = formatted || null;
|
||||
this.familyName = familyName || null;
|
||||
@ -72,30 +93,26 @@ var Contacts = function() {
|
||||
this.records = new Array();
|
||||
}
|
||||
|
||||
// Contacts.prototype.find = function(obj, win, fail) {
|
||||
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.
|
||||
//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) {
|
||||
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) {
|
||||
this.inProgress = false;
|
||||
win(contacts);
|
||||
@ -112,14 +129,14 @@ var ContactError = function() {
|
||||
this.code=null;
|
||||
};
|
||||
|
||||
ContactError.INVALID_ARGUMENT_ERROR = 0;
|
||||
ContactError.IO_ERROR = 1;
|
||||
ContactError.UNKNOWN_ERROR = 0;
|
||||
ContactError.INVALID_ARGUMENT_ERROR = 1;
|
||||
ContactError.NOT_FOUND_ERROR = 2;
|
||||
ContactError.NOT_SUPPORTED_ERROR = 3;
|
||||
ContactError.TIMEOUT_ERROR = 3;
|
||||
ContactError.PENDING_OPERATION_ERROR = 4;
|
||||
ContactError.PERMISSION_DENIED_ERROR = 5;
|
||||
ContactError.TIMEOUT_ERROR = 6;
|
||||
ContactError.UNKNOWN_ERROR = 7;
|
||||
ContactError.IO_ERROR = 5;
|
||||
ContactError.NOT_SUPPORTED_ERROR = 6;
|
||||
ContactError.PERMISSION_DENIED_ERROR = 20;
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
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.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.callbacks = {};
|
||||
|
||||
@ -687,7 +723,7 @@ Accelerometer.prototype.watchAcceleration = function(successCallback, errorCallb
|
||||
Accelerometer.prototype.clearWatch = function(id) {
|
||||
|
||||
// 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]);
|
||||
delete navigator.accelerometer.timers[id];
|
||||
}
|
||||
@ -940,6 +976,27 @@ var Contact = function(id, displayName, name, nickname, phoneNumbers, emails, ad
|
||||
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) {
|
||||
this.formatted = formatted || null;
|
||||
this.familyName = familyName || null;
|
||||
@ -985,30 +1042,26 @@ var Contacts = function() {
|
||||
this.records = new Array();
|
||||
}
|
||||
|
||||
// Contacts.prototype.find = function(obj, win, fail) {
|
||||
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.
|
||||
//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) {
|
||||
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) {
|
||||
this.inProgress = false;
|
||||
win(contacts);
|
||||
@ -1025,14 +1078,14 @@ var ContactError = function() {
|
||||
this.code=null;
|
||||
};
|
||||
|
||||
ContactError.INVALID_ARGUMENT_ERROR = 0;
|
||||
ContactError.IO_ERROR = 1;
|
||||
ContactError.UNKNOWN_ERROR = 0;
|
||||
ContactError.INVALID_ARGUMENT_ERROR = 1;
|
||||
ContactError.NOT_FOUND_ERROR = 2;
|
||||
ContactError.NOT_SUPPORTED_ERROR = 3;
|
||||
ContactError.TIMEOUT_ERROR = 3;
|
||||
ContactError.PENDING_OPERATION_ERROR = 4;
|
||||
ContactError.PERMISSION_DENIED_ERROR = 5;
|
||||
ContactError.TIMEOUT_ERROR = 6;
|
||||
ContactError.UNKNOWN_ERROR = 7;
|
||||
ContactError.IO_ERROR = 5;
|
||||
ContactError.NOT_SUPPORTED_ERROR = 6;
|
||||
ContactError.PERMISSION_DENIED_ERROR = 20;
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
if(typeof navigator.service == "undefined") navigator.service = new Object();
|
||||
|
@ -19,11 +19,14 @@
|
||||
package com.phonegap;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
@ -82,9 +85,78 @@ public abstract class ContactAccessor {
|
||||
|
||||
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.
|
||||
*/
|
||||
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
|
||||
public void search(JSONArray filter, JSONObject options) {
|
||||
public JSONArray search(JSONArray filter, JSONObject options) {
|
||||
String searchTerm = "";
|
||||
int limit = Integer.MAX_VALUE;
|
||||
boolean multiple = true;
|
||||
@ -102,7 +102,8 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
||||
ContentResolver cr = mApp.getContentResolver();
|
||||
|
||||
Set<String> contactIds = buildSetOfContactIds(filter, searchTerm);
|
||||
|
||||
HashMap<String,Boolean> populate = buildPopulationSet(filter);
|
||||
|
||||
Iterator<String> it = contactIds.iterator();
|
||||
|
||||
JSONArray contacts = new JSONArray();
|
||||
@ -124,20 +125,27 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
||||
null);
|
||||
cur.moveToFirst();
|
||||
|
||||
// name
|
||||
contact.put("displayName", cur.getString(cur.getColumnIndex(People.DISPLAY_NAME)));
|
||||
// phone number
|
||||
contact.put("phoneNumbers", phoneQuery(cr, contactId));
|
||||
// email
|
||||
contact.put("emails", emailQuery(cr, contactId));
|
||||
// addresses
|
||||
contact.put("addresses", addressQuery(cr, contactId));
|
||||
// organizations
|
||||
contact.put("organizations", organizationQuery(cr, contactId));
|
||||
// ims
|
||||
contact.put("ims", imQuery(cr, contactId));
|
||||
// note
|
||||
contact.put("note", cur.getString(cur.getColumnIndex(People.NOTES)));
|
||||
if (isRequired("displayName",populate)) {
|
||||
contact.put("displayName", cur.getString(cur.getColumnIndex(People.DISPLAY_NAME)));
|
||||
}
|
||||
if (isRequired("phoneNumbers",populate)) {
|
||||
contact.put("phoneNumbers", phoneQuery(cr, contactId));
|
||||
}
|
||||
if (isRequired("emails",populate)) {
|
||||
contact.put("emails", emailQuery(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", cur.getString(cur.getColumnIndex(People.NOTES)));
|
||||
}
|
||||
// nickname
|
||||
// urls
|
||||
// relationship
|
||||
@ -151,7 +159,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) {
|
||||
@ -359,4 +367,19 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
public ContactAccessorSdk5(WebView view, Activity app)
|
||||
{
|
||||
public ContactAccessorSdk5(WebView view, Activity app) {
|
||||
mApp = app;
|
||||
mView = view;
|
||||
}
|
||||
|
||||
@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;
|
||||
@ -133,49 +132,90 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
}
|
||||
|
||||
// Get a cursor by creating the query.
|
||||
ContentResolver cr = mApp.getContentResolver();
|
||||
|
||||
Set<String> contactIds = buildSetOfContactIds(filter, searchTerm);
|
||||
|
||||
HashMap<String,Boolean> populate = buildPopulationSet(filter);
|
||||
|
||||
Iterator<String> it = contactIds.iterator();
|
||||
|
||||
JSONArray contacts = new JSONArray();
|
||||
JSONObject contact;
|
||||
String contactId;
|
||||
int pos = 0;
|
||||
String[] events = null;
|
||||
while (it.hasNext() && (pos < limit)) {
|
||||
contact = new JSONObject();
|
||||
contactId = it.next();
|
||||
|
||||
try {
|
||||
contact.put("id", contactId);
|
||||
contact.put("displayName", displayNameQuery(cr, contactId));
|
||||
contact.put("name", nameQuery(cr, contactId));
|
||||
contact.put("phoneNumbers", phoneQuery(cr, contactId));
|
||||
contact.put("emails", emailQuery(cr, contactId));
|
||||
contact.put("addresses", addressQuery(cr, contactId));
|
||||
contact.put("organizations", organizationQuery(cr, contactId));
|
||||
contact.put("ims",imQuery(cr, contactId));
|
||||
contact.put("note",noteQuery(cr, contactId));
|
||||
contact.put("nickname",nicknameQuery(cr, contactId));
|
||||
contact.put("urls",websiteQuery(cr, contactId));
|
||||
contact.put("relationships",relationshipQuery(cr, contactId));
|
||||
contact.put("birthday",birthdayQuery(cr, contactId));
|
||||
contact.put("anniversary",anniversaryQuery(cr, contactId));
|
||||
if (isRequired("displayName",populate)) {
|
||||
contact.put("displayName", displayNameQuery(cr, contactId));
|
||||
}
|
||||
if (isRequired("name",populate)) {
|
||||
contact.put("name", nameQuery(cr, contactId));
|
||||
}
|
||||
if (isRequired("phoneNumbers",populate)) {
|
||||
contact.put("phoneNumbers", phoneQuery(cr, contactId));
|
||||
}
|
||||
if (isRequired("emails",populate)) {
|
||||
contact.put("emails", emailQuery(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) {
|
||||
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) {
|
||||
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;
|
||||
try {
|
||||
for (int i=0; i<filter.length(); i++) {
|
||||
@ -307,7 +347,12 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
String[] orgWhereParams = new String[]{contactId,
|
||||
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
|
||||
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();
|
||||
JSONObject organization = new JSONObject();
|
||||
while (cursor.moveToNext()) {
|
||||
@ -334,7 +379,13 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
String[] addrWhereParams = new String[]{contactId,
|
||||
ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
|
||||
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();
|
||||
JSONObject address = new JSONObject();
|
||||
while (cursor.moveToNext()) {
|
||||
@ -358,7 +409,12 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
String[] addrWhereParams = new String[]{contactId,
|
||||
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE};
|
||||
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();
|
||||
if (name.moveToFirst()) {
|
||||
try {
|
||||
@ -393,7 +449,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
private JSONArray phoneQuery(ContentResolver cr, String contactId) {
|
||||
Cursor phones = cr.query(
|
||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
||||
null,
|
||||
new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.TYPE},
|
||||
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
|
||||
null, null);
|
||||
JSONArray phoneNumbers = new JSONArray();
|
||||
@ -415,7 +471,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
private JSONArray emailQuery(ContentResolver cr, String contactId) {
|
||||
Cursor emails = cr.query(
|
||||
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
||||
null,
|
||||
new String[] {ContactsContract.CommonDataKinds.Email.DATA,ContactsContract.CommonDataKinds.Email.TYPE},
|
||||
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId,
|
||||
null, null);
|
||||
JSONArray emailAddresses = new JSONArray();
|
||||
@ -438,7 +494,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
String[] addrWhereParams = new String[]{contactId,
|
||||
ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE};
|
||||
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();
|
||||
JSONObject im = new JSONObject();
|
||||
while (cursor.moveToNext()) {
|
||||
@ -459,7 +516,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
String[] noteWhereParams = new String[]{contactId,
|
||||
ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
|
||||
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("");
|
||||
if (cursor.moveToFirst()) {
|
||||
note = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
|
||||
@ -472,7 +529,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
String[] nicknameWhereParams = new String[]{contactId,
|
||||
ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE};
|
||||
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("");
|
||||
if (cursor.moveToFirst()) {
|
||||
nickname = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME));
|
||||
@ -485,7 +542,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
String[] websiteWhereParams = new String[]{contactId,
|
||||
ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE};
|
||||
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();
|
||||
JSONObject website = new JSONObject();
|
||||
while (cursor.moveToNext()) {
|
||||
@ -506,7 +564,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
String[] relationshipWhereParams = new String[]{contactId,
|
||||
ContactsContract.CommonDataKinds.Relation.CONTENT_ITEM_TYPE};
|
||||
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();
|
||||
JSONObject relationship = new JSONObject();
|
||||
while (cursor.moveToNext()) {
|
||||
@ -523,31 +582,34 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
return relationships;
|
||||
}
|
||||
|
||||
private String birthdayQuery(ContentResolver cr, String contactId) {
|
||||
String birthday = conditionalStringQuery(cr, 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};
|
||||
private String[] eventQuery(ContentResolver cr, String contactId) {
|
||||
String[] whereParams = new String[]{contactId, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE};
|
||||
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
|
||||
null, WHERE_STRING, whereParams, null);
|
||||
String retVal = new String("");
|
||||
String anniversary = null;
|
||||
String birthday = null;
|
||||
while (cursor.moveToNext()) {
|
||||
if (type == cursor.getInt(cursor.getColumnIndex(label))) {
|
||||
retVal = cursor.getString(cursor.getColumnIndex(data));
|
||||
if (ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY == cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE))) {
|
||||
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();
|
||||
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.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
@ -60,16 +61,21 @@ public class ContactManager implements Plugin {
|
||||
|
||||
try {
|
||||
if (action.equals("search")) {
|
||||
contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1));
|
||||
}
|
||||
else if (action.equals("create")) {
|
||||
// TODO Coming soon!
|
||||
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1));
|
||||
return new PluginResult(status, res);
|
||||
}
|
||||
else if (action.equals("save")) {
|
||||
// TODO Coming soon!
|
||||
}
|
||||
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);
|
||||
} catch (JSONException e) {
|
||||
|
@ -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