You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2015/06/25 20:47:37 UTC
[3/4] cordova-plugin-contacts git commit: phoneNumbersInformedOnly
phoneNumbersInformedOnly
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/1a18d9c6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/1a18d9c6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/1a18d9c6
Branch: refs/heads/master
Commit: 1a18d9c6a0bbfc12e0055c466c39e0fe7c6cde92
Parents: ec0926c
Author: jonmikelm <jo...@gmail.com>
Authored: Wed May 27 10:12:22 2015 +0200
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Jun 25 11:02:35 2015 -0700
----------------------------------------------------------------------
src/android/ContactAccessorSdk5.java | 185 ++++++++++++++++--------------
www/ContactFindOptions.js | 3 +-
2 files changed, 103 insertions(+), 85 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/1a18d9c6/src/android/ContactAccessorSdk5.java
----------------------------------------------------------------------
diff --git a/src/android/ContactAccessorSdk5.java b/src/android/ContactAccessorSdk5.java
index 541e11d..7a14f09 100644
--- a/src/android/ContactAccessorSdk5.java
+++ b/src/android/ContactAccessorSdk5.java
@@ -139,6 +139,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
String searchTerm = "";
int limit = Integer.MAX_VALUE;
boolean multiple = true;
+ boolean phoneNumberInformedOnly = false;
if (options != null) {
searchTerm = options.optString("filter");
@@ -157,11 +158,16 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} catch (JSONException e) {
// Multiple was not specified so we assume the default is true.
}
+
+ try {
+ phoneNumberInformedOnly = options.getBoolean("phoneNumberInformedOnly");
+ } catch (JSONException e) {
+ // phoneNumberInformedOnly was not specified so we assume the default is false.
+ }
}
else {
searchTerm = "%";
}
-
//Log.d(LOG_TAG, "Search Term = " + searchTerm);
//Log.d(LOG_TAG, "Field Length = " + fields.length());
@@ -171,7 +177,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
HashMap<String, Boolean> populate = buildPopulationSet(options);
// Build the ugly where clause and where arguments for one big query.
- WhereOptions whereOptions = buildWhereClause(fields, searchTerm);
+ WhereOptions whereOptions = buildWhereClause(fields, searchTerm, phoneNumberInformedOnly);
// Get all the id's where the search term matches the fields passed in.
Cursor idCursor = mApp.getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
@@ -192,7 +198,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
idCursor.close();
// Build a query that only looks at ids
- WhereOptions idOptions = buildIdClause(contactIds, searchTerm);
+ WhereOptions idOptions = buildIdClause(contactIds, searchTerm, phoneNumberInformedOnly);
// Determine which columns we should be fetching.
HashSet<String> columnsToFetch = new HashSet<String>();
@@ -466,12 +472,12 @@ public class ContactAccessorSdk5 extends ContactAccessor {
* @param searchTerm what to search for
* @return an object containing the selection and selection args
*/
- private WhereOptions buildIdClause(Set<String> contactIds, String searchTerm) {
+ private WhereOptions buildIdClause(Set<String> contactIds, String searchTerm, boolean phoneNumberInformedOnly) {
WhereOptions options = new WhereOptions();
// If the user is searching for every contact then short circuit the method
// and return a shorter where clause to be searched.
- if (searchTerm.equals("%")) {
+ if (searchTerm.equals("%") && !phoneNumberInformedOnly) {
options.setWhere("(" + ContactsContract.Data.CONTACT_ID + " LIKE ? )");
options.setWhereArgs(new String[] { searchTerm });
return options;
@@ -545,7 +551,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
* @param searchTerm the string to search for
* @return an object containing the selection and selection args
*/
- private WhereOptions buildWhereClause(JSONArray fields, String searchTerm) {
+ private WhereOptions buildWhereClause(JSONArray fields, String searchTerm, boolean phoneNumberInformedOnly) {
ArrayList<String> where = new ArrayList<String>();
ArrayList<String> whereArgs = new ArrayList<String>();
@@ -557,7 +563,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
*/
if (isWildCardSearch(fields)) {
// Get all contacts with all properties
- if ("%".equals(searchTerm)) {
+ if ("%".equals(searchTerm) && !phoneNumberInformedOnly) {
options.setWhere("(" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? )");
options.setWhereArgs(new String[] { searchTerm });
return options;
@@ -607,87 +613,87 @@ public class ContactAccessorSdk5 extends ContactAccessor {
/*
* Special case for when the user wants all the contacts but
*/
- if ("%".equals(searchTerm)) {
+ if ("%".equals(searchTerm) && !phoneNumberInformedOnly) {
options.setWhere("(" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? )");
options.setWhereArgs(new String[] { searchTerm });
return options;
- }
-
- String key;
- try {
- //Log.d(LOG_TAG, "How many fields do we have = " + fields.length());
- for (int i = 0; i < fields.length(); i++) {
- key = fields.getString(i);
+ }else if(!("%".equals(searchTerm))){
+ String key;
+ try {
+ //Log.d(LOG_TAG, "How many fields do we have = " + fields.length());
+ for (int i = 0; i < fields.length(); i++) {
+ key = fields.getString(i);
- if (key.equals("id")) {
- where.add("(" + dbMap.get(key) + " = ? )");
- whereArgs.add(searchTerm.substring(1, searchTerm.length() - 1));
- }
- else if (key.startsWith("displayName")) {
- where.add("(" + dbMap.get(key) + " LIKE ? )");
- whereArgs.add(searchTerm);
- }
- else if (key.startsWith("name")) {
- where.add("(" + dbMap.get(key) + " LIKE ? AND "
- + ContactsContract.Data.MIMETYPE + " = ? )");
- whereArgs.add(searchTerm);
- whereArgs.add(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
- }
- else if (key.startsWith("nickname")) {
- where.add("(" + dbMap.get(key) + " LIKE ? AND "
- + ContactsContract.Data.MIMETYPE + " = ? )");
- whereArgs.add(searchTerm);
- whereArgs.add(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE);
- }
- else if (key.startsWith("phoneNumbers")) {
- where.add("(" + dbMap.get(key) + " LIKE ? AND "
- + ContactsContract.Data.MIMETYPE + " = ? )");
- whereArgs.add(searchTerm);
- whereArgs.add(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
- }
- else if (key.startsWith("emails")) {
- where.add("(" + dbMap.get(key) + " LIKE ? AND "
- + ContactsContract.Data.MIMETYPE + " = ? )");
- whereArgs.add(searchTerm);
- whereArgs.add(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
- }
- else if (key.startsWith("addresses")) {
- where.add("(" + dbMap.get(key) + " LIKE ? AND "
- + ContactsContract.Data.MIMETYPE + " = ? )");
- whereArgs.add(searchTerm);
- whereArgs.add(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
- }
- else if (key.startsWith("ims")) {
- where.add("(" + dbMap.get(key) + " LIKE ? AND "
- + ContactsContract.Data.MIMETYPE + " = ? )");
- whereArgs.add(searchTerm);
- whereArgs.add(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
- }
- else if (key.startsWith("organizations")) {
- where.add("(" + dbMap.get(key) + " LIKE ? AND "
- + ContactsContract.Data.MIMETYPE + " = ? )");
- whereArgs.add(searchTerm);
- whereArgs.add(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
- }
- // else if (key.startsWith("birthday")) {
-// where.add("(" + dbMap.get(key) + " LIKE ? AND "
-// + ContactsContract.Data.MIMETYPE + " = ? )");
-// }
- else if (key.startsWith("note")) {
- where.add("(" + dbMap.get(key) + " LIKE ? AND "
- + ContactsContract.Data.MIMETYPE + " = ? )");
- whereArgs.add(searchTerm);
- whereArgs.add(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE);
- }
- else if (key.startsWith("urls")) {
- where.add("(" + dbMap.get(key) + " LIKE ? AND "
- + ContactsContract.Data.MIMETYPE + " = ? )");
- whereArgs.add(searchTerm);
- whereArgs.add(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
+ if (key.equals("id")) {
+ where.add("(" + dbMap.get(key) + " = ? )");
+ whereArgs.add(searchTerm.substring(1, searchTerm.length() - 1));
+ }
+ else if (key.startsWith("displayName")) {
+ where.add("(" + dbMap.get(key) + " LIKE ? )");
+ whereArgs.add(searchTerm);
+ }
+ else if (key.startsWith("name")) {
+ where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ + ContactsContract.Data.MIMETYPE + " = ? )");
+ whereArgs.add(searchTerm);
+ whereArgs.add(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
+ }
+ else if (key.startsWith("nickname")) {
+ where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ + ContactsContract.Data.MIMETYPE + " = ? )");
+ whereArgs.add(searchTerm);
+ whereArgs.add(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE);
+ }
+ else if (key.startsWith("phoneNumbers")) {
+ where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ + ContactsContract.Data.MIMETYPE + " = ? )");
+ whereArgs.add(searchTerm);
+ whereArgs.add(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
+ }
+ else if (key.startsWith("emails")) {
+ where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ + ContactsContract.Data.MIMETYPE + " = ? )");
+ whereArgs.add(searchTerm);
+ whereArgs.add(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
+ }
+ else if (key.startsWith("addresses")) {
+ where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ + ContactsContract.Data.MIMETYPE + " = ? )");
+ whereArgs.add(searchTerm);
+ whereArgs.add(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
+ }
+ else if (key.startsWith("ims")) {
+ where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ + ContactsContract.Data.MIMETYPE + " = ? )");
+ whereArgs.add(searchTerm);
+ whereArgs.add(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
+ }
+ else if (key.startsWith("organizations")) {
+ where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ + ContactsContract.Data.MIMETYPE + " = ? )");
+ whereArgs.add(searchTerm);
+ whereArgs.add(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE);
+ }
+ // else if (key.startsWith("birthday")) {
+ // where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ // + ContactsContract.Data.MIMETYPE + " = ? )");
+ // }
+ else if (key.startsWith("note")) {
+ where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ + ContactsContract.Data.MIMETYPE + " = ? )");
+ whereArgs.add(searchTerm);
+ whereArgs.add(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE);
+ }
+ else if (key.startsWith("urls")) {
+ where.add("(" + dbMap.get(key) + " LIKE ? AND "
+ + ContactsContract.Data.MIMETYPE + " = ? )");
+ whereArgs.add(searchTerm);
+ whereArgs.add(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
+ }
}
+ } catch (JSONException e) {
+ Log.e(LOG_TAG, e.getMessage(), e);
}
- } catch (JSONException e) {
- Log.e(LOG_TAG, e.getMessage(), e);
}
// Creating the where string
@@ -698,6 +704,19 @@ public class ContactAccessorSdk5 extends ContactAccessor {
selection.append(" OR ");
}
}
+
+ //Only contacts with phone number informed
+ if(phoneNumberInformedOnly){
+ if(where.size()>0){
+ selection.insert(0,"(");
+ selection.append(") AND (" + ContactsContract.Contacts.HAS_PHONE_NUMBER + " = ?)");
+ whereArgs.add("1");
+ }else{
+ selection.append("(" + ContactsContract.Contacts.HAS_PHONE_NUMBER + " = ?)");
+ whereArgs.add("1");
+ }
+ }
+
options.setWhere(selection.toString());
// Creating the where args array
@@ -1813,8 +1832,6 @@ public class ContactAccessorSdk5 extends ContactAccessor {
Log.d(LOG_TAG, "Could not find contact with ID");
}
- cursor.close();
-
return (result > 0) ? true : false;
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/1a18d9c6/www/ContactFindOptions.js
----------------------------------------------------------------------
diff --git a/www/ContactFindOptions.js b/www/ContactFindOptions.js
index 75e6ed1..c42593e 100644
--- a/www/ContactFindOptions.js
+++ b/www/ContactFindOptions.js
@@ -26,10 +26,11 @@
* @param multiple boolean used to determine if more than one contact should be returned
*/
-var ContactFindOptions = function(filter, multiple, desiredFields) {
+var ContactFindOptions = function(filter, multiple, desiredFields, phoneNumberInformedOnly) {
this.filter = filter || '';
this.multiple = (typeof multiple != 'undefined' ? multiple : false);
this.desiredFields = typeof desiredFields != 'undefined' ? desiredFields : [];
+ this.phoneNumberInformedOnly = typeof phoneNumberInformedOnly != 'undefined' ? phoneNumberInformedOnly : false;
};
module.exports = ContactFindOptions;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org