You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/08/17 17:43:42 UTC

[2/2] android commit: Add an Echo plugin for benchmarking purposes.

Add an Echo plugin for benchmarking purposes.


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

Branch: refs/heads/master
Commit: 80654c059df71e3efa198515fd4c0b467edc1b7d
Parents: 999c548
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Aug 16 17:20:46 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Aug 17 11:10:16 2012 -0400

----------------------------------------------------------------------
 framework/res/xml/config.xml               |    1 +
 framework/src/org/apache/cordova/Echo.java |   57 +++++++++++++++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/80654c05/framework/res/xml/config.xml
----------------------------------------------------------------------
diff --git a/framework/res/xml/config.xml b/framework/res/xml/config.xml
index d37aba5..b5da8a8 100644
--- a/framework/res/xml/config.xml
+++ b/framework/res/xml/config.xml
@@ -49,6 +49,7 @@
     <plugin name="Capture" value="org.apache.cordova.Capture"/>
     <plugin name="Battery" value="org.apache.cordova.BatteryListener"/>
     <plugin name="SplashScreen" value="org.apache.cordova.SplashScreen"/>
+    <plugin name="Echo" value="org.apache.cordova.Echo"/>
 </plugins>
 </cordova>
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/80654c05/framework/src/org/apache/cordova/Echo.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Echo.java b/framework/src/org/apache/cordova/Echo.java
new file mode 100644
index 0000000..23654c9
--- /dev/null
+++ b/framework/src/org/apache/cordova/Echo.java
@@ -0,0 +1,57 @@
+/*
+       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.apache.cordova.api.Plugin;
+import org.apache.cordova.api.PluginResult;
+import org.json.JSONArray;
+import org.json.JSONException;
+
+public class Echo extends Plugin {
+
+    /**
+     * Executes the request and returns PluginResult.
+     *
+     * @param action        The action to execute.
+     * @param args          JSONArry of arguments for the plugin.
+     * @param callbackId    The callback id used when calling back into JavaScript.
+     * @return              A PluginResult object with a status and message.
+     */
+    public PluginResult execute(String action, JSONArray args, String callbackId) {
+        try {
+            String result = args.getString(0);
+            if ("echo".equals(action) || "echoAsync".equals(action)) {
+                return new PluginResult(PluginResult.Status.OK, result);
+            }
+        	return new PluginResult(PluginResult.Status.INVALID_ACTION);
+        } catch (JSONException e) {
+            return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
+        }
+    }
+
+    /**
+     * Identifies if action to be executed returns a value and should be run synchronously.
+     *
+     * @param action    The action to execute
+     * @return          T=returns value
+     */
+    public boolean isSynch(String action) {
+        return "echo".equals(action);
+    }
+}