cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [2/4] cordova-plugin-contacts git commit: hasPhoneNumber
Date Thu, 25 Jun 2015 18:47:36 GMT
hasPhoneNumber


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/4cbbc73b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/4cbbc73b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/4cbbc73b

Branch: refs/heads/master
Commit: 4cbbc73b3a72487fb386918923ee5f850b8007ab
Parents: 1a18d9c
Author: jonmikelm <jonmikelm@gmail.com>
Authored: Wed May 27 14:02:26 2015 +0200
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Thu Jun 25 11:02:35 2015 -0700

----------------------------------------------------------------------
 README.md                            |  5 ++++-
 src/android/ContactAccessorSdk5.java | 22 +++++++++++-----------
 www/ContactFindOptions.js            |  6 ++++--
 3 files changed, 19 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/4cbbc73b/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 7d2c03b..28c47ed 100644
--- a/README.md
+++ b/README.md
@@ -161,7 +161,9 @@ parameter to control which contact properties must be returned back.
 
 	- __multiple__: Determines if the find operation returns multiple navigator.contacts. _(Boolean)_
(Default: `false`)
 
-    	- __desiredFields__: Contact fields to be returned back. If specified, the resulting
`Contact` object only features values for these fields. _(DOMString[])_ [Optional]
+    - __desiredFields__: Contact fields to be returned back. If specified, the resulting
`Contact` object only features values for these fields. _(DOMString[])_ [Optional]
+
+    - __hasPhoneNumber__(Android only): Filters the search to only return contacts with a
phone number informed. _(boolean)_ [Optional]
 
 ### Supported Platforms
 
@@ -187,6 +189,7 @@ parameter to control which contact properties must be returned back.
     options.filter   = "Bob";
     options.multiple = true;
     options.desiredFields = [navigator.contacts.fieldType.id];
+    options.hasPhoneNumber = true;
     var fields       = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
     navigator.contacts.find(fields, onSuccess, onError, options);
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/4cbbc73b/src/android/ContactAccessorSdk5.java
----------------------------------------------------------------------
diff --git a/src/android/ContactAccessorSdk5.java b/src/android/ContactAccessorSdk5.java
index 7a14f09..be09f14 100644
--- a/src/android/ContactAccessorSdk5.java
+++ b/src/android/ContactAccessorSdk5.java
@@ -139,7 +139,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
         String searchTerm = "";
         int limit = Integer.MAX_VALUE;
         boolean multiple = true;
-        boolean phoneNumberInformedOnly = false;
+        boolean hasPhoneNumber = false;
 
         if (options != null) {
             searchTerm = options.optString("filter");
@@ -160,9 +160,9 @@ public class ContactAccessorSdk5 extends ContactAccessor {
             }
 
             try {
-                phoneNumberInformedOnly = options.getBoolean("phoneNumberInformedOnly");
+                hasPhoneNumber = options.getBoolean("hasPhoneNumber");
             } catch (JSONException e) {
-                // phoneNumberInformedOnly was not specified so we assume the default is
false.
+                // hasPhoneNumber was not specified so we assume the default is false.
             }
         }
         else {
@@ -177,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, phoneNumberInformedOnly);
+        WhereOptions whereOptions = buildWhereClause(fields, searchTerm, hasPhoneNumber);
 
         // Get all the id's where the search term matches the fields passed in.
         Cursor idCursor = mApp.getActivity().getContentResolver().query(ContactsContract.Data.CONTENT_URI,
@@ -198,7 +198,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
         idCursor.close();
 
         // Build a query that only looks at ids
-        WhereOptions idOptions = buildIdClause(contactIds, searchTerm, phoneNumberInformedOnly);
+        WhereOptions idOptions = buildIdClause(contactIds, searchTerm, hasPhoneNumber);
 
         // Determine which columns we should be fetching.
         HashSet<String> columnsToFetch = new HashSet<String>();
@@ -472,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, boolean
phoneNumberInformedOnly) {
+    private WhereOptions buildIdClause(Set<String> contactIds, String searchTerm, boolean
hasPhoneNumber) {
         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("%") && !phoneNumberInformedOnly) {
+        if (searchTerm.equals("%") && !hasPhoneNumber) {
             options.setWhere("(" + ContactsContract.Data.CONTACT_ID + " LIKE ? )");
             options.setWhereArgs(new String[] { searchTerm });
             return options;
@@ -551,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, boolean phoneNumberInformedOnly)
{
+  private WhereOptions buildWhereClause(JSONArray fields, String searchTerm, boolean hasPhoneNumber)
{
 
     ArrayList<String> where = new ArrayList<String>();
     ArrayList<String> whereArgs = new ArrayList<String>();
@@ -563,7 +563,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
          */
         if (isWildCardSearch(fields)) {
             // Get all contacts with all properties
-            if ("%".equals(searchTerm) && !phoneNumberInformedOnly) {
+            if ("%".equals(searchTerm) && !hasPhoneNumber) {
                 options.setWhere("(" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?
)");
                 options.setWhereArgs(new String[] { searchTerm });
                 return options;
@@ -613,7 +613,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
         /*
          * Special case for when the user wants all the contacts but
          */
-        if ("%".equals(searchTerm) && !phoneNumberInformedOnly) {
+        if ("%".equals(searchTerm) && !hasPhoneNumber) {
             options.setWhere("(" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ? )");
             options.setWhereArgs(new String[] { searchTerm });
             return options;
@@ -706,7 +706,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
         }
 
         //Only contacts with phone number informed
-        if(phoneNumberInformedOnly){
+        if(hasPhoneNumber){
             if(where.size()>0){
                 selection.insert(0,"(");
                 selection.append(") AND (" + ContactsContract.Contacts.HAS_PHONE_NUMBER +
" = ?)"); 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/4cbbc73b/www/ContactFindOptions.js
----------------------------------------------------------------------
diff --git a/www/ContactFindOptions.js b/www/ContactFindOptions.js
index c42593e..73a497d 100644
--- a/www/ContactFindOptions.js
+++ b/www/ContactFindOptions.js
@@ -24,13 +24,15 @@
  * @constructor
  * @param filter used to match contacts against
  * @param multiple boolean used to determine if more than one contact should be returned
+ * @param desiredFields 
+ * @param hasPhoneNumber boolean used to filter the search and only return contacts that
have a phone number informed
  */
 
-var ContactFindOptions = function(filter, multiple, desiredFields, phoneNumberInformedOnly)
{
+var ContactFindOptions = function(filter, multiple, desiredFields, hasPhoneNumber) {
     this.filter = filter || '';
     this.multiple = (typeof multiple != 'undefined' ? multiple : false);
     this.desiredFields = typeof desiredFields != 'undefined' ? desiredFields : [];
-    this.phoneNumberInformedOnly = typeof phoneNumberInformedOnly != 'undefined' ? phoneNumberInformedOnly
: false;
+    this.hasPhoneNumber = typeof hasPhoneNumber != 'undefined' ? hasPhoneNumber : false;
 };
 
 module.exports = ContactFindOptions;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message