mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-25 19:32:54 +08:00
Fixing bug found by tiny hippos
This commit is contained in:
parent
1b8ab156df
commit
726f1094d9
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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")) {
|
||||
|
Loading…
Reference in New Issue
Block a user