Fil Maj, Adobe Systems
Fil Maj
Vancouver, Canada
Master Exploder at Adobe Systems, eh
Beautiful country, people and culture. Thank you for having me!
Io sono Transformer!
Dov'รจ la birra?
Native apps are kicking web's ass
APIs like accelerometer, compass, contacts, etc.
BUT! Geo is here. Accelerometer is next. W3C DAP group leading the way.
MIT license, as open as it gets!
Acquired by Adobe in November 2011
PhoneGap -> Cordova as Chrome -> WebKit
Get at those sensors!
Full API docs available at docs.phonegap.com
function onSuccess(acceleration) {
console.log('Acceleration X: ' + acceleration.x + '\n' +
'Acceleration Y: ' + acceleration.y + '\n' +
'Acceleration Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
};
function onError(e) {
console.log('Error! ' + e.message);
};
var options = {frequency:100}; // get updates every 100 ms
navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
PhoneGap/Cordova "wraps" your web assets into a native binary.
http://phonegap.com/2012/05/09/phonegap-beliefs-goals-and-philosophy/
Anyone, at any time, can publish anything from anywhere. That is the stuff of revolutions, and our evolution as a species.
http://phonegap.com/2012/05/09/phonegap-beliefs-goals-and-philosophy/
Web-based SDKs for mobile platforms + apps are here, more are coming
Will not wash your dishes.
Web tech is probably not the best choice for this problem.
But! BlackBerry 6+ supports WebGL...
JavaScript
Native Code
var exec = cordova.require('cordova/exec');
exec(function(){}, function(){},
'MyClass', 'MyMethod',
["arguments", "here", 1]
);
res/xml/plugins.xml
www/Cordova.plist
www/plugins.xml
<plugin
name="Accelerometer"
value="org.apache.cordova.AccelListener"
/>
<key>Plugins</key>
<dict>
<key>Accelerometer</key>
<string>CDVAccelerometer</string>
Each project has a native Plugin interface that you need to use
Java! Who is excited?!
Cordova has a AbstractPluginFactoryManager
class (org.apache.cordova.api.AbstractPluginFactoryManager)
Then you define a PluginFactoryManager
class
You can then access the PluginFactory
class
Then you can create Plugin
s! Yus!
...
That was my Java joke, har har
Cordova has a Plugin
abstract class (org.apache.cordova.api.Plugin)
You extend the Plugin class with your own Plugin
You implement a special method:
public abstract PluginResult execute(String action, JSONArray args, String callbackId);
public PluginResult execute(String action, JSONArray args, String callbackId) {
return new PluginResult(PluginResult.Status.OK, "<3");
}
public PluginResult execute(String action, JSONArray args, String callbackId) {
return new PluginResult(PluginResult.Status.ERROR, "you're a bad boy");
}
// Call the JavaScript success callback for this plugin.
// This can be used if the execute code for the plugin is asynchronous
public void success(PluginResult pluginResult, String callbackId) {
this.webView.sendJavascript(pluginResult.toSuccessCallbackString(callbackId));
}
public PluginResult execute(String action, JSONArray args, String callbackId) {
this.callbackId = callbackId;
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
r.setKeepCallback(true);
return r;
}
private void someNativeInvocation() {
this.success(new PluginResult(PluginResult.Status.OK, "we did it!"),
this.callbackId);
}
Good news: identical to Android
Cordova has a CDVPlugin
class
You extend the Plugin class with your own Plugin
NO execute
method
action
parameter directly invokes methods with a specific signature
- (void)MyMethod:(NSArray*)arguments
withDict:(NSDictionary*)options;
CDVPlugin
provides success
and error
methods
- (void)MyMethod:(NSArray*)arguments withDict:(NSDictionary*)options {
NSString* callbackId = [arguments objectAtIndex:0];
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString:@"hi"];
[self success:result callbackId:callbackId];
}
Brand spankin' new: Use PhoneGap as a component in a larger native app
On iOS, this is called Cleaver
http://github.com/apache/incubator-cordova-ios/guides
On Android: CordovaWebView
http://github.com/apache/incubator-cordova-android/tree/CordovaWebView