forked from phonegap/phonegap-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Android AppBlade PhoneGap plugin.
- Loading branch information
Michele
committed
May 29, 2012
1 parent
45cb165
commit 356b782
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |