cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [37/45] android commit: Refactoring based on feedback from Andrew
Date Wed, 23 Sep 2015 19:58:48 GMT
Refactoring based on feedback from Andrew


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/d42c53b0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/d42c53b0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/d42c53b0

Branch: refs/heads/5.0.x
Commit: d42c53b0c7fb04f372fa711dd0481c33be5bf0fe
Parents: e766eae
Author: Joe Bowser <bowserj@apache.org>
Authored: Fri Aug 28 16:50:16 2015 -0700
Committer: Joe Bowser <bowserj@apache.org>
Committed: Mon Sep 21 18:09:29 2015 -0700

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaActivity.java |  3 +-
 .../org/apache/cordova/CordovaInterface.java    |  3 +-
 .../apache/cordova/CordovaInterfaceImpl.java    | 32 ++++++++++++++++++--
 .../src/org/apache/cordova/CordovaPlugin.java   |  7 -----
 .../src/org/apache/cordova/PluginManager.java   | 22 --------------
 5 files changed, 33 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/d42c53b0/framework/src/org/apache/cordova/CordovaActivity.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java
index 171e2a8..43e013b 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -493,8 +493,7 @@ public class CordovaActivity extends Activity {
     @Override
     public void onRequestPermissionsResult(int requestCode, String permissions[],
                                            int[] grantResults) {
-        PluginManager pm = this.appView.getPluginManager();
-        pm.onRequestPermissionResult(requestCode, permissions, grantResults);
+        cordovaInterface.onRequestPermissionResult(requestCode, permissions, grantResults);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/d42c53b0/framework/src/org/apache/cordova/CordovaInterface.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaInterface.java b/framework/src/org/apache/cordova/CordovaInterface.java
index 3fa6e63..2aa0452 100755
--- a/framework/src/org/apache/cordova/CordovaInterface.java
+++ b/framework/src/org/apache/cordova/CordovaInterface.java
@@ -70,5 +70,6 @@ public interface CordovaInterface {
      */
     public ExecutorService getThreadPool();
 
-    public void requestPermission(CordovaPlugin plugin);
+    public void requestPermission(CordovaPlugin plugin, String permission);
+    public void requestPermissions(CordovaPlugin plugin);
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/d42c53b0/framework/src/org/apache/cordova/CordovaInterfaceImpl.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaInterfaceImpl.java b/framework/src/org/apache/cordova/CordovaInterfaceImpl.java
index 146bacb..7b436af 100644
--- a/framework/src/org/apache/cordova/CordovaInterfaceImpl.java
+++ b/framework/src/org/apache/cordova/CordovaInterfaceImpl.java
@@ -38,6 +38,7 @@ public class CordovaInterfaceImpl implements CordovaInterface {
 
     protected ActivityResultHolder savedResult;
     protected CordovaPlugin activityResultCallback;
+    protected CordovaPlugin permissionResultCallback;
     protected String initCallbackService;
     protected int activityResultRequestCode;
 
@@ -162,9 +163,36 @@ public class CordovaInterfaceImpl implements CordovaInterface {
         }
     }
 
-    public void requestPermission(CordovaPlugin plugin)
+    /**
+     * Called by the system when the user grants permissions
+     *
+     * @param requestCode
+     * @param permissions
+     * @param grantResults
+     */
+    public void onRequestPermissionResult(int requestCode, String[] permissions,
+                                          int[] grantResults) {
+        if(permissionResultCallback != null)
+        {
+            permissionResultCallback.onRequestPermissionResult(requestCode, permissions,
grantResults);
+            permissionResultCallback = null;
+        }
+    }
+
+    public void requestPermission(CordovaPlugin plugin, String permission) {
+        permissionResultCallback = plugin;
+        String[] permissions = new String [1];
+        permissions[0] = permission;
+        int requestCode = 1;
+        getActivity().requestPermissions(permissions, requestCode);
+    }
+
+    public void requestPermissions(CordovaPlugin plugin)
     {
-        pluginManager.requestPermission(plugin);
+        permissionResultCallback = plugin;
+        String[] permissions = plugin.getPermissionRequest();
+        int requestCode = 1;
+        getActivity().requestPermissions(permissions, requestCode);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/d42c53b0/framework/src/org/apache/cordova/CordovaPlugin.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaPlugin.java b/framework/src/org/apache/cordova/CordovaPlugin.java
index 6cb2a3c..6e82027 100644
--- a/framework/src/org/apache/cordova/CordovaPlugin.java
+++ b/framework/src/org/apache/cordova/CordovaPlugin.java
@@ -372,13 +372,6 @@ public class CordovaPlugin {
         return permissions;
     }
 
-    /**
-     * requestPermission
-     */
-    public void requestPermission() {
-        cordova.requestPermission(this);
-    }
-
     public boolean hasPermisssion() {
         for(String p : permissions)
         {

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/d42c53b0/framework/src/org/apache/cordova/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java
index e543b04..3afbc18 100755
--- a/framework/src/org/apache/cordova/PluginManager.java
+++ b/framework/src/org/apache/cordova/PluginManager.java
@@ -511,26 +511,4 @@ public class PluginManager {
         }
     }
 
-    /**
-     * Called by the system when the user grants permissions
-     *
-     * @param requestCode
-     * @param permissions
-     * @param grantResults
-     */
-    public void onRequestPermissionResult(int requestCode, String[] permissions,
-                                          int[] grantResults) {
-        if(permissionRequester != null)
-        {
-            permissionRequester.onRequestPermissionResult(requestCode, permissions, grantResults);
-            permissionRequester = null;
-        }
-    }
-
-    public void requestPermission(CordovaPlugin plugin) {
-        permissionRequester = plugin;
-        String[] permissions = plugin.getPermissionRequest();
-        int requestCode = 1;
-        ctx.getActivity().requestPermissions(permissions, requestCode);
-    }
 }


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


Mime
View raw message