You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2015/10/28 20:00:06 UTC

[1/4] cordova-plugin-contacts git commit: Refactored ContactManager after feedback

Repository: cordova-plugin-contacts
Updated Branches:
  refs/heads/master e2ece8db8 -> 80864f452


Refactored ContactManager after feedback


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

Branch: refs/heads/master
Commit: 80864f452fd4514bd43575fa6fb5e8ea54f8fc2a
Parents: c7ae850
Author: Joe Bowser <bo...@apache.org>
Authored: Wed Sep 30 12:43:30 2015 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Wed Oct 28 10:38:11 2015 -0700

----------------------------------------------------------------------
 src/android/ContactManager.java | 44 +++++++-----------------------------
 1 file changed, 8 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/80864f45/src/android/ContactManager.java
----------------------------------------------------------------------
diff --git a/src/android/ContactManager.java b/src/android/ContactManager.java
index 2a326dd..86034c2 100644
--- a/src/android/ContactManager.java
+++ b/src/android/ContactManager.java
@@ -62,55 +62,27 @@ public class ContactManager extends CordovaPlugin {
     public static final int SAVE_REQ_CODE = 1;
     public static final int REMOVE_REQ_CODE = 2;
 
+    public static final String READ = Manifest.permission.READ_CONTACTS;
+    public static final String WRITE = Manifest.permission.WRITE_CONTACTS;
+
 
     /**
      * Constructor.
      */
     public ContactManager() {
-        permissions = new String[2];
-        permissions[0] = Manifest.permission.READ_CONTACTS;
-        permissions[1] = Manifest.permission.WRITE_CONTACTS;
-    }
 
-    public String [] requestPermissions()
-    {
-        return permissions;
     }
 
 
-    protected int checkReadPermission()
-    {
-        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
-        {
-            return cordova.getActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS);
-        }
-        else
-        {
-            return PackageManager.PERMISSION_GRANTED;
-        }
-    }
-
     protected void getReadPermission(int requestCode)
     {
-        cordova.requestPermission(this, requestCode, Manifest.permission.READ_CONTACTS);
+        cordova.requestPermission(this, requestCode, READ);
     }
 
 
-    protected int checkWritePermission()
-    {
-        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
-        {
-            return cordova.getActivity().checkSelfPermission(Manifest.permission.WRITE_CONTACTS);
-        }
-        else
-        {
-            return PackageManager.PERMISSION_GRANTED;
-        }
-    }
-
     protected void getWritePermission(int requestCode)
     {
-        cordova.requestPermission(this, requestCode, Manifest.permission.WRITE_CONTACTS);
+        cordova.requestPermission(this, requestCode, WRITE);
     }
 
 
@@ -145,7 +117,7 @@ public class ContactManager extends CordovaPlugin {
         }
 
         if (action.equals("search")) {
-            if(checkReadPermission() != PackageManager.PERMISSION_DENIED) {
+            if(cordova.hasPermission(READ)) {
                 search(executeArgs);
             }
             else
@@ -154,7 +126,7 @@ public class ContactManager extends CordovaPlugin {
             }
         }
         else if (action.equals("save")) {
-            if(checkWritePermission() != PackageManager.PERMISSION_DENIED)
+            if(cordova.hasPermission(WRITE))
             {
                 save(executeArgs);
             }
@@ -164,7 +136,7 @@ public class ContactManager extends CordovaPlugin {
             }
         }
         else if (action.equals("remove")) {
-            if(checkWritePermission() != PackageManager.PERMISSION_DENIED)
+            if(cordova.hasPermission(WRITE))
             {
                 remove(executeArgs);
             }


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


[4/4] cordova-plugin-contacts git commit: Commit of Contacts Plugin with new API

Posted by bo...@apache.org.
Commit of Contacts Plugin with new API


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

Branch: refs/heads/master
Commit: ac9bdbf86534b590a712c3022efed136e958fd69
Parents: e2ece8d
Author: Joe Bowser <bo...@apache.org>
Authored: Mon Aug 31 15:31:17 2015 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Wed Oct 28 10:38:11 2015 -0700

----------------------------------------------------------------------
 src/android/ContactAccessor.java |   2 +
 src/android/ContactManager.java  | 192 +++++++++++++++++++++++++++-------
 2 files changed, 156 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ac9bdbf8/src/android/ContactAccessor.java
----------------------------------------------------------------------
diff --git a/src/android/ContactAccessor.java b/src/android/ContactAccessor.java
index eb3cbbf..2b73d43 100644
--- a/src/android/ContactAccessor.java
+++ b/src/android/ContactAccessor.java
@@ -18,6 +18,8 @@ package org.apache.cordova.contacts;
 
 import java.util.HashMap;
 
+import android.Manifest;
+import android.content.pm.PackageManager;
 import android.util.Log;
 import org.apache.cordova.CordovaInterface;
 import org.json.JSONArray;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/ac9bdbf8/src/android/ContactManager.java
----------------------------------------------------------------------
diff --git a/src/android/ContactManager.java b/src/android/ContactManager.java
index 1bb9c43..cfad416 100644
--- a/src/android/ContactManager.java
+++ b/src/android/ContactManager.java
@@ -19,19 +19,25 @@
 package org.apache.cordova.contacts;
 
 import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaActivity;
 import org.apache.cordova.CordovaPlugin;
 import org.apache.cordova.PluginResult;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import android.Manifest;
 import android.app.Activity;
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.database.Cursor;
+import android.os.Build;
 import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.RawContacts;
 import android.util.Log;
 
+import java.lang.reflect.Method;
+
 public class ContactManager extends CordovaPlugin {
 
     private ContactAccessor contactAccessor;
@@ -48,13 +54,66 @@ public class ContactManager extends CordovaPlugin {
     public static final int NOT_SUPPORTED_ERROR = 5;
     public static final int PERMISSION_DENIED_ERROR = 20;
     private static final int CONTACT_PICKER_RESULT = 1000;
+    public static String [] permissions;
+
+
+    //Request code for the permissions picker (Pick is async and uses intents)
+    public static final int SEARCH_REQ_CODE = 0;
+    public static final int SAVE_REQ_CODE = 1;
+    public static final int REMOVE_REQ_CODE = 2;
+
 
     /**
      * Constructor.
      */
     public ContactManager() {
+        permissions = new String[2];
+        permissions[0] = Manifest.permission.READ_CONTACTS;
+        permissions[1] = Manifest.permission.WRITE_CONTACTS;
+    }
+
+    public String [] requestPermissions()
+    {
+        return permissions;
+    }
+
+
+    protected int checkReadPermission()
+    {
+        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
+        {
+            return cordova.getActivity().checkSelfPermission(Manifest.permission.READ_CONTACTS);
+        }
+        else
+        {
+            return PackageManager.PERMISSION_GRANTED;
+        }
+    }
+
+    protected void getReadPermission(int requestCode)
+    {
+        cordova.requestPermission(this, requestCode, Manifest.permission.READ_CONTACTS);
+    }
+
+
+    protected int checkWritePermission()
+    {
+        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
+        {
+            return cordova.getActivity().checkSelfPermission(Manifest.permission.WRITE_CONTACTS);
+        }
+        else
+        {
+            return PackageManager.PERMISSION_GRANTED;
+        }
+    }
+
+    protected void getWritePermission(int requestCode)
+    {
+        cordova.requestPermission(this, requestCode, Manifest.permission.WRITE_CONTACTS);
     }
 
+
     /**
      * Executes the request and returns PluginResult.
      *
@@ -86,47 +145,33 @@ public class ContactManager extends CordovaPlugin {
         }
 
         if (action.equals("search")) {
-            final JSONArray filter = args.getJSONArray(0);
-            final JSONObject options = args.get(1) == null ? null : args.getJSONObject(1);
-            this.cordova.getThreadPool().execute(new Runnable() {
-                public void run() {
-                    JSONArray res = contactAccessor.search(filter, options);
-                    callbackContext.success(res);
-                }
-            });
+            if(checkReadPermission() != PackageManager.PERMISSION_DENIED) {
+                search(executeArgs);
+            }
+            else
+            {
+                getReadPermission(SEARCH_REQ_CODE);
+            }
         }
         else if (action.equals("save")) {
-            final JSONObject contact = args.getJSONObject(0);
-            this.cordova.getThreadPool().execute(new Runnable(){
-                public void run() {
-                    JSONObject res = null;
-                    String id = contactAccessor.save(contact);
-                    if (id != null) {
-                        try {
-                            res = contactAccessor.getContactById(id);
-                        } catch (JSONException e) {
-                            Log.e(LOG_TAG, "JSON fail.", e);
-                        }
-                    }
-                    if (res != null) {
-                        callbackContext.success(res);
-                    } else {
-                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
-                    }
-                }
-            });
+            if(checkWritePermission() != PackageManager.PERMISSION_DENIED)
+            {
+                save(executeArgs);
+            }
+            else
+            {
+                getWritePermission(SAVE_REQ_CODE);
+            }
         }
         else if (action.equals("remove")) {
-            final String contactId = args.getString(0);
-            this.cordova.getThreadPool().execute(new Runnable() {
-                public void run() {
-                    if (contactAccessor.remove(contactId)) {
-                        callbackContext.success();
-                    } else {
-                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
-                    }
-                }
-            });
+            if(checkWritePermission() != PackageManager.PERMISSION_DENIED)
+            {
+                remove(executeArgs);
+            }
+            else
+            {
+                getWritePermission(REMOVE_REQ_CODE);
+            }
         }
         else if (action.equals("pickContact")) {
             pickContactAsync();
@@ -136,7 +181,55 @@ public class ContactManager extends CordovaPlugin {
         }
         return true;
     }
-    
+
+    private void remove(JSONArray args) throws JSONException {
+        final String contactId = args.getString(0);
+        this.cordova.getThreadPool().execute(new Runnable() {
+            public void run() {
+                if (contactAccessor.remove(contactId)) {
+                    callbackContext.success();
+                } else {
+                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
+                }
+            }
+        });
+    }
+
+    private void save(JSONArray args) throws JSONException {
+        final JSONObject contact = args.getJSONObject(0);
+        this.cordova.getThreadPool().execute(new Runnable(){
+            public void run() {
+                JSONObject res = null;
+                String id = contactAccessor.save(contact);
+                if (id != null) {
+                    try {
+                        res = contactAccessor.getContactById(id);
+                    } catch (JSONException e) {
+                        Log.e(LOG_TAG, "JSON fail.", e);
+                    }
+                }
+                if (res != null) {
+                    callbackContext.success(res);
+                } else {
+                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
+                }
+            }
+        });
+    }
+
+    private void search(JSONArray args) throws JSONException
+    {
+        final JSONArray filter = args.getJSONArray(0);
+        final JSONObject options = args.get(1) == null ? null : args.getJSONObject(1);
+        this.cordova.getThreadPool().execute(new Runnable() {
+            public void run() {
+                JSONArray res = contactAccessor.search(filter, options);
+                callbackContext.success(res);
+            }
+        });
+    }
+
+
     /**
      * Launches the Contact Picker to select a single contact.
      */
@@ -188,4 +281,27 @@ public class ContactManager extends CordovaPlugin {
             this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, UNKNOWN_ERROR));
         }
     }
+
+    public void onRequestPermissionResult(int requestCode, String[] permissions,
+                                             int[] grantResults) throws JSONException
+    {
+        for(int r:grantResults)
+        {
+            if(r == PackageManager.PERMISSION_DENIED)
+            {
+                this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR));
+            }
+        }
+        switch(requestCode)
+        {
+            case SEARCH_REQ_CODE:
+                search(executeArgs);
+                break;
+            case SAVE_REQ_CODE:
+                break;
+            case REMOVE_REQ_CODE:
+                break;
+        }
+    }
+
 }


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


[2/4] cordova-plugin-contacts git commit: Fixed error with permission checking. We should exit the method after the permission is denied.

Posted by bo...@apache.org.
Fixed error with permission checking. We should exit the method after the permission is denied.


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

Branch: refs/heads/master
Commit: 610eb844fada71c58754c5f5573e4451040bcb9f
Parents: ac9bdbf
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Sep 3 08:43:24 2015 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Wed Oct 28 10:38:11 2015 -0700

----------------------------------------------------------------------
 src/android/ContactManager.java | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/610eb844/src/android/ContactManager.java
----------------------------------------------------------------------
diff --git a/src/android/ContactManager.java b/src/android/ContactManager.java
index cfad416..2a326dd 100644
--- a/src/android/ContactManager.java
+++ b/src/android/ContactManager.java
@@ -290,6 +290,7 @@ public class ContactManager extends CordovaPlugin {
             if(r == PackageManager.PERMISSION_DENIED)
             {
                 this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR));
+                return;
             }
         }
         switch(requestCode)


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


[3/4] cordova-plugin-contacts git commit: Adding engine tag

Posted by bo...@apache.org.
Adding engine tag


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

Branch: refs/heads/master
Commit: c7ae850b4f0d0209844e42edcaadcfc2afcbd919
Parents: 610eb84
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Sep 24 15:13:35 2015 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Wed Oct 28 10:38:11 2015 -0700

----------------------------------------------------------------------
 plugin.xml | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/c7ae850b/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 5f4cb3d..36d875a 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -31,6 +31,10 @@
     <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts.git</repo>
     <issue>https://issues.apache.org/jira/browse/CB/component/12320652</issue>
 
+    <engines>
+      <engine name="cordova-android" version=">=5.0.0-dev" />
+    </engines>
+
     <js-module src="www/contacts.js" name="contacts">
         <clobbers target="navigator.contacts" />
     </js-module>


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