Created
August 29, 2015 18:39
-
-
Save jbasinger/38e67ecc3d77be86b77e to your computer and use it in GitHub Desktop.
ReversePlugin Embeded Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" | |
| id="sciencevikinglabs-reverseplugin" version="0.0.1"> | |
| <name>Reverse</name> | |
| <description>Science Vikings Reverse String Plugin</description> | |
| <license>MIT</license> | |
| <keywords>reverse</keywords> | |
| <js-module src="www/reverse.js" name="reverse"> | |
| <clobbers target="reverse" /> | |
| </js-module> | |
| <platform name="android"> | |
| <config-file target="config.xml" parent="/*"> | |
| <feature name="Reverse"> | |
| <param name="android-package" value="com.sciencevikinglabs.reverseplugin.ReversePlugin"/> | |
| </feature> | |
| </config-file> | |
| <source-file src="src/android/ReversePlugin.java" target-dir="src/com/sciencevikinglabs/reverseplugin" /> | |
| </platform> | |
| </plugin> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cordova = require('cordova'); | |
| function Reverse(){ | |
| this.doIt = function(str, successCallback, errorCallback){ | |
| successCallback = successCallback || function(){}; | |
| errorCallback = errorCallback || function(){}; | |
| cordova.exec(successCallback, errorCallback, "Reverse","doIt",[str]); | |
| }; | |
| } | |
| module.exports = new Reverse(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.sciencevikinglabs.reverseplugin; | |
| import org.apache.cordova.CordovaWebView; | |
| import org.apache.cordova.CallbackContext; | |
| import org.apache.cordova.CordovaPlugin; | |
| import org.apache.cordova.CordovaInterface; | |
| import org.json.JSONArray; | |
| import org.json.JSONException; | |
| import org.json.JSONObject; | |
| public class ReversePlugin extends CordovaPlugin { | |
| /** | |
| * Constructor. | |
| */ | |
| public ReversePlugin() { | |
| } | |
| /** | |
| * Sets the context of the Command. This can then be used to do things like | |
| * get file paths associated with the Activity. | |
| * | |
| * @param cordova The context of the main Activity. | |
| * @param webView The CordovaWebView Cordova is running in. | |
| */ | |
| public void initialize(CordovaInterface cordova, CordovaWebView webView) { | |
| super.initialize(cordova, webView); | |
| } | |
| /** | |
| * Executes the request and returns PluginResult. | |
| * | |
| * @param action The action to execute. | |
| * @param args JSONArry of arguments for the plugin. | |
| * @param callbackContext The callback id used when calling back into JavaScript. | |
| * @return True if the action was valid, false if not. | |
| */ | |
| public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { | |
| if(action.equals("doIt")){ | |
| JSONObject r = new JSONObject(); | |
| r.put("value", new StringBuilder(args.get(0).toString()).reverse().toString()); | |
| callbackContext.success(r); | |
| } else { | |
| return false; | |
| } | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment