You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/01/18 18:33:40 UTC

[4/8] android commit: Add CordovaArguments helper to decode ArrayBuffers

Add CordovaArguments helper to decode ArrayBuffers


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

Branch: refs/heads/master
Commit: ff1d943a6949edec6f87790a223ed1a71277bda5
Parents: 15a5c89
Author: Braden Shepherdson <br...@chromium.org>
Authored: Tue Jan 15 13:21:09 2013 -0500
Committer: Braden Shepherdson <br...@chromium.org>
Committed: Tue Jan 15 13:21:09 2013 -0500

----------------------------------------------------------------------
 framework/src/org/apache/cordova/BinaryEcho.java   |    6 +--
 .../src/org/apache/cordova/CordovaArguments.java   |   36 +++++++++++++++
 2 files changed, 37 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/ff1d943a/framework/src/org/apache/cordova/BinaryEcho.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/BinaryEcho.java b/framework/src/org/apache/cordova/BinaryEcho.java
index ad7393f..38ca939 100644
--- a/framework/src/org/apache/cordova/BinaryEcho.java
+++ b/framework/src/org/apache/cordova/BinaryEcho.java
@@ -25,8 +25,6 @@ import org.apache.cordova.api.PluginResult;
 import org.json.JSONArray;
 import org.json.JSONException;
 
-import android.util.Base64;
-
 public class BinaryEcho extends CordovaPlugin {
 
     /**
@@ -40,9 +38,7 @@ public class BinaryEcho extends CordovaPlugin {
     public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
         try {
             if (action.equals("echo")) {
-                //CordovaJSONArray cdvArgs = (CordovaJSONArray) args;
-                //byte[] data = cdvArgs.getArrayBuffer(0);
-                byte[] data = Base64.decode(args.getString(0), Base64.DEFAULT);
+                byte[] data = CordovaArguments.getArrayBuffer(args, 0);
 
                 // Don't return any result now, since status results will be sent when events come in from broadcast receiver
                 PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, data);

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/ff1d943a/framework/src/org/apache/cordova/CordovaArguments.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaArguments.java b/framework/src/org/apache/cordova/CordovaArguments.java
new file mode 100644
index 0000000..347dc5e
--- /dev/null
+++ b/framework/src/org/apache/cordova/CordovaArguments.java
@@ -0,0 +1,36 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+package org.apache.cordova;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+
+import android.util.Base64;
+import android.util.Log;
+
+public class CordovaArguments {
+    public static byte[] getArrayBuffer(JSONArray args, int index) throws JSONException {
+        Log.i("Braden", "getting array buffer at index " + index);
+        String encoded = args.getString(index);
+        Log.i("Braden", encoded);
+        return Base64.decode(encoded, Base64.DEFAULT);
+    }
+}
+
+