Skip to content

Commit

Permalink
Basic plugin flow for android
Browse files Browse the repository at this point in the history
Echo-like plugin flow implemented for android.
  • Loading branch information
koraybalci committed Dec 26, 2013
1 parent 303cf95 commit 9e071df
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 5 deletions.
67 changes: 62 additions & 5 deletions .gitignore
@@ -1,6 +1,9 @@
# Xcode
# ObjectiveC https://github.com/github/gitignore/blob/master/Objective-C.gitignore
# OS X
.DS_Store
*/build/*

# Xcode
build/
*.pbxuser
!default.pbxuser
*.mode1v3
Expand All @@ -10,12 +13,66 @@
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
profile
*.moved-aside
DerivedData
.idea/
*.hmap
*.xccheckout
*.ipa

#CocoaPods
# CocoaPods
Pods

# Android https://github.com/github/gitignore/blob/master/Android.gitignore
# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Ignore gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Eclipse https://github.com/github/gitignore/blob/master/Global/Eclipse.gitignore
*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath

# TeXlipse plugin
.texlipse
40 changes: 40 additions & 0 deletions plugin.xml
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.ccsoft.plugin.CordovaFacebook"
version="1.0.0">

<name>CordovaFacebook</name>
<description>Cordova plugin that handles Facebook integration in mobile apps.</description>
<author>CCSoft</author>
<keywords>facebook,cordova,ccsoft</keywords>
<license>Apache 2.0 License</license>

<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>

<asset src="www/CordovaFacebook.js" target="plugins/CordovaFacebook.js" />

<!-- android -->
<platform name="android">

<source-file src="src/android/CordovaFacebook.java"
target-dir="src/com/ccsoft/plugin" />

<config-file target="AndroidManifest.xml" parent="/*/application">
<activity android:label="@string/app_name" android:name="com.facebook.LoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
</config-file>

<config-file target="config.xml" parent="/*">
<feature name="CordovaFacebook">
<param name="android-package" value="com.ccsoft.plugin.CordovaFacebook" />
</feature>

</config-file>

</platform>


</plugin>

32 changes: 32 additions & 0 deletions src/android/CordovaFacebook.java
@@ -0,0 +1,32 @@
package com.ccsoft.plugin;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

import android.util.Log;

public class CordovaFacebook extends CordovaPlugin {

private final String TAG = "CordovaFacebook";

@Override
public boolean execute(String action, JSONArray args,
final CallbackContext callbackContext) throws JSONException {
Log.d(TAG, "action:" + action);
cordova.setActivityResultCallback(this);

if (action.equals("login")) {
callbackContext.success("login call ok");
return true;
}
else if (action.equals("logout")) {
callbackContext.success("logout call ok");
return true;
}

return false;
}

}
31 changes: 31 additions & 0 deletions www/CordovaFacebook.js
@@ -0,0 +1,31 @@
var CC;
(function (CC) {
var CordovaFacebook = (function () {
function CordovaFacebook(appId) {
this.appId = appId;
}
CordovaFacebook.prototype.login = function (successcb, failcb) {
window.cordova.exec(function (response) {
console.log("login call successful");
if (successcb)
successcb(response);
}, function (err) {
console.log("login call failed with error: " + err);
if (failcb)
failcb(err);
}, "CordovaFacebook", "login", []);
};

CordovaFacebook.prototype.logout = function (successcb) {
window.cordova.exec(function (response) {
console.log("logout call successful");
if (successcb)
successcb(response);
}, function (err) {
console.log(err);
}, "CordovaFacebook", "logout", []);
};
return CordovaFacebook;
})();
CC.CordovaFacebook = CordovaFacebook;
})(CC || (CC = {}));
29 changes: 29 additions & 0 deletions www/CordovaFacebook.ts
@@ -0,0 +1,29 @@
module CC {
export class CordovaFacebook {
constructor(private appId: string) {
}

login(successcb?: (r: any) => void, failcb?: (err: any) => void) {
(<any>window).cordova.exec(
(response) => {
console.log("login call successful");
if (successcb) successcb(response);
},
(err) => {
console.log("login call failed with error: " + err);
if (failcb) failcb(err);
}, "CordovaFacebook", "login", []);
}

logout(successcb?: (r: any) => void) {
(<any>window).cordova.exec(
(response) => {
console.log("logout call successful");
if (successcb) successcb(response);
},
(err) => {
console.log(err)
}, "CordovaFacebook", "logout", []);
}
}
}

0 comments on commit 9e071df

Please sign in to comment.