Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1D7E111CD0 for ; Fri, 4 Jul 2014 02:10:57 +0000 (UTC) Received: (qmail 43666 invoked by uid 500); 4 Jul 2014 02:10:57 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 43630 invoked by uid 500); 4 Jul 2014 02:10:57 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 43617 invoked by uid 99); 4 Jul 2014 02:10:56 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jul 2014 02:10:56 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B63CF999D70; Fri, 4 Jul 2014 02:10:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org Date: Fri, 04 Jul 2014 02:10:56 -0000 Message-Id: <3807858880764200be9abd55e07ca665@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] spec commit: android: Fix up double-callback of Echo plugin. 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 Authored: Thu Jul 3 22:10:00 2014 -0400 Committer: Andrew Grieve 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; } }