From 356b7820e61f0c06882928fd603021f6e0f97bf6 Mon Sep 17 00:00:00 2001 From: Michele Date: Tue, 29 May 2012 10:03:26 -0400 Subject: [PATCH] Added Android AppBlade PhoneGap plugin. --- Android/AppBlade/AppBlade.js | 44 +++++++++++++++++++++ Android/AppBlade/AppBladePlugin.java | 57 ++++++++++++++++++++++++++++ Android/AppBlade/README.md | 19 ++++++++++ 3 files changed, 120 insertions(+) create mode 100644 Android/AppBlade/AppBlade.js create mode 100644 Android/AppBlade/AppBladePlugin.java create mode 100644 Android/AppBlade/README.md diff --git a/Android/AppBlade/AppBlade.js b/Android/AppBlade/AppBlade.js new file mode 100644 index 00000000..47aea49c --- /dev/null +++ b/Android/AppBlade/AppBlade.js @@ -0,0 +1,44 @@ +/** + * AppBlade.js + * + * Phonegap AppBlade Instance plugin + * Copyright (c) AppBlade 2012 + * + */ + +// -------------------------------------------------------- + +var AppBlade = function(){}; + +// -------------------------------------------------------- + +AppBlade.prototype.setupAppBlade = function(project, token, secret, timestamp) { + cordova.exec(null, null, "AppBlade", "setupAppBlade", [project, token, secret, timestamp]); +}; + +AppBlade.prototype.catchAndReportCrashes = function() { + // Automatically set with Register on Android + //cordova.exec("AppBlade.catchAndReportCrashes"); +}; + +AppBlade.prototype.checkAuthentication = function() { + console.log("Checking authentication"); + cordova.exec(null, null, "AppBlade", "checkAuthentication", []); +}; + +AppBlade.prototype.allowFeedbackReporting = function() { + // Not supported yet + //cordova.exec("AppBlade.allowFeedbackReporting"); +}; + +// -------------------------------------------------------- + +cordova.addConstructor(function() { + + if (!window.Cordova) { + window.Cordova = cordova; + }; + + if(!window.plugins) window.plugins = {}; + window.plugins.appBlade = new AppBlade(); +}); \ No newline at end of file diff --git a/Android/AppBlade/AppBladePlugin.java b/Android/AppBlade/AppBladePlugin.java new file mode 100644 index 00000000..e02c96eb --- /dev/null +++ b/Android/AppBlade/AppBladePlugin.java @@ -0,0 +1,57 @@ +/** + * + */ +package com.phonegap.helloworld; + +import org.apache.cordova.api.PluginResult; +import org.json.JSONArray; + +import android.util.Log; + +import com.phonegap.api.Plugin; + +import android.app.Activity; + +import com.appblade.framework.AppBlade; + +/** + * @author micheletitolo + * + */ +public class AppBladePlugin extends Plugin { + public static final String SETUP="setupAppBlade"; + public static final String CHECKAPPROVAL="checkAuthentication"; + /* (non-Javadoc) + * @see org.apache.cordova.api.Plugin#execute(java.lang.String, org.json.JSONArray, java.lang.String) + */ + @Override + public PluginResult execute(String action, JSONArray data, String callbackId) { + PluginResult result = null; + if (SETUP.equals(action)) { + String token = data.optString(2); + String secret = data.optString(1); + String uuid = data.optString(0); + String issuance = data.optString(3); + + AppBlade.register(this.ctx.getApplicationContext(), token, secret, uuid, issuance); + result = new PluginResult(PluginResult.Status.OK); + } + else if (CHECKAPPROVAL.equals(action)) + { + // PhoneGap runs on its own thread. So we need one to display an alert and do our UI on. + this.ctx.runOnUiThread(new Runnable() { + + public void run() { + AppBlade.authorize((Activity) AppBladePlugin.this.ctx); + } + }); + result = new PluginResult(PluginResult.Status.OK); + } + else { + result = new PluginResult(PluginResult.Status.INVALID_ACTION); + } + + return result; + } + +} diff --git a/Android/AppBlade/README.md b/Android/AppBlade/README.md new file mode 100644 index 00000000..3e1353ae --- /dev/null +++ b/Android/AppBlade/README.md @@ -0,0 +1,19 @@ +AppBladeSDK PhoneGap Plugin +=================== + +Plugin for PhoneGap that uses the AppBlade SDK. + +##Installation - Android + +1. Copy `AppBlade.js` into your `www` directory. +2. Add `AppBladePlugin.java` to your project. +3. Follow directions for [adding plugins to your Android project](http://wiki.phonegap.com/w/page/43708611/How%20to%20Install%20a%20PhoneGap%20Plugin%20for%20Android). +3. Follow directions for [adding the AppBlade SDK to your project](http://github.com/AppBlade/SDK), but do not do the last 2 steps where you edit your main activity file. +3. In your `index.html`, register for the `"deviceready"` eventListener, and call the setup method with your SDK keys in this order: project, token, secret, issued timestamp. + +See the Example project included for examples using the other functions of the SDK. + + +##Resources: +###[AppBlade.com](https://appblade.com/) +###[License and Terms](https://appblade.com/terms_of_use) \ No newline at end of file