module.exports = {
JavaScript: 'Everywhere'
};
Powered by
Ruy R. Garcia
@rrgarciach
rrgarciach@gmail.com
github.com/rrgarciach
#include <node.h>
#include <v8.h>
using namespace v8;
Handle<Value> Method(const Arguments& args) {
HandleScope scope;
return scope.Close(String::New("world"));
}
void init(Handle<Object> target) {
target->Set(String::NewSymbol("hello"),
FunctionTemplate::New(Method)->GetFunction());
}
NODE_MODULE(hello, init)
sudo npm install -g cordova
cordova create hello
com.example.hello HelloWorld
cordova platform add ios
cordova platform add amazon-fireos
cordova platform add android
cordova platform add blackberry10
cordova platform add firefoxos
cordova plugin add
org.apache.cordova.core.console
cordova plugin rm
org.apache.cordova.core.console
cordova build ios
cordova run ios
module.exports = function(context) {
...
}
module.exports = function(context) {
var Q = context.requireCordovaModule('q');
var deferral = new Q.defer();
setTimeout(function(){
console.log('hook.js>> end');
deferral.resolve();
}, 1000);
return deferral.promise;
}
console.log("Setting BillPocketPlugin...");
var exec = require('cordova/exec');
module.exports = {
sendPayment: function(arrParams, callback) {
var urlScheme, amount, pin, transaction,
transactionid, tip, identifier, reference, email, phone;
if (arrParams.urlScheme.length > 0
&& typeof arrParams.urlScheme != 'undefined') {
app.arrData.push(arrParams.urlScheme);
} else {
app.arrData.push(arrParams.urlScheme);
app.arrData.push( parseFloat(arrParams.amount).toFixed(2) );
app.arrData.push(arrParams.pin);
app.arrData.push(arrParams.transaction);
app.arrData.push(arrParams.transactionid);
app.arrData.push(arrParams.tip);
app.arrData.push(arrParams.identifier);
app.arrData.push(arrParams.reference);
app.arrData.push(arrParams.email);
app.arrData.push(arrParams.phone);
}
console.log("BillPocketPlugin.js: added to scope.");
exec(callback, callback, "BillPocketPlugin", "sendPayment", app.arrData);
},
callbacksuccess: function(message) {
return message;
},
callbackerror: function() {
return false;
}
};
BillPocketPlugin.js
public class BillPocketPlugin extends CordovaPlugin {
...
private void sendPayment(JSONArray args, CallbackContext callbackContext)
throws JSONException {
Intent intent = new Intent("billpocket.payments.START");
String urlScheme = args.getString(0);
if (urlScheme.length() > 0) {
intent.putExtra("urlScheme", urlScheme);
startActivity(intent);
}
intent.putExtra("amount", args.getString(1));
intent.putExtra("pin", args.getString(2));
intent.putExtra("transaction", args.getString(3));
intent.putExtra("transactionid", args.getString(4));
intent.putExtra("tip", args.getString(5));
intent.putExtra("identifier", args.getString(6));
intent.putExtra("reference", args.getString(7));
intent.putExtra("email", args.getString(8));
intent.putExtra("phone", args.getString(9));
this.callbackContext = callbackContext;
cordova.setActivityResultCallback(this);
cordova.getActivity().startActivityForResult(intent, BP_INTENT_CODE);
}
BillPocketPlugin.java
npm install -g cordova ionic
ionic start myApp tabs
cd myApp
ionic platform add ios
ionic build ios
ionic emulate ios
tns create hello-world
cd hello-world
tns platform add ios
tns platform add android
tns run ios
<Page loaded="onPageLoaded">
<GridLayout rows="auto, *">
<StackLayout orientation="horizontal" row="0">
<TextField width="200" text="{{ task }}" hint="Enter a task" id="task" />
<Button text="Add" tap="add"></Button>
</StackLayout>
<ListView items="{{ tasks }}" row="1">
<ListView.itemTemplate>
<Label text="{{ name }}" />
</ListView.itemTemplate>
</ListView>
</GridLayout>
</Page>
User interface (tasks.xml)
var observableModule = require("data/observable");
var observableArray = require("data/observable-array");
var viewModule = require("ui/core/view");
var tasks = new observableArray.ObservableArray([]);
var pageData = new observableModule.Observable();
var page;
exports.onPageLoaded = function(args) {
page = args.object;
pageData.set("task", "");
pageData.set("tasks", tasks);
page.bindingContext = pageData;
};
exports.add = function() {
tasks.push({ name: pageData.get("task") });
pageData.set("task", "");
viewModule.getViewById( page, "task" ).dismissSoftInput();
};
View model (tasks.js)
label {
margin: 15;
}
textfield {
margin: 15;
}
Styles (app.css)
var application = require("application");
application.mainModule = "tasks";
application.start();
app.js
Prototype
Final
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var led = new five.Led(13);
led.blink(500);
});
var five = require("johnny-five"),
board, nunchuk;
board = new five.Board();
board.on("ready", function() {
new five.Pin("A2").low();
new five.Pin("A3").high();
// Create a new `nunchuk` hardware instance.
nunchuk = new five.Wii.Nunchuk({
freq: 50
});
nunchuk.joystick.on("change", function(err, event) {
console.log(
"joystick " + event.axis,
event.target[event.axis],
event.axis, event.direction
);
});
nunchuk.accelerometer.on("change", function(err, event) {
console.log(
"accelerometer " + event.axis,
event.target[event.axis],
event.axis, event.direction
);
});
Thank you!