Able to query contact DB on Android 1.6

This commit is contained in:
macdonst 2010-09-21 22:08:45 -04:00
parent fdca4c5ecb
commit 328bc106e5
4 changed files with 57 additions and 7 deletions

View File

@ -237,6 +237,28 @@ PhoneGap.stringify = function(args) {
if ((type == "number") || (type == "boolean")) { if ((type == "number") || (type == "boolean")) {
s = s + args[i]; s = s + args[i];
} }
else if (args[i] instanceof Array) {
s = s + "[" + args[i] + "]";
}
else if (args[i] instanceof Object) {
var start = true;
s = s + '{';
for (var name in args[i]) {
if (!start) {
s = s + ',';
}
s = s + '"' + name + '":';
var nameType = typeof args[i][name];
if ((nameType == "number") || (nameType == "boolean")) {
s = s + args[i][name];
}
else {
s = s + '"' + args[i][name] + '"';
}
start=false;
}
s = s + '}';
}
else { else {
s = s + '"' + args[i] + '"'; s = s + '"' + args[i] + '"';
} }

View File

@ -237,6 +237,28 @@ PhoneGap.stringify = function(args) {
if ((type == "number") || (type == "boolean")) { if ((type == "number") || (type == "boolean")) {
s = s + args[i]; s = s + args[i];
} }
else if (args[i] instanceof Array) {
s = s + "[" + args[i] + "]";
}
else if (args[i] instanceof Object) {
var start = true;
s = s + '{';
for (var name in args[i]) {
if (!start) {
s = s + ',';
}
s = s + '"' + name + '":';
var nameType = typeof args[i][name];
if ((nameType == "number") || (nameType == "boolean")) {
s = s + args[i][name];
}
else {
s = s + '"' + args[i][name] + '"';
}
start=false;
}
s = s + '}';
}
else { else {
s = s + '"' + args[i] + '"'; s = s + '"' + args[i] + '"';
} }

View File

@ -62,6 +62,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
@Override @Override
public void search(JSONArray filter, JSONObject options) { public void search(JSONArray filter, JSONObject options) {
Log.d(LOG_TAG, "in 1.5+ search");
String searchTerm = ""; String searchTerm = "";
int limit = Integer.MAX_VALUE; int limit = Integer.MAX_VALUE;
boolean multiple = true; boolean multiple = true;
@ -98,7 +99,7 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
contact.put("phoneNumbers", phoneQuery(cr, contactId)); contact.put("phoneNumbers", phoneQuery(cr, contactId));
} }
// email // email
contact.put("emails", emailQuery(cr, contactId)); //contact.put("emails", emailQuery(cr, contactId));
// addresses // addresses
contact.put("addresses", addressQuery(cr, contactId)); contact.put("addresses", addressQuery(cr, contactId));
// organizations // organizations
@ -119,6 +120,9 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
} }
contacts.put(contact); contacts.put(contact);
} }
cur.close();
Log.d(LOG_TAG, "returning contacts string to javascript");
mView.loadUrl("javascript:navigator.service.contacts.droidDone('" + contacts.toString() + "');");
} }
private JSONArray imQuery(ContentResolver cr, String contactId) { private JSONArray imQuery(ContentResolver cr, String contactId) {

View File

@ -2,7 +2,6 @@ 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;
@ -10,9 +9,7 @@ import com.phonegap.api.PluginResult;
import android.util.Log; import android.util.Log;
import android.webkit.WebView; import android.webkit.WebView;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
@SuppressWarnings("deprecation")
public class ContactManager implements Plugin { public class ContactManager implements Plugin {
private static ContactAccessor contactAccessor; private static ContactAccessor contactAccessor;
@ -20,9 +17,6 @@ public class ContactManager implements Plugin {
DroidGap ctx; // DroidGap object DroidGap ctx; // DroidGap object
private static final String LOG_TAG = "Contact Query"; private static final String LOG_TAG = "Contact Query";
Uri mPeople = android.provider.Contacts.People.CONTENT_URI;
Uri mPhone = android.provider.Contacts.Phones.CONTENT_URI;
Uri mEmail = android.provider.Contacts.ContactMethods.CONTENT_URI;
/** /**
* Constructor. * Constructor.
@ -70,10 +64,18 @@ public class ContactManager implements Plugin {
//} //}
//else if (action.equals("search")) { //else if (action.equals("search")) {
if (action.equals("search")) { if (action.equals("search")) {
Log.d(LOG_TAG, "*** Calling search of " + contactAccessor.getClass().getName());
Log.d(LOG_TAG, "what is 0 " + args.get(0).getClass().toString());
Log.d(LOG_TAG, "what is 0 " + args.get(0).toString());
Log.d(LOG_TAG, "what is 1 " + args.get(1).getClass().toString());
Log.d(LOG_TAG, "what is 1 " + args.get(1).toString());
Log.d(LOG_TAG, "Fields = " + args.getJSONArray(0).toString());
Log.d(LOG_TAG, "Options = " + args.getJSONObject(1).toString());
contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1)); contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1));
} }
return new PluginResult(status, result); return new PluginResult(status, result);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
return new PluginResult(PluginResult.Status.JSON_EXCEPTION); return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
} }
} }