cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [1/2] spec commit: android: Fix up double-callback of Echo plugin.
Date Fri, 04 Jul 2014 02:10:56 GMT
Repository: cordova-mobile-spec
Updated Branches:
  refs/heads/master 15e6e6b3b -> e2ddbd366


android: Fix up double-callback of Echo plugin.


Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/9cf02457
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/9cf02457
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/9cf02457

Branch: refs/heads/master
Commit: 9cf02457f103234271a4e66c9395777c6d159952
Parents: 15e6e6b
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Jul 3 22:10:00 2014 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Jul 3 22:10:00 2014 -0400

----------------------------------------------------------------------
 cordova-plugin-echo/src/android/Echo.java | 99 ++++++++++++--------------
 1 file changed, 44 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/9cf02457/cordova-plugin-echo/src/android/Echo.java
----------------------------------------------------------------------
diff --git a/cordova-plugin-echo/src/android/Echo.java b/cordova-plugin-echo/src/android/Echo.java
index 80e1ac7..91921ba 100644
--- a/cordova-plugin-echo/src/android/Echo.java
+++ b/cordova-plugin-echo/src/android/Echo.java
@@ -42,68 +42,57 @@ public class Echo extends CordovaPlugin {
      * @param action            The action to execute.
      * @param args              JSONArry of arguments for the plugin.
      * @param callbackContext   The callback context from which we were invoked.
-     * @return                  A PluginResult object with a status and message.
      */
     @SuppressLint("NewApi")
-	public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext)
throws JSONException {
-        try {
-            if (action.equals("echo")) {
-                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK,
args.getString(0)));
-                return true;
-            } else if(action.equals("echoAsync")) {
-                cordova.getActivity().runOnUiThread(new Runnable() {
-                    public void run() {
-                    	callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK,
args.optString(0)));
-                    }
-                });
-                return true;
-            } else if(action.equals("echoArrayBuffer")) {
-            	String data = args.optString(0);
-                byte[] rawData= Base64.decode(data, Base64.DEFAULT);
-            	callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, rawData));
-                return true;
-            } else if(action.equals("echoArrayBufferAsync")) {
-                cordova.getThreadPool().execute(new Runnable() {
-                    public void run() {
-                        String data = args.optString(0);
-                        byte[] rawData= Base64.decode(data, Base64.DEFAULT);
-                        callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK,
rawData));
-                    }
-                });
-                return true;
-            } else if(action.equals("echoMultiPart")) {
-            	callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, args.getJSONObject(0)));
-                return true;
-            } else if(action.equals("stopEchoBulk")) {
-                bulkEchoing = false;
-            } else if(action.equals("echoBulk")) {
-                if (bulkEchoing) {
-                    return true;
+    public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext)
throws JSONException {
+        if (action.equals("echo")) {
+            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, args.getString(0)));
+        } else if(action.equals("echoAsync")) {
+            cordova.getActivity().runOnUiThread(new Runnable() {
+                public void run() {
+                    callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK,
args.optString(0)));
                 }
-                final String payload = args.getString(0);
-                final int delayMs = args.getInt(1);
-                bulkEchoing = true;
-                cordova.getThreadPool().execute(new Runnable() {
-                    public void run() {
-                        while (bulkEchoing) {
-                            try {
-                                Thread.sleep(delayMs);
-                            } catch (InterruptedException e) {}
-                            PluginResult pr = new PluginResult(PluginResult.Status.OK, payload);
-                            pr.setKeepCallback(true);
-                            callbackContext.sendPluginResult(pr);
-                        }
+            });
+        } else if(action.equals("echoArrayBuffer")) {
+            String data = args.optString(0);
+            byte[] rawData= Base64.decode(data, Base64.DEFAULT);
+            callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, rawData));
+        } else if(action.equals("echoArrayBufferAsync")) {
+            cordova.getThreadPool().execute(new Runnable() {
+                public void run() {
+                    String data = args.optString(0);
+                    byte[] rawData= Base64.decode(data, Base64.DEFAULT);
+                    callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK,
rawData));
+                }
+            });
+        } else if(action.equals("echoMultiPart")) {
+            callbackContext.sendPluginResult( new PluginResult(PluginResult.Status.OK, args.getJSONObject(0)));
+        } else if(action.equals("stopEchoBulk")) {
+            bulkEchoing = false;
+        } else if(action.equals("echoBulk")) {
+            if (bulkEchoing) {
+                return true;
+            }
+            final String payload = args.getString(0);
+            final int delayMs = args.getInt(1);
+            bulkEchoing = true;
+            cordova.getThreadPool().execute(new Runnable() {
+                public void run() {
+                    while (bulkEchoing) {
+                        try {
+                            Thread.sleep(delayMs);
+                        } catch (InterruptedException e) {}
                         PluginResult pr = new PluginResult(PluginResult.Status.OK, payload);
+                        pr.setKeepCallback(true);
                         callbackContext.sendPluginResult(pr);
                     }
-                });
-                return true;
-            }
-            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
-            return false;
-        } catch (JSONException e) {
-            callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+                    PluginResult pr = new PluginResult(PluginResult.Status.OK, payload);
+                    callbackContext.sendPluginResult(pr);
+                }
+            });
+        } else {
             return false;
         }
+        return true;
     }
 }


Mime
View raw message