Fixing bug found by tiny hippos

This commit is contained in:
macdonst 2011-01-25 03:04:11 +08:00
parent 1b8ab156df
commit 726f1094d9
3 changed files with 23 additions and 15 deletions

View File

@ -106,20 +106,23 @@ public class ContactAccessorSdk3_4 extends ContactAccessor {
String searchTerm = "";
int limit = 1;
boolean multiple = false;
try {
searchTerm = options.getString("filter");
if (options != null) {
searchTerm = options.optString("filter");
if (searchTerm.length()==0) {
searchTerm = "%";
}
else {
searchTerm = "%" + searchTerm + "%";
}
multiple = options.getBoolean("multiple");
multiple = options.optBoolean("multiple");
if (multiple) {
limit = options.getInt("limit");
limit = options.optInt("limit");
limit = limit > 0 ? limit : 1;
}
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
}
else {
searchTerm = "%";
}
ContentResolver cr = mApp.getContentResolver();

View File

@ -158,20 +158,23 @@ public class ContactAccessorSdk5 extends ContactAccessor {
String searchTerm = "";
int limit = 1;
boolean multiple = false;
try {
searchTerm = options.getString("filter");
if (options != null) {
searchTerm = options.optString("filter");
if (searchTerm.length()==0) {
searchTerm = "%";
}
else {
searchTerm = "%" + searchTerm + "%";
}
multiple = options.getBoolean("multiple");
multiple = options.optBoolean("multiple");
if (multiple) {
limit = options.getInt("limit");
limit = options.optInt("limit");
limit = limit > 0 ? limit : 1;
}
} catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e);
}
else {
searchTerm = "%";
}
//Log.d(LOG_TAG, "Search Term = " + searchTerm);
@ -339,8 +342,10 @@ public class ContactAccessorSdk5 extends ContactAccessor {
}
// Push the last contact into the contacts array
contacts.put(populateContact(contact, organizations, addresses, phones,
emails, ims, websites, relationships, photos));
if (contacts.length() < limit) {
contacts.put(populateContact(contact, organizations, addresses, phones,
emails, ims, websites, relationships, photos));
}
}
c.close();

View File

@ -42,7 +42,7 @@ public class ContactManager extends Plugin {
try {
if (action.equals("search")) {
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.getJSONObject(1));
JSONArray res = contactAccessor.search(args.getJSONArray(0), args.optJSONObject(1));
return new PluginResult(status, res, "navigator.service.contacts.cast");
}
else if (action.equals("save")) {