Merge pull request #2441 from natural-law/master

Add social protocol & plugin twitter
This commit is contained in:
James Chen 2013-04-26 19:36:13 -07:00
commit c60224a3c4
117 changed files with 4555 additions and 549 deletions

View File

@ -0,0 +1,289 @@
#include "jsb_pluginx_admob_auto.hpp"
#include "jsb_pluginx_spidermonkey_specifics.h"
#include "jsb_pluginx_basic_conversions.h"
using namespace pluginx;
#include "AdsAdmob.h"
template<class T>
static JSBool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) {
TypeTest<T> t;
T* cobj = new T();
js_type_class_t *p;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
assert(p);
JSObject *_tmp = JS_NewObject(cx, p->jsclass, p->proto, p->parentProto);
js_proxy_t *pp;
JS_NEW_PROXY(pp, cobj, _tmp);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(_tmp));
return JS_TRUE;
}
static JSBool empty_constructor(JSContext *cx, uint32_t argc, jsval *vp) {
return JS_FALSE;
}
JSClass *jsb_AdsAdmob_class;
JSObject *jsb_AdsAdmob_prototype;
JSBool js_pluginx_admob_AdsAdmob_addTestDevice(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::AdsAdmob* cobj = (cocos2d::plugin::AdsAdmob *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
const char* arg0;
std::string arg0_tmp; ok &= jsval_to_std_string(cx, argv[0], &arg0_tmp); arg0 = arg0_tmp.c_str();
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->addTestDevice(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_pluginx_admob_AdsAdmob_hideBannerAd(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::AdsAdmob* cobj = (cocos2d::plugin::AdsAdmob *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
cobj->hideBannerAd();
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_admob_AdsAdmob_showBannerAd(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::AdsAdmob* cobj = (cocos2d::plugin::AdsAdmob *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 2) {
cocos2d::plugin::ProtocolAds::EBannerPos arg0;
int arg1;
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->showBannerAd(arg0, arg1);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2);
return JS_FALSE;
}
JSBool js_pluginx_admob_AdsAdmob_getPluginName(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::AdsAdmob* cobj = (cocos2d::plugin::AdsAdmob *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
const char* ret = cobj->getPluginName();
jsval jsret;
jsret = c_string_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_admob_AdsAdmob_getPluginVersion(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::AdsAdmob* cobj = (cocos2d::plugin::AdsAdmob *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
const char* ret = cobj->getPluginVersion();
jsval jsret;
jsret = c_string_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_admob_AdsAdmob_init(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::AdsAdmob* cobj = (cocos2d::plugin::AdsAdmob *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
bool ret = cobj->init();
jsval jsret;
jsret = BOOLEAN_TO_JSVAL(ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_admob_AdsAdmob_initAppInfo(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::AdsAdmob* cobj = (cocos2d::plugin::AdsAdmob *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
TAppInfo arg0;
#pragma warning NO CONVERSION TO NATIVE FOR TAppInfo;
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->initAppInfo(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_pluginx_admob_AdsAdmob_getSDKVersion(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::AdsAdmob* cobj = (cocos2d::plugin::AdsAdmob *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
const char* ret = cobj->getSDKVersion();
jsval jsret;
jsret = c_string_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_admob_AdsAdmob_setDebugMode(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::AdsAdmob* cobj = (cocos2d::plugin::AdsAdmob *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
JSBool arg0;
ok &= JS_ValueToBoolean(cx, argv[0], &arg0);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->setDebugMode(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
extern JSObject *jsb_ProtocolAds_prototype;
void js_pluginx_admob_AdsAdmob_finalize(JSFreeOp *fop, JSObject *obj) {
js_proxy_t* nproxy;
js_proxy_t* jsproxy;
JS_GET_NATIVE_PROXY(jsproxy, obj);
if (jsproxy) {
JS_GET_PROXY(nproxy, jsproxy->ptr);
// cocos2d::plugin::AdsAdmob *nobj = static_cast<cocos2d::plugin::AdsAdmob *>(nproxy->ptr);
// if (nobj)
// delete nobj;
JS_REMOVE_PROXY(nproxy, jsproxy);
}
}
void js_register_pluginx_admob_AdsAdmob(JSContext *cx, JSObject *global) {
jsb_AdsAdmob_class = (JSClass *)calloc(1, sizeof(JSClass));
jsb_AdsAdmob_class->name = "AdsAdmob";
jsb_AdsAdmob_class->addProperty = JS_PropertyStub;
jsb_AdsAdmob_class->delProperty = JS_PropertyStub;
jsb_AdsAdmob_class->getProperty = JS_PropertyStub;
jsb_AdsAdmob_class->setProperty = JS_StrictPropertyStub;
jsb_AdsAdmob_class->enumerate = JS_EnumerateStub;
jsb_AdsAdmob_class->resolve = JS_ResolveStub;
jsb_AdsAdmob_class->convert = JS_ConvertStub;
jsb_AdsAdmob_class->finalize = js_pluginx_admob_AdsAdmob_finalize;
jsb_AdsAdmob_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
JSPropertySpec *properties = NULL;
static JSFunctionSpec funcs[] = {
JS_FN("addTestDevice", js_pluginx_admob_AdsAdmob_addTestDevice, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("hideBannerAd", js_pluginx_admob_AdsAdmob_hideBannerAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("showBannerAd", js_pluginx_admob_AdsAdmob_showBannerAd, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getPluginName", js_pluginx_admob_AdsAdmob_getPluginName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getPluginVersion", js_pluginx_admob_AdsAdmob_getPluginVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("init", js_pluginx_admob_AdsAdmob_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("initAppInfo", js_pluginx_admob_AdsAdmob_initAppInfo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getSDKVersion", js_pluginx_admob_AdsAdmob_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setDebugMode", js_pluginx_admob_AdsAdmob_setDebugMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};
JSFunctionSpec *st_funcs = NULL;
jsb_AdsAdmob_prototype = JS_InitClass(
cx, global,
jsb_ProtocolAds_prototype,
jsb_AdsAdmob_class,
empty_constructor, 0,
properties,
funcs,
NULL, // no static properties
st_funcs);
// make the class enumerable in the registered namespace
JSBool found;
JS_SetPropertyAttributes(cx, global, "AdsAdmob", JSPROP_ENUMERATE | JSPROP_READONLY, &found);
// add the proto and JSClass to the type->js info hash table
TypeTest<cocos2d::plugin::AdsAdmob> t;
js_type_class_t *p;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
if (!p) {
p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
p->type = typeId;
p->jsclass = jsb_AdsAdmob_class;
p->proto = jsb_AdsAdmob_prototype;
p->parentProto = jsb_ProtocolAds_prototype;
HASH_ADD_INT(_js_global_type_ht, type, p);
}
}
void register_all_pluginx_admob(JSContext* cx, JSObject* obj) {
// first, try to get the ns
jsval nsval;
JSObject *ns;
JS_GetProperty(cx, obj, "plugin", &nsval);
if (nsval == JSVAL_VOID) {
ns = JS_NewObject(cx, NULL, NULL, NULL);
nsval = OBJECT_TO_JSVAL(ns);
JS_SetProperty(cx, obj, "plugin", &nsval);
} else {
JS_ValueToObject(cx, nsval, &ns);
}
obj = ns;
js_register_pluginx_admob_AdsAdmob(cx, obj);
}

View File

@ -0,0 +1,25 @@
#ifndef __pluginx_admob_h__
#define __pluginx_admob_h__
#include "jsapi.h"
#include "jsfriendapi.h"
extern JSClass *jsb_AdsAdmob_class;
extern JSObject *jsb_AdsAdmob_prototype;
JSBool js_pluginx_admob_AdsAdmob_constructor(JSContext *cx, uint32_t argc, jsval *vp);
void js_pluginx_admob_AdsAdmob_finalize(JSContext *cx, JSObject *obj);
void js_register_pluginx_admob_AdsAdmob(JSContext *cx, JSObject *global);
void register_all_pluginx_admob(JSContext* cx, JSObject* obj);
JSBool js_pluginx_admob_AdsAdmob_addTestDevice(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_admob_AdsAdmob_hideBannerAd(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_admob_AdsAdmob_showBannerAd(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_admob_AdsAdmob_getPluginName(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_admob_AdsAdmob_getPluginVersion(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_admob_AdsAdmob_init(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_admob_AdsAdmob_initAppInfo(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_admob_AdsAdmob_getSDKVersion(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_admob_AdsAdmob_setDebugMode(JSContext *cx, uint32_t argc, jsval *vp);
#endif

View File

@ -0,0 +1,65 @@
/**
* @module pluginx_admob
*/
var plugin = plugin || {};
/**
* @class AdsAdmob
*/
plugin.AdsAdmob = {
/**
* @method addTestDevice
* @param {const char*}
*/
addTestDevice : function () {},
/**
* @method hideBannerAd
*/
hideBannerAd : function () {},
/**
* @method showBannerAd
* @param {cocos2d::plugin::ProtocolAds::EBannerPos}
* @param {int}
*/
showBannerAd : function () {},
/**
* @method getPluginName
* @return A value converted from C/C++ "const char*"
*/
getPluginName : function () {},
/**
* @method getPluginVersion
* @return A value converted from C/C++ "const char*"
*/
getPluginVersion : function () {},
/**
* @method init
* @return A value converted from C/C++ "bool"
*/
init : function () {},
/**
* @method initAppInfo
* @param {TAppInfo}
*/
initAppInfo : function () {},
/**
* @method getSDKVersion
* @return A value converted from C/C++ "const char*"
*/
getSDKVersion : function () {},
/**
* @method setDebugMode
* @param {bool}
*/
setDebugMode : function () {},
};

View File

@ -198,7 +198,7 @@ void js_register_pluginx_alipay_IAPAlipay(JSContext *cx, JSObject *global) {
JS_FN("payForProduct", js_pluginx_alipay_IAPAlipay_payForProduct, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getSDKVersion", js_pluginx_alipay_IAPAlipay_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setDebugMode", js_pluginx_alipay_IAPAlipay_setDebugMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
JS_FS_END
};
JSFunctionSpec *st_funcs = NULL;

View File

@ -523,7 +523,7 @@ void js_register_pluginx_flurry_AnalyticsFlurry(JSContext *cx, JSObject *global)
JS_FN("logTimedEventEnd", js_pluginx_flurry_AnalyticsFlurry_logTimedEventEnd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getSDKVersion", js_pluginx_flurry_AnalyticsFlurry_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setDebugMode", js_pluginx_flurry_AnalyticsFlurry_setDebugMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
JS_FS_END
};
JSFunctionSpec *st_funcs = NULL;

View File

@ -198,7 +198,7 @@ void js_register_pluginx_nd91_IAPNd91(JSContext *cx, JSObject *global) {
JS_FN("payForProduct", js_pluginx_nd91_IAPNd91_payForProduct, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getSDKVersion", js_pluginx_nd91_IAPNd91_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setDebugMode", js_pluginx_nd91_IAPNd91_setDebugMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
JS_FS_END
};
JSFunctionSpec *st_funcs = NULL;

View File

@ -5,7 +5,7 @@ using namespace pluginx;
#include "PluginManager.h"
#include "ProtocolAnalytics.h"
#include "ProtocolIAP.h"
#include "ProtocolIAPOnLine.h"
#include "ProtocolAds.h"
template<class T>
static JSBool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) {
@ -181,7 +181,7 @@ void js_register_pluginx_protocols_PluginProtocol(JSContext *cx, JSObject *globa
JS_FN("getPluginVersion", js_pluginx_protocols_PluginProtocol_getPluginVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("init", js_pluginx_protocols_PluginProtocol_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setDebugMode", js_pluginx_protocols_PluginProtocol_setDebugMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
JS_FS_END
};
JSFunctionSpec *st_funcs = NULL;
@ -334,7 +334,7 @@ void js_register_pluginx_protocols_PluginManager(JSContext *cx, JSObject *global
static JSFunctionSpec funcs[] = {
JS_FN("unloadPlugin", js_pluginx_protocols_PluginManager_unloadPlugin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("loadPlugin", js_pluginx_protocols_PluginManager_loadPlugin, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
JS_FS_END
};
static JSFunctionSpec st_funcs[] = {
@ -682,7 +682,7 @@ void js_register_pluginx_protocols_ProtocolAnalytics(JSContext *cx, JSObject *gl
JS_FN("logTimedEventEnd", js_pluginx_protocols_ProtocolAnalytics_logTimedEventEnd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getSDKVersion", js_pluginx_protocols_ProtocolAnalytics_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setDebugMode", js_pluginx_protocols_ProtocolAnalytics_setDebugMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
JS_FS_END
};
JSFunctionSpec *st_funcs = NULL;
@ -907,7 +907,7 @@ void js_register_pluginx_protocols_ProtocolIAP(JSContext *cx, JSObject *global)
JS_FN("getSDKVersion", js_pluginx_protocols_ProtocolIAP_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setDebugMode", js_pluginx_protocols_ProtocolIAP_setDebugMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getPluginName", js_pluginx_protocols_ProtocolIAP_getPluginName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
JS_FS_END
};
static JSFunctionSpec st_funcs[] = {
@ -944,34 +944,68 @@ void js_register_pluginx_protocols_ProtocolIAP(JSContext *cx, JSObject *global)
}
JSClass *jsb_ProtocolIAPOnLine_class;
JSObject *jsb_ProtocolIAPOnLine_prototype;
JSClass *jsb_ProtocolAds_class;
JSObject *jsb_ProtocolAds_prototype;
JSBool js_pluginx_protocols_ProtocolIAPOnLine_initDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp)
JSBool js_pluginx_protocols_ProtocolAds_hideBannerAd(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
cobj->hideBannerAd();
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolAds_showBannerAd(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::ProtocolIAPOnLine* cobj = (cocos2d::plugin::ProtocolIAPOnLine *)(proxy ? proxy->ptr : NULL);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
TDeveloperInfo arg0;
ok &= jsval_to_TDeveloperInfo(cx, argv[0], &arg0);
if (argc == 2) {
cocos2d::plugin::ProtocolAds::EBannerPos arg0;
int arg1;
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
ok &= jsval_to_int32(cx, argv[1], (int32_t *)&arg1);
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->initDeveloperInfo(arg0);
cobj->showBannerAd(arg0, arg1);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolIAPOnLine_getPluginVersion(JSContext *cx, uint32_t argc, jsval *vp)
JSBool js_pluginx_protocols_ProtocolAds_getPluginName(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::ProtocolIAPOnLine* cobj = (cocos2d::plugin::ProtocolIAPOnLine *)(proxy ? proxy->ptr : NULL);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
const char* ret = cobj->getPluginName();
jsval jsret;
jsret = c_string_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolAds_getPluginVersion(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
const char* ret = cobj->getPluginVersion();
@ -984,11 +1018,11 @@ JSBool js_pluginx_protocols_ProtocolIAPOnLine_getPluginVersion(JSContext *cx, ui
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolIAPOnLine_init(JSContext *cx, uint32_t argc, jsval *vp)
JSBool js_pluginx_protocols_ProtocolAds_init(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::ProtocolIAPOnLine* cobj = (cocos2d::plugin::ProtocolIAPOnLine *)(proxy ? proxy->ptr : NULL);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
bool ret = cobj->init();
@ -1001,19 +1035,19 @@ JSBool js_pluginx_protocols_ProtocolIAPOnLine_init(JSContext *cx, uint32_t argc,
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolIAPOnLine_payForProduct(JSContext *cx, uint32_t argc, jsval *vp)
JSBool js_pluginx_protocols_ProtocolAds_initAppInfo(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::ProtocolIAPOnLine* cobj = (cocos2d::plugin::ProtocolIAPOnLine *)(proxy ? proxy->ptr : NULL);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
TProductInfo arg0;
ok &= jsval_to_TProductInfo(cx, argv[0], &arg0);
TAppInfo arg0;
#pragma warning NO CONVERSION TO NATIVE FOR TAppInfo;
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cobj->payForProduct(arg0);
cobj->initAppInfo(arg0);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
@ -1021,11 +1055,11 @@ JSBool js_pluginx_protocols_ProtocolIAPOnLine_payForProduct(JSContext *cx, uint3
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolIAPOnLine_getSDKVersion(JSContext *cx, uint32_t argc, jsval *vp)
JSBool js_pluginx_protocols_ProtocolAds_getSDKVersion(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::ProtocolIAPOnLine* cobj = (cocos2d::plugin::ProtocolIAPOnLine *)(proxy ? proxy->ptr : NULL);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
const char* ret = cobj->getSDKVersion();
@ -1038,13 +1072,13 @@ JSBool js_pluginx_protocols_ProtocolIAPOnLine_getSDKVersion(JSContext *cx, uint3
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolIAPOnLine_setDebugMode(JSContext *cx, uint32_t argc, jsval *vp)
JSBool js_pluginx_protocols_ProtocolAds_setDebugMode(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::ProtocolIAPOnLine* cobj = (cocos2d::plugin::ProtocolIAPOnLine *)(proxy ? proxy->ptr : NULL);
cocos2d::plugin::ProtocolAds* cobj = (cocos2d::plugin::ProtocolAds *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 1) {
JSBool arg0;
@ -1058,34 +1092,50 @@ JSBool js_pluginx_protocols_ProtocolIAPOnLine_setDebugMode(JSContext *cx, uint32
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1);
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolIAPOnLine_getPluginName(JSContext *cx, uint32_t argc, jsval *vp)
JSBool js_pluginx_protocols_ProtocolAds_presentScreen(JSContext *cx, uint32_t argc, jsval *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
js_proxy_t *proxy; JS_GET_NATIVE_PROXY(proxy, obj);
cocos2d::plugin::ProtocolIAPOnLine* cobj = (cocos2d::plugin::ProtocolIAPOnLine *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
if (argc == 0) {
const char* ret = cobj->getPluginName();
jsval jsret;
jsret = c_string_to_jsval(cx, ret);
JS_SET_RVAL(cx, vp, jsret);
cocos2d::plugin::ProtocolAds::presentScreen();
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolIAPOnLine_payFailedLocally(JSContext *cx, uint32_t argc, jsval *vp)
JSBool js_pluginx_protocols_ProtocolAds_receiveAd(JSContext *cx, uint32_t argc, jsval *vp)
{
if (argc == 0) {
cocos2d::plugin::ProtocolAds::receiveAd();
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolAds_failedToReceiveAd(JSContext *cx, uint32_t argc, jsval *vp)
{
jsval *argv = JS_ARGV(cx, vp);
JSBool ok = JS_TRUE;
if (argc == 2) {
cocos2d::plugin::EPayResult arg0;
cocos2d::plugin::AdListener::EAdErrorCode arg0;
const char* arg1;
ok &= jsval_to_int32(cx, argv[0], (int32_t *)&arg0);
std::string arg1_tmp; ok &= jsval_to_std_string(cx, argv[1], &arg1_tmp); arg1 = arg1_tmp.c_str();
JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");
cocos2d::plugin::ProtocolIAPOnLine::payFailedLocally(arg0, arg1);
cocos2d::plugin::ProtocolAds::failedToReceiveAd(arg0, arg1);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
JS_ReportError(cx, "wrong number of arguments");
return JS_FALSE;
}
JSBool js_pluginx_protocols_ProtocolAds_dismissScreen(JSContext *cx, uint32_t argc, jsval *vp)
{
if (argc == 0) {
cocos2d::plugin::ProtocolAds::dismissScreen();
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;
}
@ -1097,14 +1147,14 @@ JSBool js_pluginx_protocols_ProtocolIAPOnLine_payFailedLocally(JSContext *cx, ui
extern JSObject *jsb_PluginProtocol_prototype;
void js_pluginx_protocols_ProtocolIAPOnLine_finalize(JSFreeOp *fop, JSObject *obj) {
void js_pluginx_protocols_ProtocolAds_finalize(JSFreeOp *fop, JSObject *obj) {
js_proxy_t* nproxy;
js_proxy_t* jsproxy;
JS_GET_NATIVE_PROXY(jsproxy, obj);
if (jsproxy) {
JS_GET_PROXY(nproxy, jsproxy->ptr);
// cocos2d::plugin::ProtocolIAPOnLine *nobj = static_cast<cocos2d::plugin::ProtocolIAPOnLine *>(nproxy->ptr);
// cocos2d::plugin::ProtocolAds *nobj = static_cast<cocos2d::plugin::ProtocolAds *>(nproxy->ptr);
// if (nobj)
// delete nobj;
@ -1112,41 +1162,45 @@ void js_pluginx_protocols_ProtocolIAPOnLine_finalize(JSFreeOp *fop, JSObject *ob
}
}
void js_register_pluginx_protocols_ProtocolIAPOnLine(JSContext *cx, JSObject *global) {
jsb_ProtocolIAPOnLine_class = (JSClass *)calloc(1, sizeof(JSClass));
jsb_ProtocolIAPOnLine_class->name = "ProtocolIAPOnLine";
jsb_ProtocolIAPOnLine_class->addProperty = JS_PropertyStub;
jsb_ProtocolIAPOnLine_class->delProperty = JS_PropertyStub;
jsb_ProtocolIAPOnLine_class->getProperty = JS_PropertyStub;
jsb_ProtocolIAPOnLine_class->setProperty = JS_StrictPropertyStub;
jsb_ProtocolIAPOnLine_class->enumerate = JS_EnumerateStub;
jsb_ProtocolIAPOnLine_class->resolve = JS_ResolveStub;
jsb_ProtocolIAPOnLine_class->convert = JS_ConvertStub;
jsb_ProtocolIAPOnLine_class->finalize = js_pluginx_protocols_ProtocolIAPOnLine_finalize;
jsb_ProtocolIAPOnLine_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JSObject *global) {
jsb_ProtocolAds_class = (JSClass *)calloc(1, sizeof(JSClass));
jsb_ProtocolAds_class->name = "ProtocolAds";
jsb_ProtocolAds_class->addProperty = JS_PropertyStub;
jsb_ProtocolAds_class->delProperty = JS_PropertyStub;
jsb_ProtocolAds_class->getProperty = JS_PropertyStub;
jsb_ProtocolAds_class->setProperty = JS_StrictPropertyStub;
jsb_ProtocolAds_class->enumerate = JS_EnumerateStub;
jsb_ProtocolAds_class->resolve = JS_ResolveStub;
jsb_ProtocolAds_class->convert = JS_ConvertStub;
jsb_ProtocolAds_class->finalize = js_pluginx_protocols_ProtocolAds_finalize;
jsb_ProtocolAds_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2);
JSPropertySpec *properties = NULL;
static JSFunctionSpec funcs[] = {
JS_FN("initDeveloperInfo", js_pluginx_protocols_ProtocolIAPOnLine_initDeveloperInfo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getPluginVersion", js_pluginx_protocols_ProtocolIAPOnLine_getPluginVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("init", js_pluginx_protocols_ProtocolIAPOnLine_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("payForProduct", js_pluginx_protocols_ProtocolIAPOnLine_payForProduct, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getSDKVersion", js_pluginx_protocols_ProtocolIAPOnLine_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setDebugMode", js_pluginx_protocols_ProtocolIAPOnLine_setDebugMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getPluginName", js_pluginx_protocols_ProtocolIAPOnLine_getPluginName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
JS_FN("hideBannerAd", js_pluginx_protocols_ProtocolAds_hideBannerAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("showBannerAd", js_pluginx_protocols_ProtocolAds_showBannerAd, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getPluginName", js_pluginx_protocols_ProtocolAds_getPluginName, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getPluginVersion", js_pluginx_protocols_ProtocolAds_getPluginVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("init", js_pluginx_protocols_ProtocolAds_init, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("initAppInfo", js_pluginx_protocols_ProtocolAds_initAppInfo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("getSDKVersion", js_pluginx_protocols_ProtocolAds_getSDKVersion, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setDebugMode", js_pluginx_protocols_ProtocolAds_setDebugMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};
static JSFunctionSpec st_funcs[] = {
JS_FN("payFailedLocally", js_pluginx_protocols_ProtocolIAPOnLine_payFailedLocally, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("presentScreen", js_pluginx_protocols_ProtocolAds_presentScreen, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("receiveAd", js_pluginx_protocols_ProtocolAds_receiveAd, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("failedToReceiveAd", js_pluginx_protocols_ProtocolAds_failedToReceiveAd, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("dismissScreen", js_pluginx_protocols_ProtocolAds_dismissScreen, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
};
jsb_ProtocolIAPOnLine_prototype = JS_InitClass(
jsb_ProtocolAds_prototype = JS_InitClass(
cx, global,
jsb_PluginProtocol_prototype,
jsb_ProtocolIAPOnLine_class,
jsb_ProtocolAds_class,
empty_constructor, 0,
properties,
funcs,
@ -1154,18 +1208,18 @@ void js_register_pluginx_protocols_ProtocolIAPOnLine(JSContext *cx, JSObject *gl
st_funcs);
// make the class enumerable in the registered namespace
JSBool found;
JS_SetPropertyAttributes(cx, global, "ProtocolIAPOnLine", JSPROP_ENUMERATE | JSPROP_READONLY, &found);
JS_SetPropertyAttributes(cx, global, "ProtocolAds", JSPROP_ENUMERATE | JSPROP_READONLY, &found);
// add the proto and JSClass to the type->js info hash table
TypeTest<cocos2d::plugin::ProtocolIAPOnLine> t;
TypeTest<cocos2d::plugin::ProtocolAds> t;
js_type_class_t *p;
uint32_t typeId = t.s_id();
HASH_FIND_INT(_js_global_type_ht, &typeId, p);
if (!p) {
p = (js_type_class_t *)malloc(sizeof(js_type_class_t));
p->type = typeId;
p->jsclass = jsb_ProtocolIAPOnLine_class;
p->proto = jsb_ProtocolIAPOnLine_prototype;
p->jsclass = jsb_ProtocolAds_class;
p->proto = jsb_ProtocolAds_prototype;
p->parentProto = jsb_PluginProtocol_prototype;
HASH_ADD_INT(_js_global_type_ht, type, p);
}
@ -1186,9 +1240,9 @@ void register_all_pluginx_protocols(JSContext* cx, JSObject* obj) {
obj = ns;
js_register_pluginx_protocols_PluginProtocol(cx, obj);
js_register_pluginx_protocols_ProtocolAds(cx, obj);
js_register_pluginx_protocols_ProtocolIAP(cx, obj);
js_register_pluginx_protocols_PluginManager(cx, obj);
js_register_pluginx_protocols_ProtocolIAPOnLine(cx, obj);
js_register_pluginx_protocols_ProtocolAnalytics(cx, obj);
}

View File

@ -68,20 +68,24 @@ JSBool js_pluginx_protocols_ProtocolIAP_setDebugMode(JSContext *cx, uint32_t arg
JSBool js_pluginx_protocols_ProtocolIAP_getPluginName(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolIAP_payResult(JSContext *cx, uint32_t argc, jsval *vp);
extern JSClass *jsb_ProtocolIAPOnLine_class;
extern JSObject *jsb_ProtocolIAPOnLine_prototype;
extern JSClass *jsb_ProtocolAds_class;
extern JSObject *jsb_ProtocolAds_prototype;
JSBool js_pluginx_protocols_ProtocolIAPOnLine_constructor(JSContext *cx, uint32_t argc, jsval *vp);
void js_pluginx_protocols_ProtocolIAPOnLine_finalize(JSContext *cx, JSObject *obj);
void js_register_pluginx_protocols_ProtocolIAPOnLine(JSContext *cx, JSObject *global);
JSBool js_pluginx_protocols_ProtocolAds_constructor(JSContext *cx, uint32_t argc, jsval *vp);
void js_pluginx_protocols_ProtocolAds_finalize(JSContext *cx, JSObject *obj);
void js_register_pluginx_protocols_ProtocolAds(JSContext *cx, JSObject *global);
void register_all_pluginx_protocols(JSContext* cx, JSObject* obj);
JSBool js_pluginx_protocols_ProtocolIAPOnLine_initDeveloperInfo(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolIAPOnLine_getPluginVersion(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolIAPOnLine_init(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolIAPOnLine_payForProduct(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolIAPOnLine_getSDKVersion(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolIAPOnLine_setDebugMode(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolIAPOnLine_getPluginName(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolIAPOnLine_payFailedLocally(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_hideBannerAd(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_showBannerAd(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_getPluginName(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_getPluginVersion(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_init(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_initAppInfo(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_getSDKVersion(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_setDebugMode(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_presentScreen(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_receiveAd(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_failedToReceiveAd(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_protocols_ProtocolAds_dismissScreen(JSContext *cx, uint32_t argc, jsval *vp);
#endif

View File

@ -220,15 +220,27 @@ payResult : function () {},
};
/**
* @class ProtocolIAPOnLine
* @class ProtocolAds
*/
plugin.ProtocolIAPOnLine = {
plugin.ProtocolAds = {
/**
* @method initDeveloperInfo
* @param {TDeveloperInfo}
* @method hideBannerAd
*/
initDeveloperInfo : function () {},
hideBannerAd : function () {},
/**
* @method showBannerAd
* @param {cocos2d::plugin::ProtocolAds::EBannerPos}
* @param {int}
*/
showBannerAd : function () {},
/**
* @method getPluginName
* @return A value converted from C/C++ "const char*"
*/
getPluginName : function () {},
/**
* @method getPluginVersion
@ -243,10 +255,10 @@ getPluginVersion : function () {},
init : function () {},
/**
* @method payForProduct
* @param {TProductInfo}
* @method initAppInfo
* @param {TAppInfo}
*/
payForProduct : function () {},
initAppInfo : function () {},
/**
* @method getSDKVersion
@ -261,16 +273,25 @@ getSDKVersion : function () {},
setDebugMode : function () {},
/**
* @method getPluginName
* @return A value converted from C/C++ "const char*"
* @method presentScreen
*/
getPluginName : function () {},
presentScreen : function () {},
/**
* @method payFailedLocally
* @param {cocos2d::plugin::EPayResult}
* @method receiveAd
*/
receiveAd : function () {},
/**
* @method failedToReceiveAd
* @param {cocos2d::plugin::AdListener::EAdErrorCode}
* @param {const char*}
*/
payFailedLocally : function () {},
failedToReceiveAd : function () {},
/**
* @method dismissScreen
*/
dismissScreen : function () {},
};

View File

@ -621,7 +621,7 @@ void js_register_pluginx_umeng_AnalyticsUmeng(JSContext *cx, JSObject *global) {
JS_FN("logTimedEventEnd", js_pluginx_umeng_AnalyticsUmeng_logTimedEventEnd, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("logEventWithLabel", js_pluginx_umeng_AnalyticsUmeng_logEventWithLabel, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FN("setDebugMode", js_pluginx_umeng_AnalyticsUmeng_setDebugMode, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
JS_FS_END
JS_FS_END
};
JSFunctionSpec *st_funcs = NULL;

View File

@ -28,7 +28,7 @@ void register_pluginx_js_extensions(JSContext* cx, JSObject* global)
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return plugin.ProtocolIAP; })()"));
JS_DefineFunction(cx, tmpObj, "setResultListener", js_pluginx_ProtocolIAP_setResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return plugin.ProtocolIAPOnLine; })()"));
JS_DefineFunction(cx, tmpObj, "setLocalResultListener", js_pluginx_ProtocolIAPOnLine_setLocalResultListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
tmpObj = JSVAL_TO_OBJECT(anonEvaluate(cx, global, "(function () { return plugin.ProtocolAds; })()"));
JS_DefineFunction(cx, tmpObj, "setLocalResultListener", js_pluginx_ProtocolAds_setAdListener, 1, JSPROP_READONLY | JSPROP_PERMANENT);
}

View File

@ -1,7 +1,7 @@
#include "jsb_pluginx_manual_iap.h"
#include "jsb_pluginx_basic_conversions.h"
#include "jsb_pluginx_spidermonkey_specifics.h"
#include "ProtocolIAPOnLine.h"
#include "ProtocolAds.h"
using namespace pluginx;
@ -75,10 +75,56 @@ JSBool js_pluginx_ProtocolIAP_setResultListener(JSContext *cx, uint32_t argc, js
return JS_FALSE;
}
class Pluginx_PurchaseLocalResult : public cocos2d::plugin::LocalResultListener
class Pluginx_AdListener : public cocos2d::plugin::AdListener
{
public:
virtual void payFailedLocally(cocos2d::plugin::EPayResult ret, const char* msg)
virtual void onReceiveAd()
{
JSContext* cx = s_cx;
JSBool hasAction;
jsval retval;
jsval temp_retval;
JSObject* obj = m_pJSDelegate;
JSBool bRet = JS_HasProperty(cx, obj, "onReceiveAd", &hasAction);
if (bRet && hasAction) {
if(!JS_GetProperty(cx, obj, "onReceiveAd", &temp_retval)) {
return;
}
if(temp_retval == JSVAL_VOID) {
return;
}
JSAutoCompartment ac(cx, obj);
JS_CallFunctionName(cx, obj, "onReceiveAd",
0, NULL, &retval);
}
}
virtual void onPresentScreen()
{
JSContext* cx = s_cx;
JSBool hasAction;
jsval retval;
jsval temp_retval;
JSObject* obj = m_pJSDelegate;
JSBool bRet = JS_HasProperty(cx, obj, "onPresentScreen", &hasAction);
if (bRet && hasAction) {
if(!JS_GetProperty(cx, obj, "onPresentScreen", &temp_retval)) {
return;
}
if(temp_retval == JSVAL_VOID) {
return;
}
JSAutoCompartment ac(cx, obj);
JS_CallFunctionName(cx, obj, "onPresentScreen",
0, NULL, &retval);
}
}
virtual void onFailedToReceiveAd(EAdErrorCode code, const char* msg)
{
JSContext* cx = s_cx;
@ -86,25 +132,48 @@ public:
jsval retval;
jsval temp_retval;
jsval dataVal[2];
dataVal[0] = INT_TO_JSVAL(ret);
dataVal[0] = INT_TO_JSVAL(code);
std::string strMsgInfo = msg;
dataVal[1] = std_string_to_jsval(cx, strMsgInfo);
JSObject* obj = m_pJSDelegate;
JSBool bRet = JS_HasProperty(cx, obj, "payFailedLocally", &hasAction);
JSBool bRet = JS_HasProperty(cx, obj, "onFailedToReceiveAd", &hasAction);
if (bRet && hasAction) {
if(!JS_GetProperty(cx, obj, "payFailedLocally", &temp_retval)) {
if(!JS_GetProperty(cx, obj, "onFailedToReceiveAd", &temp_retval)) {
return;
}
if(temp_retval == JSVAL_VOID) {
return;
}
JSAutoCompartment ac(cx, obj);
JS_CallFunctionName(cx, obj, "payFailedLocally",
JS_CallFunctionName(cx, obj, "onFailedToReceiveAd",
2, dataVal, &retval);
}
}
virtual void onDismissScreen()
{
JSContext* cx = s_cx;
JSBool hasAction;
jsval retval;
jsval temp_retval;
JSObject* obj = m_pJSDelegate;
JSBool bRet = JS_HasProperty(cx, obj, "onDismissScreen", &hasAction);
if (bRet && hasAction) {
if(!JS_GetProperty(cx, obj, "onDismissScreen", &temp_retval)) {
return;
}
if(temp_retval == JSVAL_VOID) {
return;
}
JSAutoCompartment ac(cx, obj);
JS_CallFunctionName(cx, obj, "onDismissScreen",
0, NULL, &retval);
}
}
void setJSDelegate(JSObject* pJSDelegate)
{
m_pJSDelegate = pJSDelegate;
@ -114,7 +183,7 @@ private:
JSObject* m_pJSDelegate;
};
JSBool js_pluginx_ProtocolIAPOnLine_setLocalResultListener(JSContext *cx, uint32_t argc, jsval *vp)
JSBool js_pluginx_ProtocolAds_setAdListener(JSContext *cx, uint32_t argc, jsval *vp)
{
s_cx = cx;
jsval *argv = JS_ARGV(cx, vp);
@ -122,9 +191,9 @@ JSBool js_pluginx_ProtocolIAPOnLine_setLocalResultListener(JSContext *cx, uint32
if (argc == 1) {
// save the delegate
JSObject *jsDelegate = JSVAL_TO_OBJECT(argv[0]);
Pluginx_PurchaseLocalResult* nativeDelegate = new Pluginx_PurchaseLocalResult();
Pluginx_AdListener* nativeDelegate = new Pluginx_AdListener();
nativeDelegate->setJSDelegate(jsDelegate);
cocos2d::plugin::ProtocolIAPOnLine::setLocalResultListener(nativeDelegate);
cocos2d::plugin::ProtocolAds::setAdListener(nativeDelegate);
JS_SET_RVAL(cx, vp, JSVAL_VOID);
return JS_TRUE;

View File

@ -5,6 +5,6 @@
#include "jsfriendapi.h"
JSBool js_pluginx_ProtocolIAP_setResultListener(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_ProtocolIAPOnLine_setLocalResultListener(JSContext *cx, uint32_t argc, jsval *vp);
JSBool js_pluginx_ProtocolAds_setAdListener(JSContext *cx, uint32_t argc, jsval *vp);
#endif /* __JS_MANUAL_IAP_H__ */

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_ADS_ADMOB_H__
#define __CCX_ADS_ADMOB_H__
@ -13,11 +36,11 @@ class AdsAdmob : public ProtocolAds
public:
typedef enum {
eSizeBanner = 0,
eSizeIABMRect,
eSizeIABBanner,
eSizeIABLeaderboard,
} ESizeAdmobBanner;
kSizeBanner = 0,
kSizeIABMRect,
kSizeIABBanner,
kSizeIABLeaderboard,
} AdmobBannerSize;
/**
@brief plugin initialization
@ -25,25 +48,30 @@ public:
virtual bool init();
/**
@brief initialize the application info
@param appInfo This parameter is the info of application, must contains:
@brief config the application info
@param devInfo This parameter is the info of application, must contains:
AdmobID The publisher ID of admob.
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void initAppInfo(TAppInfo appInfo);
virtual void configDeveloperInfo(TAdsDeveloperInfo devInfo);
/**
@brief show adview
@param type The adview type need to show.
@param sizeEnum The size of the banner view.
(only used when type is kBannerAd)
Use the enum number in AdmobBannerSize.
@param pos The position where the adview be shown.
(only used when type is kBannerAd)
*/
virtual void showAds(AdsType type, int sizeEnum = 0, AdsPos pos = kPosCenter);
/**
@brief show banner ads at specified position
@param pos The position where the banner view be shown
@param sizeEnum The size of the banner view. Use the value in ESizeAdmobBanner
@brief Hide the adview
@param type The adview type need to hide.
*/
virtual void showBannerAd(EBannerPos pos, int sizeEnum);
/**
@brief hide the banner ads view
*/
virtual void hideBannerAd();
virtual void hideAds(AdsType type);
/**
@brief Set whether needs to output logs to console.

View File

@ -23,11 +23,11 @@ cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s
# what headers to parse
headers = %(pluginxdir)s/plugins/admob/include/IAPAlipay.h
headers = %(pluginxdir)s/plugins/admob/include/AdsAdmob.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^CCMenu*$".
classes = IAPAlipay
classes = AdsAdmob
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
@ -53,7 +53,7 @@ base_classes_to_skip =
# classes that create no constructor
# CCSet is special and we will use a hand-written constructor
abstract_classes = IAPAlipay
abstract_classes = AdsAdmob
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = yes

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "AdsAdmob.h"
#include "PluginUtils.h"
@ -14,19 +37,19 @@ bool AdsAdmob::init()
return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.AdsAdmob");
}
void AdsAdmob::initAppInfo(TAppInfo appInfo)
void AdsAdmob::configDeveloperInfo(TAdsDeveloperInfo appInfo)
{
ProtocolAds::initAppInfo(appInfo);
ProtocolAds::configDeveloperInfo(appInfo);
}
void AdsAdmob::showBannerAd(EBannerPos pos, int sizeEnum)
void AdsAdmob::showAds(AdsType type, int sizeEnum, AdsPos pos)
{
ProtocolAds::showBannerAd(pos, sizeEnum);
ProtocolAds::showAds(type, sizeEnum, pos);
}
void AdsAdmob::hideBannerAd()
void AdsAdmob::hideAds(AdsType type)
{
ProtocolAds::hideBannerAd();
ProtocolAds::hideAds(type);
}
const char* AdsAdmob::getSDKVersion()

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.HashSet;
@ -20,18 +43,17 @@ public class AdsAdmob implements AdsAdapter {
private static final String LOG_TAG = "AdsAdmob";
private static Activity mContext = null;
private static boolean bDebug = false;
// private static Handler mHandler = null;
// private static AdsAdmob mAdapter = null;
private static AdsAdmob mAdapter = null;
private AdView adView = null;
private String mPublishID = "";
private Set<String> mTestDevices = null;
private WindowManager mWm = null;
private static final int SIZE_BANNER = 0;
private static final int SIZE_IABMRect = 1;
private static final int SIZE_IABBanner = 2;
private static final int SIZE_IABLeaderboard = 3;
private static final int ADMOB_SIZE_BANNER = 0;
private static final int ADMOB_SIZE_IABMRect = 1;
private static final int ADMOB_SIZE_IABBanner = 2;
private static final int ADMOB_SIZE_IABLeaderboard = 3;
protected static void LogE(String msg, Exception e) {
Log.e(LOG_TAG, msg, e);
@ -46,7 +68,7 @@ public class AdsAdmob implements AdsAdapter {
public AdsAdmob(Context context) {
mContext = (Activity) context;
//mAdapter = this;
mAdapter = this;
}
@Override
@ -60,9 +82,9 @@ public class AdsAdmob implements AdsAdapter {
}
@Override
public void initAppInfo(Hashtable<String, String> appInfo) {
public void configDeveloperInfo(Hashtable<String, String> devInfo) {
try {
mPublishID = appInfo.get("AdmobID");
mPublishID = devInfo.get("AdmobID");
LogD("init AppInfo : " + mPublishID);
} catch (Exception e) {
LogE("initAppInfo, The format of appInfo is wrong", e);
@ -70,7 +92,38 @@ public class AdsAdmob implements AdsAdapter {
}
@Override
public void showBannerAd(int pos, int sizeEnum) {
public void showAds(int adsType, int sizeEnum, int pos) {
switch (adsType) {
case InterfaceAds.ADS_TYPE_BANNER:
showBannerAd(sizeEnum, pos);
break;
case InterfaceAds.ADS_TYPE_FULL_SCREEN:
LogD("Now not support full screen view in Admob");
break;
default:
break;
}
}
@Override
public void spendPoints(int points) {
// do nothing, Admob don't have this function
}
@Override
public void hideAds(int adsType) {
switch (adsType) {
case InterfaceAds.ADS_TYPE_BANNER:
hideBannerAd();
break;
case InterfaceAds.ADS_TYPE_FULL_SCREEN:
break;
default:
break;
}
}
private void showBannerAd(int sizeEnum, int pos) {
final int curPos = pos;
final int curSize = sizeEnum;
@ -89,13 +142,17 @@ public class AdsAdmob implements AdsAdapter {
AdSize size = AdSize.BANNER;
switch (curSize) {
case AdsAdmob.SIZE_BANNER:
case AdsAdmob.ADMOB_SIZE_BANNER:
size = AdSize.BANNER;
break;
case AdsAdmob.SIZE_IABMRect:
case AdsAdmob.ADMOB_SIZE_IABMRect:
size = AdSize.IAB_MRECT;
break;
case AdsAdmob.SIZE_IABBanner:
case AdsAdmob.ADMOB_SIZE_IABBanner:
size = AdSize.IAB_BANNER;
break;
case AdsAdmob.SIZE_IABLeaderboard:
case AdsAdmob.ADMOB_SIZE_IABLeaderboard:
size = AdSize.IAB_LEADERBOARD;
break;
default:
break;
@ -116,7 +173,7 @@ public class AdsAdmob implements AdsAdapter {
}
adView.loadAd(req);
adView.setAdListener(new AdmobAdListener());
adView.setAdListener(new AdmobAdsListener());
if (null == mWm) {
mWm = (WindowManager) mContext.getSystemService("window");
@ -126,8 +183,7 @@ public class AdsAdmob implements AdsAdapter {
});
}
@Override
public void hideBannerAd() {
private void hideBannerAd() {
PluginWrapper.runOnMainThread(new Runnable() {
@Override
public void run() {
@ -150,25 +206,25 @@ public class AdsAdmob implements AdsAdapter {
mTestDevices.add(deviceID);
}
private class AdmobAdListener implements AdListener {
private class AdmobAdsListener implements AdListener {
@Override
public void onDismissScreen(Ad arg0) {
LogD("onDismissScreen invoked");
InterfaceAds.dismissScreen();
InterfaceAds.onAdsResult(mAdapter, InterfaceAds.RESULT_CODE_FullScreenViewDismissed, "Full screen ads view dismissed!");
}
@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
int errorNo = InterfaceAds.UNKNOWN_ERROR;
int errorNo = InterfaceAds.RESULT_CODE_UnknownError;
String errorMsg = "Unknow error";
switch (arg1) {
case NETWORK_ERROR:
errorNo = InterfaceAds.NETWORK_ERROR;
errorNo = InterfaceAds.RESULT_CODE_NetworkError;
errorMsg = "Network error";
break;
case INVALID_REQUEST:
errorNo = InterfaceAds.REQUESTING_ERROR;
errorNo = InterfaceAds.RESULT_CODE_NetworkError;
errorMsg = "The ad request is invalid";
break;
case NO_FILL:
@ -178,7 +234,7 @@ public class AdsAdmob implements AdsAdapter {
break;
}
LogD("failed to receive ad : " + errorNo + " , " + errorMsg);
InterfaceAds.failedToReceiveAd(errorNo, errorMsg);
InterfaceAds.onAdsResult(mAdapter, errorNo, errorMsg);
}
@Override
@ -189,13 +245,13 @@ public class AdsAdmob implements AdsAdapter {
@Override
public void onPresentScreen(Ad arg0) {
LogD("onPresentScreen invoked");
InterfaceAds.presentScreen();
InterfaceAds.onAdsResult(mAdapter, InterfaceAds.RESULT_CODE_FullScreenViewShown, "Full screen ads view shown!");
}
@Override
public void onReceiveAd(Ad arg0) {
LogD("onReceiveAd invoked");
InterfaceAds.receiveAd();
InterfaceAds.onAdsResult(mAdapter, InterfaceAds.RESULT_CODE_AdsReceived, "Ads request received success!");
}
}
}

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_IAP_ALIPAY_H__
#define __CCX_IAP_ALIPAY_H__
@ -17,7 +40,7 @@ public:
virtual bool init();
/**
@brief initialize the developer info
@brief config the developer info
@param devInfo This parameter is the info of developer, must contains key:
AlipayPartner The partner id of alipay account
AlipaySeller The seller id of alipay account
@ -28,7 +51,7 @@ public:
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void initDeveloperInfo(TDeveloperInfo devInfo);
virtual void configDeveloperInfo(TIAPDeveloperInfo devInfo);
/**
@brief pay for product

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "IAPAlipay.h"
#include "PluginUtils.h"
@ -18,7 +41,7 @@ bool IAPAlipay::init()
}
/**
@brief initialize the developer info
@brief config the developer info
@param devInfo This parameter is the info of developer, must contains key:
AlipayPartner The partner id of alipay account
AlipaySeller The seller id of alipay account
@ -29,9 +52,9 @@ bool IAPAlipay::init()
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
void IAPAlipay::initDeveloperInfo(TDeveloperInfo devInfo)
void IAPAlipay::configDeveloperInfo(TIAPDeveloperInfo devInfo)
{
ProtocolIAP::initDeveloperInfo(devInfo);
ProtocolIAP::configDeveloperInfo(devInfo);
}
/**

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.net.URLEncoder;
@ -51,7 +74,7 @@ public class IAPAlipay implements IAPAdapter {
}
@Override
public void initDeveloperInfo(Hashtable<String, String> cpInfo) {
public void configDeveloperInfo(Hashtable<String, String> cpInfo) {
LogD("initDeveloperInfo invoked " + cpInfo.toString());
try {
PartnerConfig.PARTNER = cpInfo.get("AlipayPartner");
@ -312,7 +335,7 @@ public class IAPAlipay implements IAPAdapter {
}
private static void payResult(int ret, String msg) {
InterfaceIAP.payResult(ret, msg);
InterfaceIAP.onPayResult(mAdapter, ret, msg);
LogD("Alipay result : " + ret + " msg : " + msg);
}
}

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_ANALYTICS_FLURRY_H__
#define __CCX_ANALYTICS_FLURRY_H__

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "AnalyticsFlurry.h"
#include "PluginJniHelper.h"
#include <android/log.h>

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "AnalyticsFlurry.h"
#include "Flurry.h"

View File

@ -1,61 +0,0 @@
#include "AnalyticsFlurry.h"
namespace cocos2d { namespace plugin {
PLUGIN_REGISTER_IMPL(AnalyticsFlurry)
AnalyticsFlurry::~AnalyticsFlurry()
{
}
bool AnalyticsFlurry::init()
{
return true;
}
void AnalyticsFlurry::setReportLocation(bool enabled)
{
}
void AnalyticsFlurry::logPageView()
{
}
void AnalyticsFlurry::setVersionName(const char* versionName)
{
}
void AnalyticsFlurry::setAge(int age)
{
}
void AnalyticsFlurry::setGender(Gender gender)
{
}
void AnalyticsFlurry::setUserId(const char* userId)
{
}
void AnalyticsFlurry::setUseHttps(bool useHttps)
{
}
void AnalyticsFlurry::logTimedEventBegin(const char* eventId)
{
}
void AnalyticsFlurry::logTimedEventBegin(const char* eventId, LogEventParamMap* paramMap)
{
}
}} // namespace cocos2d { namespace plugin {

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_IAP_ND91_H__
#define __CCX_IAP_ND91_H__
@ -17,7 +40,7 @@ public:
virtual bool init();
/**
@brief initialize the developer info
@brief config the developer info
@param devInfo This parameter is the info of developer, must contains key:
Nd91AppId The app id of nd91
Nd91AppKey The app key of nd91
@ -26,7 +49,7 @@ public:
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void initDeveloperInfo(TDeveloperInfo devInfo);
virtual void configDeveloperInfo(TIAPDeveloperInfo devInfo);
/**
@brief pay for product

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "IAPNd91.h"
#include "PluginUtils.h"
@ -18,7 +41,7 @@ bool IAPNd91::init()
}
/**
@brief initialize the developer info
@brief config the developer info
@param devInfo This parameter is the info of developer, must contains key:
Nd91AppId The app id of nd91
Nd91AppKey The app key of nd91
@ -27,9 +50,9 @@ bool IAPNd91::init()
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
void IAPNd91::initDeveloperInfo(TDeveloperInfo devInfo)
void IAPNd91::configDeveloperInfo(TIAPDeveloperInfo devInfo)
{
ProtocolIAP::initDeveloperInfo(devInfo);
ProtocolIAP::configDeveloperInfo(devInfo);
}
/**

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;
@ -21,6 +44,7 @@ public class IAPNd91 implements IAPAdapter {
private static final String LOG_TAG = "IAPNd91";
private static Activity mContext = null;
private static IAPNd91 mNd91 = null;
private static boolean bDebug = false;
private static Hashtable<String, String> curProductInfo = null;
@ -37,10 +61,11 @@ public class IAPNd91 implements IAPAdapter {
public IAPNd91(Context context) {
mContext = (Activity) context;
mNd91 = this;
}
@Override
public void initDeveloperInfo(Hashtable<String, String> cpInfo) {
public void configDeveloperInfo(Hashtable<String, String> cpInfo) {
LogD("initDeveloperInfo invoked " + cpInfo.toString());
final Hashtable<String, String> curCPInfo = cpInfo;
PluginWrapper.runOnMainThread(new Runnable() {
@ -125,7 +150,7 @@ public class IAPNd91 implements IAPAdapter {
}
private static void payResult(int ret, String msg) {
InterfaceIAP.payResult(ret, msg);
InterfaceIAP.onPayResult(mNd91, ret, msg);
LogD("Nd91 result : " + ret + " msg : " + msg);
}

View File

@ -0,0 +1,76 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_SOCIAL_TWITTER_H__
#define __CCX_SOCIAL_TWITTER_H__
#include "ProtocolSocial.h"
#include <map>
#include <string>
namespace cocos2d { namespace plugin {
class SocialTwitter : public ProtocolSocial
{
PLUGIN_REGISTER_DECL(SocialTwitter)
public:
/**
@brief plugin initialization
*/
virtual bool init();
/**
@brief config the developer info
@param devInfo This parameter is the info of developer, must contains key:
TwitterKey The consumerkey of twitter account
TwitterSecret The consumersecret of twitter account
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void configDeveloperInfo(TSocialDeveloperInfo devInfo);
/**
@brief pay for product
@param info The info of product, can contains key:
SharedText The text need to share
SharedImagePath The full path of image file need to share (optinal)
@warning For different plugin, the parameter should have other keys to pay.
Look at the manual of plugins.
*/
virtual void share(TShareInfo info);
/**
@brief Set whether needs to output logs to console.
@param debug if true debug mode enabled, or debug mode disabled.
*/
virtual void setDebugMode(bool debug);
virtual const char* getPluginVersion() { return "v0.1.01"; };
virtual const char* getSDKVersion();
virtual ~SocialTwitter();
};
}} // namespace cocos2d { namespace plugin {
#endif /* __CCX_SOCIAL_TWITTER_H__ */

View File

@ -0,0 +1,55 @@
#include "SocialTwitter.h"
#include "PluginUtils.h"
namespace cocos2d { namespace plugin {
PLUGIN_REGISTER_IMPL(SocialTwitter)
SocialTwitter::~SocialTwitter()
{
}
/**
@brief plugin initialization
*/
bool SocialTwitter::init()
{
return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.SocialTwitter");
}
/**
@brief config the developer info
@param devInfo This parameter is the info of developer, must contains key:
TwitterKey The consumerkey of twitter account
TwitterSecret The consumersecret of twitter account
More: https://dev.twitter.com
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
void SocialTwitter::configDeveloperInfo(TSocialDeveloperInfo devInfo)
{
ProtocolSocial::configDeveloperInfo(devInfo);
}
/**
@brief pay for product
@param info The info of product, must contains key:
SharedText The text need to share
SharedImagePath The full path of image file need to share (optinal)
*/
void SocialTwitter::share(TShareInfo info)
{
ProtocolSocial::share(info);
}
const char* SocialTwitter::getSDKVersion()
{
return ProtocolSocial::getSDKVersion();
}
void SocialTwitter::setDebugMode(bool debug)
{
ProtocolSocial::setDebugMode(debug);
}
}} // namespace cocos2d { namespace plugin {

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="lib" path="sdk/signpost-commonshttp4-1.2.1.1.jar"/>
<classpathentry exported="true" kind="lib" path="sdk/signpost-core-1.2.1.1.jar"/>
<classpathentry exported="true" kind="lib" path="sdk/signpost-jetty6-1.2.1.1.jar"/>
<classpathentry exported="true" kind="lib" path="sdk/twitter4j-core-android-3.0.1.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>libPluginTwitter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>android</name>
<type>2</type>
<locationURI>PARENT-1-PROJECT_LOC/platform/android</locationURI>
</link>
<link>
<name>include</name>
<type>2</type>
<locationURI>PARENT-1-PROJECT_LOC/include</locationURI>
</link>
</linkedResources>
</projectDescription>

View File

@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.cocos2dx.libSocialTwitter"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
</manifest>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifestConfig xmlns:android="http://schemas.android.com/apk/res/android">
<permissionCfg>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</permissionCfg>
</manifestConfig>

View File

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="libPluginSocialTwitter" default="plugin-publish">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${plugin.dir}/tools/android/build_common.xml" />
</project>

View File

@ -0,0 +1,20 @@
# set params
PLUGIN_ANDROID_ROOT=$(cd "$(dirname "$0")"; pwd)
if [ ! "${PLUGIN_ROOT}" ]; then
PLUGIN_ROOT="$PLUGIN_ANDROID_ROOT"/../..
fi
# build
"$ANDROID_NDK_ROOT"/ndk-build -C "$PLUGIN_ANDROID_ROOT" \
NDK_MODULE_PATH="$PLUGIN_ROOT"
echo
if [ "0" != "$?" ]; then
echo "Build error occoured!!!"
exit 1
fi
echo
echo "Native build action success."
exit 0

View File

@ -0,0 +1,29 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := PluginTwitterStatic
LOCAL_MODULE_FILENAME := libPluginTwitterStatic
LOCAL_SRC_FILES := \
$(addprefix ../../platform/android/, \
SocialTwitter.cpp \
) \
LOCAL_CFLAGS :=
LOCAL_EXPORT_CFLAGS :=
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../include
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../include
LOCAL_WHOLE_STATIC_LIBRARIES := PluginProtocolStatic
LOCAL_LDLIBS := -landroid
LOCAL_LDLIBS += -llog
include $(BUILD_STATIC_LIBRARY)
$(call import-module, protocols/proj.android/jni)

View File

@ -0,0 +1,7 @@
# it is needed for ndk-r5
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
APP_MODULES := PluginTwitterStatic
APP_ABI :=armeabi
#APP_ABI :=x86
#APP_ABI :=mips mips-r2 mips-r2-sf armeabi

View File

@ -0,0 +1,16 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-7
android.library=true
android.library.reference.1=../../../protocols/proj.android

View File

View File

@ -0,0 +1 @@
62d02b6f0d450b3b64d061280594018742ddcd27

View File

@ -0,0 +1,9 @@
package org.cocos2dx.plugin;
public interface Consts {
public static int EGETTING_ACCESS_TOKEN =0;
public static int EUSER_CANCELED = 1;
public static int EGETTING_REQUEST_TOKEN=2;
public static int EFAILED_OPENING_AUTHORIZATION_PAGE=3;
public static int EPAGE_ERROR =4;
}

View File

@ -0,0 +1,191 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;
import org.cocos2dx.plugin.InterfaceSocial.ShareAdapter;
import org.cocos2dx.plugin.TwitterApp.TwDialogListener;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
public class SocialTwitter implements ShareAdapter {
private static final String LOG_TAG = "SocialTwitter";
private static Activity mContext = null;
private static ShareAdapter mSocialAdapter = null;
protected static boolean bDebug = false;
private static String CONSUMER_KEY="";
private static String CONSUMER_SECRET="";
private static TwitterApp mTwitter = null;
private static boolean isInitialized = false;
private static Hashtable<String, String> mShareInfo = null;
public static String KEY_TEXT="SharedText";
public static String KEY_IMAGE_PATH = "SharedImagePath";
protected static void LogE(String msg, Exception e) {
Log.e(LOG_TAG, msg, e);
e.printStackTrace();
}
protected static void LogD(String msg) {
if (bDebug) {
Log.d(LOG_TAG, msg);
}
}
public SocialTwitter(Context context) {
mContext = (Activity) context;
mSocialAdapter = this;
}
@Override
public void configDeveloperInfo(Hashtable<String, String> cpInfo) {
LogD("initDeveloperInfo invoked " + cpInfo.toString());
try {
SocialTwitter.CONSUMER_KEY = cpInfo.get("TwitterKey");
SocialTwitter.CONSUMER_SECRET = cpInfo.get("TwitterSecret");
LogD("key : " + SocialTwitter.CONSUMER_KEY);
LogD("secret : " + SocialTwitter.CONSUMER_SECRET);
if(isInitialized){
return;
}
isInitialized = true;
PluginWrapper.runOnMainThread(new Runnable() {
@Override
public void run() {
mTwitter = new TwitterApp(PluginWrapper.getContext(), SocialTwitter.CONSUMER_KEY, SocialTwitter.CONSUMER_SECRET);
mTwitter.setListener(mTwLoginDialogListener);
}
});
} catch (Exception e) {
LogE("Developer info is wrong!", e);
}
}
@Override
public void share(Hashtable<String, String> info) {
LogD("share invoked " + info.toString());
mShareInfo = info;
if (! networkReachable()) {
shareResult(InterfaceSocial.SHARERESULT_FAIL, "Network error!");
return;
}
if (! isInitialized) {
shareResult(InterfaceSocial.SHARERESULT_FAIL, "Initialize failed!");
return;
}
// need login
if(!mTwitter.hasAccessToken()){
PluginWrapper.runOnMainThread(new Runnable() {
@Override
public void run() {
mTwitter.authorize();
}
});
return;
}
PluginWrapper.runOnMainThread(new Runnable() {
@Override
public void run() {
SocialTwitter.sendToTwitter();
}
});
}
@Override
public void setDebugMode(boolean debug) {
bDebug = debug;
}
@Override
public String getSDKVersion() {
return "Unknown version";
}
private boolean networkReachable() {
boolean bRet = false;
try {
ConnectivityManager conn = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = conn.getActiveNetworkInfo();
bRet = (null == netInfo) ? false : netInfo.isAvailable();
} catch (Exception e) {
LogE("Fail to check network status", e);
}
LogD("NetWork reachable : " + bRet);
return bRet;
}
private static void shareResult(int ret, String msg) {
InterfaceSocial.onShareResult(mSocialAdapter, ret, msg);
LogD("SocialTwitter result : " + ret + " msg : " + msg);
}
private static final TwDialogListener mTwLoginDialogListener = new TwDialogListener() {
@Override
public void onError(int flag, String value) {
LogD("Twitter connection failed!");
shareResult(InterfaceSocial.SHARERESULT_FAIL, value);
}
@Override
public void onComplete(String value) {
SocialTwitter.sendToTwitter();
}
};
private static void sendToTwitter() {
String text = mShareInfo.get(KEY_TEXT);
String imagePath = mShareInfo.get(KEY_IMAGE_PATH);
try {
if(imagePath != null && imagePath.length() > 0){
mTwitter.updateStatus(text, imagePath);
}else{
mTwitter.updateStatus(text);
}
LogD("Posted to Twitter!");
shareResult(InterfaceSocial.SHARERESULT_SUCCESS, "Share succeed!");
} catch (Exception e) {
LogD("Post to Twitter failed!");
shareResult(InterfaceSocial.SHARERESULT_FAIL, "Unknown error!");
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,235 @@
/**
* @author Lorensius W. L. T <lorenz@londatiga.net>
*
* http://www.londatiga.net
*/
package org.cocos2dx.plugin;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import twitter4j.StatusUpdate;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.User;
import twitter4j.auth.AccessToken;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Window;
public class TwitterApp {
private Twitter mTwitter;
private TwitterSession mSession;
private AccessToken mAccessToken;
private CommonsHttpOAuthConsumer mHttpOauthConsumer;
private OAuthProvider mHttpOauthprovider;
private String mConsumerKey;
private String mSecretKey;
private ProgressDialog mProgressDlg;
private TwDialogListener mListener;
private Context context;
private boolean mInit = true;
private static final String LOG_TAG = "TwitterApp";
public static final String CALLBACK_URL = "twitterapp://connect";
protected static void LogE(String msg, Exception e) {
Log.e(LOG_TAG, msg, e);
e.printStackTrace();
}
protected static void LogD(String msg) {
if (SocialTwitter.bDebug) {
Log.d(LOG_TAG, msg);
}
}
public TwitterApp(Context context, String consumerKey, String secretKey) {
this.context = context;
mTwitter = new TwitterFactory().getInstance();
mSession = new TwitterSession(context);
mProgressDlg = new ProgressDialog(context);
mProgressDlg.setCancelable(false);
mProgressDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
mConsumerKey = consumerKey;
mSecretKey = secretKey;
mHttpOauthConsumer = new CommonsHttpOAuthConsumer(mConsumerKey, mSecretKey);
mHttpOauthprovider = new DefaultOAuthProvider("https://twitter.com/oauth/request_token",
"https://twitter.com/oauth/access_token",
"https://twitter.com/oauth/authorize");
mAccessToken = mSession.getAccessToken();
configureToken();
}
public void setListener(TwDialogListener listener) {
mListener = listener;
}
private void configureToken() {
if (mAccessToken != null) {
if (mInit) {
mTwitter.setOAuthConsumer(mConsumerKey, mSecretKey);
mInit = false;
}
mTwitter.setOAuthAccessToken(mAccessToken);
}
}
public boolean hasAccessToken() {
return (mAccessToken == null) ? false : true;
}
public void resetAccessToken() {
if (mAccessToken != null) {
mSession.resetAccessToken();
mAccessToken = null;
}
}
public String getUsername() {
return mSession.getUsername();
}
public void updateStatus(String status) throws Exception {
try {
mTwitter.updateStatus(status);
} catch (TwitterException e) {
throw e;
}
}
public void updateStatus(String status, String imagePath) throws Exception {
StatusUpdate update = new StatusUpdate(status);
update.setMedia(new File(imagePath));
try {
mTwitter.updateStatus(update);
} catch (TwitterException e) {
throw e;
}
}
public void authorize() {
mProgressDlg.setMessage("Initializing ...");
mProgressDlg.show();
new Thread() {
@Override
public void run() {
String authUrl = "";
int what = 1;
try {
authUrl = mHttpOauthprovider.retrieveRequestToken(mHttpOauthConsumer, CALLBACK_URL);
what = 0;
LogD("Request token url " + authUrl);
} catch (Exception e) {
LogD("Failed to get request token");
e.printStackTrace();
}
mHandler.sendMessage(mHandler.obtainMessage(what, 1, 0, authUrl));
}
}.start();
}
public void processToken(String callbackUrl) {
mProgressDlg.setMessage("Finalizing ...");
mProgressDlg.show();
final String verifier = getVerifier(callbackUrl);
new Thread() {
@Override
public void run() {
int what = 1;
try {
mHttpOauthprovider.retrieveAccessToken(mHttpOauthConsumer, verifier);
mAccessToken = new AccessToken(mHttpOauthConsumer.getToken(), mHttpOauthConsumer.getTokenSecret());
configureToken();
User user = mTwitter.verifyCredentials();
mSession.storeAccessToken(mAccessToken, user.getName());
what = 0;
} catch (Exception e){
LogD("Error getting access token");
e.printStackTrace();
}
mHandler.sendMessage(mHandler.obtainMessage(what, 2, 0));
}
}.start();
}
private String getVerifier(String callbackUrl) {
String verifier = "";
try {
callbackUrl = callbackUrl.replace("twitterapp", "http");
URL url = new URL(callbackUrl);
String query = url.getQuery();
String array[] = query.split("&");
for (String parameter : array) {
String v[] = parameter.split("=");
if (URLDecoder.decode(v[0]).equals(oauth.signpost.OAuth.OAUTH_VERIFIER)) {
verifier = URLDecoder.decode(v[1]);
break;
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
return verifier;
}
private void showLoginDialog(String url) {
final TwDialogListener listener = new TwDialogListener() {
@Override
public void onComplete(String value) {
processToken(value);
}
@Override
public void onError(int flag, String value) {
mListener.onError(Consts.EFAILED_OPENING_AUTHORIZATION_PAGE, "Failed opening authorization page");
}
};
new TwitterDialog(context, url, listener).show();
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
mProgressDlg.dismiss();
if (msg.what == 1) {
if (msg.arg1 == 1)
mListener.onError(Consts.EGETTING_REQUEST_TOKEN, "Error getting request token");
else
mListener.onError(Consts.EGETTING_ACCESS_TOKEN, "Error getting access token");
}else {
if (msg.arg1 == 1)
showLoginDialog((String) msg.obj);
else
mListener.onComplete("");
}
}
};
public interface TwDialogListener {
public void onComplete(String value);
public void onError(int flag, String value);
}
}

View File

@ -0,0 +1,182 @@
/**
* Modified from FbDialog from Facebook SDK
*
* Lorensius W. L. T <lorenz@londatiga.net>
*/
package org.cocos2dx.plugin;
import org.cocos2dx.plugin.TwitterApp.TwDialogListener;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
public class TwitterDialog extends Dialog {
static final FrameLayout.LayoutParams FILL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
static final int MARGIN = 4;
static final int PADDING = 2;
private String mUrl;
private TwDialogListener mListener;
private ProgressDialog mSpinner;
private WebView mWebView;
private LinearLayout mContent;
private TextView mTitle;
private static final String LOG_TAG = "Twitter-WebView";
protected static void LogD(String msg) {
if (SocialTwitter.bDebug) {
Log.d(LOG_TAG, msg);
}
}
public TwitterDialog(Context context, String url, TwDialogListener listener) {
super(context);
mUrl = url;
mListener = listener;
setOnCancelListener(mCancelListener);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSpinner = new ProgressDialog(getContext());
mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
mSpinner.setMessage("Loading...");
mSpinner.setCancelable(false);
mContent = new LinearLayout(getContext());
mContent.setOrientation(LinearLayout.VERTICAL);
setUpTitle();
setUpWebView();
Display display = getWindow().getWindowManager().getDefaultDisplay();
double[] dimensions = new double[2];
if (display.getWidth() < display.getHeight()) {
dimensions[0] = 0.87 * display.getWidth();
dimensions[1] = 0.82 * display.getHeight();
} else {
dimensions[0] = 0.75 * display.getWidth();
dimensions[1] = 0.75 * display.getHeight();
}
addContentView(mContent, new FrameLayout.LayoutParams((int) dimensions[0], (int) dimensions[1]));
}
private void setUpTitle() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Drawable icon = getContext().getResources().getDrawable(R.drawable.twitter_icon);
mTitle = new TextView(getContext());
mTitle.setText("Twitter");
mTitle.setTextColor(Color.WHITE);
mTitle.setTypeface(Typeface.DEFAULT_BOLD);
mTitle.setBackgroundColor(0xFFbbd7e9);
mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN);
mTitle.setCompoundDrawablePadding(MARGIN + PADDING);
// mTitle.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
mTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
mContent.addView(mTitle);
}
private void setUpWebView() {
CookieSyncManager.createInstance(getContext());
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
mWebView = new WebView(getContext());
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.setWebViewClient(new TwitterWebViewClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(mUrl);
mWebView.setLayoutParams(FILL);
mContent.addView(mWebView);
}
private class TwitterWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
LogD("Redirecting URL " + url);
if (url.startsWith(TwitterApp.CALLBACK_URL)) {
mListener.onComplete(url);
TwitterDialog.this.dismiss();
return true;
} else if (url.startsWith("authorize")) {
return false;
}
return true;
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
LogD("Page error: " + description);
super.onReceivedError(view, errorCode, description, failingUrl);
mListener.onError(Consts.EPAGE_ERROR, description);
TwitterDialog.this.dismiss();
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
LogD("Loading URL: " + url);
super.onPageStarted(view, url, favicon);
mSpinner.show();
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String title = mWebView.getTitle();
if (title != null && title.length() > 0) {
mTitle.setText(title);
}
mSpinner.dismiss();
}
}
private DialogInterface.OnCancelListener mCancelListener = new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mSpinner.dismiss();
mListener.onError(Consts.EUSER_CANCELED, "User canceled!");
}
};
}

View File

@ -0,0 +1,56 @@
/**
* @author Lorensius W. L. T <lorenz@londatiga.net>
*
* http://www.londatiga.net
*/
package org.cocos2dx.plugin;
import twitter4j.auth.AccessToken;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
public class TwitterSession {
private SharedPreferences sharedPref;
private Editor editor;
private static final String TWEET_AUTH_KEY = "auth_key";
private static final String TWEET_AUTH_SECRET_KEY = "auth_secret_key";
private static final String TWEET_USER_NAME = "user_name";
private static final String SHARED = "Twitter_Preferences";
public TwitterSession(Context context) {
sharedPref = context.getSharedPreferences(SHARED, Context.MODE_PRIVATE);
editor = sharedPref.edit();
}
public void storeAccessToken(AccessToken accessToken, String username) {
editor.putString(TWEET_AUTH_KEY, accessToken.getToken());
editor.putString(TWEET_AUTH_SECRET_KEY, accessToken.getTokenSecret());
editor.putString(TWEET_USER_NAME, username);
editor.commit();
}
public void resetAccessToken() {
editor.putString(TWEET_AUTH_KEY, null);
editor.putString(TWEET_AUTH_SECRET_KEY, null);
editor.putString(TWEET_USER_NAME, null);
editor.commit();
}
public String getUsername() {
return sharedPref.getString(TWEET_USER_NAME, "");
}
public AccessToken getAccessToken() {
String token = sharedPref.getString(TWEET_AUTH_KEY, null);
String tokenSecret = sharedPref.getString(TWEET_AUTH_SECRET_KEY, null);
if (token != null && tokenSecret != null)
return new AccessToken(token, tokenSecret);
else
return null;
}
}

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_ANALYTICS_UMENG_H__
#define __CCX_ANALYTICS_UMENG_H__

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "AnalyticsUmeng.h"
#include "PluginJniHelper.h"
#include <android/log.h>

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "AnalyticsUmeng.h"
#include "MobClick.h"

View File

@ -1,67 +0,0 @@
#include "AnalyticsUmeng.h"
namespace cocos2d { namespace plugin {
PLUGIN_REGISTER_IMPL(AnalyticsUmeng)
AnalyticsUmeng::~AnalyticsUmeng()
{
}
bool AnalyticsUmeng::init()
{
return true;
}
void AnalyticsUmeng::updateOnlineConfig()
{
}
const char* AnalyticsUmeng::getConfigParams(const char* key)
{
return "";
}
void AnalyticsUmeng::setDefaultReportPolicy(ReportPolicy ePolicy)
{
}
void AnalyticsUmeng::logEventWithLabel(const char* eventId, const char* label)
{
}
void AnalyticsUmeng::logEventWithDuration(const char* eventId, long duration, const char* label)
{
}
void AnalyticsUmeng::logEventWithDuration(const char* eventId, long duration, LogEventParamMap* paramMap /* = NULL */)
{
}
void AnalyticsUmeng::logTimedEventWithLabelBegin(const char* eventId, const char* label)
{
}
void AnalyticsUmeng::logTimedEventWithLabelEnd(const char* eventId, const char* label)
{
}
void AnalyticsUmeng::logTimedKVEventBegin(const char* eventId, const char* label, LogEventParamMap* paramMap)
{
}
void AnalyticsUmeng::logTimedKVEventEnd(const char* eventId, const char* label)
{
}
}} // namespace cocos2d { namespace plugin {

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "PluginManager.h"
#include <map>
#include <string>

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "RegisterPlugin.h"
#include "PluginManager.h"

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_PLUGINMANAGER_H__
#define __CCX_PLUGINMANAGER_H__

View File

@ -1,5 +1,28 @@
#ifndef __CXX_IPLUGIN_H__
#define __CXX_IPLUGIN_H__
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_IPLUGIN_H__
#define __CCX_IPLUGIN_H__
#include "RegisterPlugin.h"
@ -35,4 +58,4 @@ protected:
}} //namespace cocos2d { namespace plugin {
#endif /* __CXX_IPLUGIN_H__ */
#endif /* __CCX_IPLUGIN_H__ */

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_PROTOCOL_ADS_H__
#define __CCX_PROTOCOL_ADS_H__
@ -7,21 +30,37 @@
namespace cocos2d { namespace plugin {
typedef std::map<std::string, std::string> TAppInfo;
typedef std::map<std::string, std::string> TAdsDeveloperInfo;
class AdListener
typedef enum
{
kAdsReceived = 0, // The ad is received
kFullScreenViewShown, // The full screen advertisement shown
kFullScreenViewDismissed, // The full screen advertisement dismissed
kPointsSpendSucceed, // The points spend succeed
kPointsSpendFailed, // The points spend failed
kNetworkError, // Network error
kUnknownError, // Unknown error
} AdsResultCode;
class ProtocolAds;
class AdsListener
{
public:
typedef enum
{
eUnknownError = 0,
eNetworkError,
} EAdErrorCode;
/**
@brief The advertisement request result
*/
virtual void onAdsResult(AdsResultCode code, const char* msg) = 0;
virtual void onReceiveAd() {}
virtual void onPresentScreen() {}
virtual void onFailedToReceiveAd(EAdErrorCode code, const char* msg) {}
virtual void onDismissScreen() {}
/**
@brief Player get points from advertisement(For example: Tapjoy)
@param points The point number player has got.
@param pAdsPlugin The plugin which the player get points. Used to spend the points.
*/
virtual void onPlayerGetPoints(int points, ProtocolAds* pAdsPlugin) {}
};
class ProtocolAds : public PluginProtocol
@ -29,13 +68,19 @@ class ProtocolAds : public PluginProtocol
public:
typedef enum {
ePosTop = 0,
ePosTopLeft,
ePosTopRight,
ePosBottom,
ePosBottomLeft,
ePosBottomRight,
} EBannerPos;
kBannerAd = 0,
kFullScreenAd,
} AdsType;
typedef enum {
kPosCenter = 0,
kPosTop,
kPosTopLeft,
kPosTopRight,
kPosBottom,
kPosBottomLeft,
kPosBottomRight,
} AdsPos;
/**
@brief plugin initialization
@ -43,27 +88,38 @@ public:
virtual bool init();
/**
@brief initialize the application info
@param appInfo This parameter is the info of aplication,
@brief config the application info
@param devInfo This parameter is the info of aplication,
different plugin have different format
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void initAppInfo(TAppInfo appInfo);
virtual void configDeveloperInfo(TAdsDeveloperInfo devInfo);
/**
@brief show banner ads at specified position
@param pos The position where the banner view be shown
@brief show adview
@param type The adview type need to show.
@param sizeEnum The size of the banner view.
In different plugin, it's have different mean.
Pay attention to the subclass definition
(only used when type is kBannerAd)
In different plugin, it's have different mean.
Pay attention to the subclass definition
@param pos The position where the adview be shown.
(only used when type is kBannerAd)
*/
virtual void showBannerAd(EBannerPos pos, int sizeEnum);
virtual void showAds(AdsType type, int sizeEnum = 0, AdsPos pos = kPosCenter);
/**
@brief hide the banner ads view
@brief Hide the adview
@param type The adview type need to hide.
*/
virtual void hideBannerAd();
virtual void hideAds(AdsType type);
/**
@brief Spend the points.
Use this method to notify server spend points.
@param points Need spend number of points
*/
virtual void spendPoints(int points);
/**
@brief Set whether needs to output logs to console.
@ -74,16 +130,11 @@ public:
/**
@brief set the Ads listener
*/
static void setAdListener(AdListener* pListener)
{
m_pListener = pListener;
}
void setAdsListener(AdsListener* pListener);
// For the callbak methods
static void receiveAd();
static void presentScreen();
static void failedToReceiveAd(AdListener::EAdErrorCode code, const char* msg);
static void dismissScreen();
void onAdsResult(AdsResultCode code, const char* msg);
void onPlayerGetPoints(int points);
virtual const char* getPluginVersion() { return "ProtocolAds, v0.1.01 , subclass should override this interface!"; };
virtual const char* getSDKVersion();
@ -95,7 +146,7 @@ public:
virtual ~ProtocolAds();
protected:
static AdListener* m_pListener;
AdsListener* m_pListener;
};
}} // namespace cocos2d { namespace plugin {

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_PROTOCOL_ANALYTICS_H__
#define __CCX_PROTOCOL_ANALYTICS_H__

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_PROTOCOL_IAP_H__
#define __CCX_PROTOCOL_IAP_H__
@ -7,21 +30,21 @@
namespace cocos2d { namespace plugin {
typedef std::map<std::string, std::string> TDeveloperInfo;
typedef std::map<std::string, std::string> TIAPDeveloperInfo;
typedef std::map<std::string, std::string> TProductInfo;
typedef enum
{
ePaySuccess = 0,
ePayFail,
ePayCancel,
ePayTimeOut,
} EPayResult;
kPaySuccess = 0,
kPayFail,
kPayCancel,
kPayTimeOut,
} PayResultCode;
class PayResultListener
{
public:
virtual void payResult(EPayResult ret, const char* msg, TProductInfo info) = 0;
virtual void onPayResult(PayResultCode ret, const char* msg, TProductInfo info) = 0;
};
class ProtocolIAP : public PluginProtocol
@ -34,13 +57,13 @@ public:
virtual bool init();
/**
@brief initialize the developer info
@brief config the developer info
@param devInfo This parameter is the info of developer,
different plugin have different format
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void initDeveloperInfo(TDeveloperInfo devInfo);
virtual void configDeveloperInfo(TIAPDeveloperInfo devInfo);
/**
@brief pay for product
@ -64,12 +87,12 @@ public:
@param pListener The callback object for pay result
@wraning Must invoke this interface before payForProduct.
*/
static void setResultListener(PayResultListener* pListener);
void setResultListener(PayResultListener* pListener);
/**
@brief pay result callback
*/
static void payResult(EPayResult ret, const char* msg);
void onPayResult(PayResultCode ret, const char* msg);
virtual const char* getPluginVersion() { return "ProtocolIAP, v0.1.01 , subclass should override this interface!"; };
virtual const char* getSDKVersion();
@ -82,8 +105,9 @@ public:
protected:
static bool m_bPaying;
static PayResultListener* m_pListener;
static TProductInfo m_curInfo;
TProductInfo m_curInfo;
PayResultListener* m_pListener;
};
}} // namespace cocos2d { namespace plugin {

View File

@ -0,0 +1,111 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_PROTOCOL_SOCIAL_H__
#define __CCX_PROTOCOL_SOCIAL_H__
#include "PluginProtocol.h"
#include <map>
#include <string>
namespace cocos2d { namespace plugin {
typedef std::map<std::string, std::string> TSocialDeveloperInfo;
typedef std::map<std::string, std::string> TShareInfo;
typedef enum
{
kShareSuccess = 0,
kShareFail,
kShareCancel,
kShareTimeOut,
} ShareResultCode;
class ShareResultListener
{
public:
virtual void onShareResult(ShareResultCode ret, const char* msg) = 0;
};
class ProtocolSocial : public PluginProtocol
{
public:
/**
@brief plugin initialization
*/
virtual bool init();
/**
@brief config the social developer info
@param devInfo This parameter is the info of developer,
different plugin have different format
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void configDeveloperInfo(TSocialDeveloperInfo devInfo);
/**
@brief share information
@param info The info of share, contains key:
SharedText The text need to share
SharedImagePath The full path of image file need to share (optinal)
@warning For different plugin, the parameter should have other keys to share.
Look at the manual of plugins.
*/
virtual void share(TShareInfo info);
/**
@brief Set whether needs to output logs to console.
@param debug if true debug mode enabled, or debug mode disabled.
*/
virtual void setDebugMode(bool debug);
/**
@breif set the result listener
@param pListener The callback object for share result
@wraning Must invoke this interface before share
*/
void setResultListener(ShareResultListener* pListener);
/**
@brief share result callback
*/
void onShareResult(ShareResultCode ret, const char* msg);
virtual const char* getPluginVersion() { return "ProtocolSocial, v0.1.0, subclass should override this interface!"; };
virtual const char* getSDKVersion();
virtual const char* getPluginName() = 0;
protected:
ProtocolSocial();
public:
virtual ~ProtocolSocial();
protected:
ShareResultListener* m_pListener;
};
}} // namespace cocos2d { namespace plugin {
#endif /* ----- #ifndef __CCX_PROTOCOL_SOCIAL_H__ ----- */

View File

@ -1,5 +1,28 @@
#ifndef __CXX_REGISTERPLUGIN_H__
#define __CXX_REGISTERPLUGIN_H__
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_REGISTERPLUGIN_H__
#define __CCX_REGISTERPLUGIN_H__
namespace cocos2d { namespace plugin {
@ -20,11 +43,12 @@ public:
#define PLUGIN_REGISTER_DECL(type) \
private: type() {} \
static RegisterPlugin s_registerPlugin; \
public: static PluginProtocol* createPlugin(); \
virtual const char* getPluginName() { return #type; };
#define PLUGIN_REGISTER_IMPL(type) \
static RegisterPlugin s_registerPlugin(#type, type::createPlugin); \
RegisterPlugin type::s_registerPlugin(#type, type::createPlugin); \
PluginProtocol* type::createPlugin() { \
type* pRet = new type(); \
if (pRet) { \
@ -37,4 +61,4 @@ PluginProtocol* type::createPlugin() { \
}} //namespace cocos2d { namespace plugin {
#endif /* __CXX_REGISTERPLUGIN_H__ */
#endif /* __CCX_REGISTERPLUGIN_H__ */

View File

@ -23,11 +23,11 @@ cxxgenerator_headers = -I%(cxxgeneratordir)s/targets/spidermonkey/common
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s
# what headers to parse
headers = %(pluginxdir)s/protocols/include/PluginManager.h %(pluginxdir)s/protocols/include/ProtocolAnalytics.h %(pluginxdir)s/protocols/include/ProtocolIAP.h %(pluginxdir)s/protocols/include/ProtocolIAPOnLine.h
headers = %(pluginxdir)s/protocols/include/PluginManager.h %(pluginxdir)s/protocols/include/ProtocolAnalytics.h %(pluginxdir)s/protocols/include/ProtocolIAP.h %(pluginxdir)s/protocols/include/ProtocolAds.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^CCMenu*$".
classes = PluginProtocol PluginManager ProtocolIAP ProtocolAnalytics ProtocolIAPOnLine
classes = PluginProtocol PluginManager ProtocolIAP ProtocolAnalytics ProtocolAds
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
@ -37,7 +37,7 @@ classes = PluginProtocol PluginManager ProtocolIAP ProtocolAnalytics ProtocolIAP
# functions from all classes.
skip = ProtocolIAP::[setResultListener],
ProtocolIAPOnLine::[setLocalResultListener]
ProtocolAds::[setAdListener]
rename_functions =
@ -54,7 +54,7 @@ base_classes_to_skip =
# classes that create no constructor
# CCSet is special and we will use a hand-written constructor
abstract_classes = PluginProtocol ProtocolIAP ProtocolAnalytics PluginManager ProtocolIAPOnLine
abstract_classes = PluginProtocol ProtocolIAP ProtocolAnalytics PluginManager ProtocolAds
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = yes

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __PLUGIN_JAVA_DATA_H__
#define __PLUGIN_JAVA_DATA_H__

View File

@ -1,5 +1,5 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org

View File

@ -1,5 +1,5 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "PluginUtils.h"
#include <android/log.h>
#include <map>
@ -96,8 +119,10 @@ JNIEnv* PluginUtils::getEnv()
}
std::map<PluginProtocol*, PluginJavaData*> s_PluginObjMap;
std::map<jobject, PluginProtocol*> s_JObjPluginMap;
typedef std::map<PluginProtocol*, PluginJavaData*>::iterator ObjMapIter;
typedef std::map<jobject, PluginProtocol*>::iterator JObjPluginMapIter;
PluginJavaData* PluginUtils::getPluginJavaData(PluginProtocol* pKeyObj)
{
@ -110,10 +135,22 @@ PluginJavaData* PluginUtils::getPluginJavaData(PluginProtocol* pKeyObj)
return ret;
}
PluginProtocol* PluginUtils::getPluginPtr(jobject jobj)
{
PluginProtocol* ret = NULL;
JObjPluginMapIter it = s_JObjPluginMap.find(jobj);
if (it != s_JObjPluginMap.end()) {
ret = it->second;
}
return ret;
}
void PluginUtils::setPluginJavaData(PluginProtocol* pKeyObj, PluginJavaData* pData)
{
erasePluginJavaData(pKeyObj);
s_PluginObjMap.insert(std::pair<PluginProtocol*, PluginJavaData*>(pKeyObj, pData));
s_JObjPluginMap.insert(std::pair<jobject, PluginProtocol*>(pData->jobj, pKeyObj));
}
void PluginUtils::erasePluginJavaData(PluginProtocol* pKeyObj)
@ -124,6 +161,13 @@ void PluginUtils::erasePluginJavaData(PluginProtocol* pKeyObj)
if (pData != NULL)
{
jobject jobj = pData->jobj;
JObjPluginMapIter pluginIt = s_JObjPluginMap.find(jobj);
if (pluginIt != s_JObjPluginMap.end())
{
s_JObjPluginMap.erase(pluginIt);
}
JNIEnv* pEnv = getEnv();
LOGD("Delete global reference.");
pEnv->DeleteGlobalRef(jobj);

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __PLUGIN_UTILS_H__
#define __PLUGIN_UTILS_H__
@ -23,6 +46,8 @@ public:
static void setPluginJavaData(PluginProtocol* pKeyObj, PluginJavaData* pData);
static void erasePluginJavaData(PluginProtocol* pKeyObj);
static PluginProtocol* getPluginPtr(jobject jobj);
template <typename T>
static void callJavaFunctionWithName_oneBaseType(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param)
{

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "ProtocolAds.h"
#include "PluginJniHelper.h"
#include <android/log.h>
@ -14,27 +37,38 @@
namespace cocos2d { namespace plugin {
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeReceiveAd(JNIEnv* env, jobject thiz) {
ProtocolAds::receiveAd();
}
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativePresentScreen(JNIEnv* env, jobject thiz) {
ProtocolAds::presentScreen();
}
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeFailedToReceiveAd(JNIEnv* env, jobject thiz, jint ret, jstring msg) {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnAdsResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg) {
std::string strMsg = PluginJniHelper::jstring2string(msg);
ProtocolAds::failedToReceiveAd((AdListener::EAdErrorCode) ret, strMsg.c_str());
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj);
LOGD("nativeOnAdsResult(), Get plugin ptr : %p", pPlugin);
if (pPlugin != NULL)
{
LOGD("nativeOnAdsResult(), Get plugin name : %s", pPlugin->getPluginName());
ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin);
if (pAds != NULL)
{
pAds->onAdsResult((AdsResultCode) ret, strMsg.c_str());
}
}
}
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeDismissScreen(JNIEnv* env, jobject thiz) {
ProtocolAds::dismissScreen();
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jobject obj, jint points) {
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj);
LOGD("nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin);
if (pPlugin != NULL)
{
LOGD("nativeOnPlayerGetPoints(), Get plugin name : %s", pPlugin->getPluginName());
ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin);
if (pAds != NULL)
{
pAds->onPlayerGetPoints(points);
}
}
}
}
AdListener* ProtocolAds::m_pListener = NULL;
ProtocolAds::ProtocolAds()
: m_pListener(NULL)
{
}
@ -48,9 +82,9 @@ bool ProtocolAds::init()
return true;
}
void ProtocolAds::initAppInfo(TAppInfo appInfo)
void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo)
{
if (appInfo.empty())
if (devInfo.empty())
{
LOGD("The application info is empty!");
return;
@ -61,11 +95,11 @@ void ProtocolAds::initAppInfo(TAppInfo appInfo)
PluginJniMethodInfo t;
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "initAppInfo"
, "configDeveloperInfo"
, "(Ljava/util/Hashtable;)V"))
{
// generate the hashtable from map
jobject obj_Map = PluginUtils::createJavaMapObject(t, &appInfo);
jobject obj_Map = PluginUtils::createJavaMapObject(t, &devInfo);
// invoke java method
t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map);
@ -75,7 +109,7 @@ void ProtocolAds::initAppInfo(TAppInfo appInfo)
}
}
void ProtocolAds::showBannerAd(EBannerPos pos, int size)
void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos)
{
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
PluginJniMethodInfo t;
@ -83,17 +117,22 @@ void ProtocolAds::showBannerAd(EBannerPos pos, int size)
LOGD("Class name : %s", pData->jclassName.c_str());
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "showBannerAd"
, "(II)V"))
, "showAds"
, "(III)V"))
{
t.env->CallVoidMethod(pData->jobj, t.methodID, pos, size);
t.env->CallVoidMethod(pData->jobj, t.methodID, type, sizeEnum, pos);
t.env->DeleteLocalRef(t.classID);
}
}
void ProtocolAds::hideBannerAd()
void ProtocolAds::hideAds(AdsType type)
{
PluginUtils::callJavaFunctionWithName(this, "hideBannerAd");
PluginUtils::callJavaFunctionWithName_oneBaseType(this, "hideAds", "(I)V", type);
}
void ProtocolAds::spendPoints(int points)
{
PluginUtils::callJavaFunctionWithName_oneBaseType(this, "spendPoints", "(I)V", points);
}
const char* ProtocolAds::getSDKVersion()
@ -118,39 +157,26 @@ void ProtocolAds::setDebugMode(bool debug)
PluginUtils::callJavaFunctionWithName_oneBaseType(this, "setDebugMode", "(Z)V", debug);
}
void ProtocolAds::receiveAd()
void ProtocolAds::setAdsListener(AdsListener* pListener)
{
LOGD("ProtocolAds::receiveAd invoked!");
m_pListener = pListener;
}
void ProtocolAds::onAdsResult(AdsResultCode code, const char* msg)
{
LOGD("ProtocolAds::adsResult invoked!");
if (m_pListener != NULL)
{
m_pListener->onReceiveAd();
m_pListener->onAdsResult(code, msg);
}
}
void ProtocolAds::presentScreen()
void ProtocolAds::onPlayerGetPoints(int points)
{
LOGD("ProtocolAds::presentScreen invoked!");
LOGD("ProtocolAds::onPlayerGetPoints invoked!");
if (m_pListener != NULL)
{
m_pListener->onPresentScreen();
}
}
void ProtocolAds::failedToReceiveAd(AdListener::EAdErrorCode code, const char* msg)
{
LOGD("ProtocolAds::failedToReceiveAd invoked!");
if (m_pListener != NULL)
{
m_pListener->onFailedToReceiveAd(code, msg);
}
}
void ProtocolAds::dismissScreen()
{
LOGD("ProtocolAds::dismissScreen invoked!");
if (m_pListener != NULL)
{
m_pListener->onDismissScreen();
m_pListener->onPlayerGetPoints(points, this);
}
}

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "ProtocolAnalytics.h"
#include "PluginJniHelper.h"
#include <android/log.h>

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "ProtocolIAP.h"
#include "PluginJniHelper.h"
#include <android/log.h>
@ -14,18 +37,27 @@
namespace cocos2d { namespace plugin {
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativePayResult(JNIEnv* env, jobject thiz, jint ret, jstring msg)
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceIAP_nativeOnPayResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg)
{
std::string strMsg = PluginJniHelper::jstring2string(msg);
ProtocolIAP::payResult((EPayResult) ret, strMsg.c_str());
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj);
LOGD("nativeOnPayResult(), Get plugin ptr : %p", pPlugin);
if (pPlugin != NULL)
{
LOGD("nativeOnPayResult(), Get plugin name : %s", pPlugin->getPluginName());
ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin);
if (pIAP != NULL)
{
pIAP->onPayResult((PayResultCode) ret, strMsg.c_str());
}
}
}
}
bool ProtocolIAP::m_bPaying = false;
PayResultListener* ProtocolIAP::m_pListener = NULL;
TProductInfo ProtocolIAP::m_curInfo;
ProtocolIAP::ProtocolIAP()
: m_pListener(NULL)
{
}
@ -39,7 +71,7 @@ bool ProtocolIAP::init()
return true;
}
void ProtocolIAP::initDeveloperInfo(TDeveloperInfo devInfo)
void ProtocolIAP::configDeveloperInfo(TIAPDeveloperInfo devInfo)
{
if (devInfo.empty())
{
@ -52,7 +84,7 @@ void ProtocolIAP::initDeveloperInfo(TDeveloperInfo devInfo)
PluginJniMethodInfo t;
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "initDeveloperInfo"
, "configDeveloperInfo"
, "(Ljava/util/Hashtable;)V"))
{
// generate the hashtable from map
@ -78,7 +110,7 @@ void ProtocolIAP::payForProduct(TProductInfo info)
{
if (NULL != m_pListener)
{
payResult(ePayFail, "Product info error");
onPayResult(kPayFail, "Product info error");
}
LOGD("The product info is empty!");
return;
@ -111,12 +143,12 @@ void ProtocolIAP::setResultListener(PayResultListener* pListener)
m_pListener = pListener;
}
void ProtocolIAP::payResult(EPayResult ret, const char* msg)
void ProtocolIAP::onPayResult(PayResultCode ret, const char* msg)
{
m_bPaying = false;
if (m_pListener)
{
m_pListener->payResult(ret, msg, m_curInfo);
m_pListener->onPayResult(ret, msg, m_curInfo);
}
else
{

View File

@ -0,0 +1,170 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "ProtocolSocial.h"
#include "PluginJniHelper.h"
#include <android/log.h>
#include "PluginUtils.h"
#include "PluginJavaData.h"
#if 1
#define LOG_TAG "ProtocolSocial"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#else
#define LOGD(...)
#endif
namespace cocos2d { namespace plugin {
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceSocial_nativeOnShareResult(JNIEnv* env, jobject thiz, jobject obj, jint ret, jstring msg)
{
std::string strMsg = PluginJniHelper::jstring2string(msg);
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(obj);
LOGD("nativeOnShareResult(), Get plugin ptr : %p", pPlugin);
if (pPlugin != NULL)
{
LOGD("nativeOnShareResult(), Get plugin name : %s", pPlugin->getPluginName());
ProtocolSocial* pSocial = dynamic_cast<ProtocolSocial*>(pPlugin);
if (pSocial != NULL)
{
pSocial->onShareResult((ShareResultCode) ret, strMsg.c_str());
}
}
}
}
ProtocolSocial::ProtocolSocial()
: m_pListener(NULL)
{
}
ProtocolSocial::~ProtocolSocial()
{
PluginUtils::erasePluginJavaData(this);
}
bool ProtocolSocial::init()
{
return true;
}
void ProtocolSocial::configDeveloperInfo(TSocialDeveloperInfo devInfo)
{
if (devInfo.empty())
{
LOGD("The developer info is empty!");
return;
}
else
{
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
PluginJniMethodInfo t;
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "configDeveloperInfo"
, "(Ljava/util/Hashtable;)V"))
{
// generate the hashtable from map
jobject obj_Map = PluginUtils::createJavaMapObject(t, &devInfo);
// invoke java method
t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map);
t.env->DeleteLocalRef(obj_Map);
t.env->DeleteLocalRef(t.classID);
}
}
}
void ProtocolSocial::share(TShareInfo info)
{
if (info.empty())
{
if (NULL != m_pListener)
{
onShareResult(kShareFail, "Share info error");
}
LOGD("The Share info is empty!");
return;
}
else
{
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
PluginJniMethodInfo t;
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "share"
, "(Ljava/util/Hashtable;)V"))
{
// generate the hashtable from map
jobject obj_Map = PluginUtils::createJavaMapObject(t, &info);
// invoke java method
t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map);
t.env->DeleteLocalRef(obj_Map);
t.env->DeleteLocalRef(t.classID);
}
}
}
void ProtocolSocial::setResultListener(ShareResultListener* pListener)
{
m_pListener = pListener;
}
void ProtocolSocial::onShareResult(ShareResultCode ret, const char* msg)
{
if (m_pListener)
{
m_pListener->onShareResult(ret, msg);
}
else
{
LOGD("Result listener is null!");
}
LOGD("Share result is : %d(%s)", (int) ret, msg);
}
const char* ProtocolSocial::getSDKVersion()
{
std::string verName;
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
PluginJniMethodInfo t;
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "getSDKVersion"
, "()Ljava/lang/String;"))
{
jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID));
verName = PluginJniHelper::jstring2string(ret);
}
return verName.c_str();
}
void ProtocolSocial::setDebugMode(bool debug)
{
PluginUtils::callJavaFunctionWithName_oneBaseType(this, "setDebugMode", "(Z)V", debug);
}
}} // namespace cocos2d { namespace plugin {

1
plugin/protocols/proj.android/jni/Android.mk Normal file → Executable file
View File

@ -13,6 +13,7 @@ $(addprefix ../../platform/android/, \
ProtocolAnalytics.cpp \
ProtocolIAP.cpp \
ProtocolAds.cpp \
ProtocolSocial.cpp \
) \
../../PluginManager.cpp \
../../RegisterPlugin.cpp \

View File

@ -1,28 +1,60 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
public class InterfaceAds {
public static final int UNKNOWN_ERROR = 0;
public static final int NETWORK_ERROR = 1;
public static final int REQUESTING_ERROR = 2;
public static final int POS_TOP = 0;
public static final int POS_TOP_LEFT = 1;
public static final int POS_TOP_RIGHT = 2;
public static final int POS_BOTTOM = 3;
public static final int POS_BOTTOM_LEFT = 4;
public static final int POS_BOTTOM_RIGHT = 5;
public static final int RESULT_CODE_AdsReceived = 0; // The ad is received
public static final int RESULT_CODE_FullScreenViewShown = 1; // The full screen advertisement shown
public static final int RESULT_CODE_FullScreenViewDismissed = 2; // The full screen advertisement dismissed
public static final int RESULT_CODE_PointsSpendSucceed = 3; // The points spend succeed
public static final int RESULT_CODE_PointsSpendFailed = 4; // The points spend failed
public static final int RESULT_CODE_NetworkError = 5; // Network error
public static final int RESULT_CODE_UnknownError = 6; // Unknown error
public static final int ADS_TYPE_BANNER = 0;
public static final int ADS_TYPE_FULL_SCREEN = 1;
public static final int POS_CENTER = 0;
public static final int POS_TOP = 1;
public static final int POS_TOP_LEFT = 2;
public static final int POS_TOP_RIGHT = 3;
public static final int POS_BOTTOM = 4;
public static final int POS_BOTTOM_LEFT = 5;
public static final int POS_BOTTOM_RIGHT = 6;
public interface AdsAdapter {
public void initAppInfo(Hashtable<String, String> appInfo);
public void showBannerAd(int pos, int sizeEnum);
public void hideBannerAd();
public void configDeveloperInfo(Hashtable<String, String> devInfo);
public void showAds(int type, int sizeEnum, int pos);
public void hideAds(int type);
public void spendPoints(int points);
public void setDebugMode(boolean debug);
public String getSDKVersion();
}
@ -35,6 +67,9 @@ public class InterfaceAds {
mLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
switch (pos) {
case POS_CENTER:
mLayoutParams.gravity = Gravity.CENTER;
break;
case POS_TOP:
mLayoutParams.gravity = Gravity.TOP;
break;
@ -59,45 +94,28 @@ public class InterfaceAds {
mWm.addView(adView, mLayoutParams);
}
public static void receiveAd() {
public static void onAdsResult(AdsAdapter adapter, int code, String msg) {
final int curCode = code;
final String curMsg = msg;
final AdsAdapter curObj = adapter;
PluginWrapper.runOnGLThread(new Runnable(){
@Override
public void run() {
InterfaceAds.nativeReceiveAd();
InterfaceAds.nativeOnAdsResult(curObj, curCode, curMsg);
}
});
}
private native static void nativeReceiveAd();
private native static void nativeOnAdsResult(Object obj, int code, String msg);
public static void presentScreen() {
public static void onPlayerGetPoints(AdsAdapter adapter, int points) {
final int curPoints = points;
final AdsAdapter curAdapter = adapter;
PluginWrapper.runOnGLThread(new Runnable(){
@Override
public void run() {
InterfaceAds.nativePresentScreen();
InterfaceAds.nativeOnPlayerGetPoints(curAdapter, curPoints);
}
});
}
private native static void nativePresentScreen();
public static void failedToReceiveAd(int code, String msg) {
final int eCode = code;
final String eMsg = msg;
PluginWrapper.runOnGLThread(new Runnable(){
@Override
public void run() {
InterfaceAds.nativeFailedToReceiveAd(eCode, eMsg);
}
});
}
private native static void nativeFailedToReceiveAd(int code, String msg);
public static void dismissScreen() {
PluginWrapper.runOnGLThread(new Runnable(){
@Override
public void run() {
InterfaceAds.nativeDismissScreen();
}
});
}
private native static void nativeDismissScreen();
private native static void nativeOnPlayerGetPoints(Object obj, int points);
}

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;
@ -9,21 +32,22 @@ public class InterfaceIAP {
public static final int PAYRESULT_TIMEOUT = 3;
public interface IAPAdapter {
public void initDeveloperInfo(Hashtable<String, String> cpInfo);
public void configDeveloperInfo(Hashtable<String, String> cpInfo);
public void payForProduct(Hashtable<String, String> cpInfo);
public void setDebugMode(boolean debug);
public String getSDKVersion();
}
public static void payResult(int ret, String msg) {
public static void onPayResult(IAPAdapter obj, int ret, String msg) {
final int curRet = ret;
final String curMsg = msg;
final IAPAdapter curObj = obj;
PluginWrapper.runOnGLThread(new Runnable() {
@Override
public void run() {
nativePayResult(curRet, curMsg);
nativeOnPayResult(curObj, curRet, curMsg);
}
});
}
private static native void nativePayResult(int ret, String msg);
private static native void nativeOnPayResult(Object obj, int ret, String msg);
}

View File

@ -0,0 +1,53 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import java.util.Hashtable;
public class InterfaceSocial {
public static final int SHARERESULT_SUCCESS = 0;
public static final int SHARERESULT_FAIL = 1;
public static final int SHARERESULT_CANCEL = 2;
public static final int SHARERESULT_TIMEOUT = 3;
public interface ShareAdapter {
public void configDeveloperInfo(Hashtable<String, String> cpInfo);
public void share(Hashtable<String, String> cpInfo);
public void setDebugMode(boolean debug);
public String getSDKVersion();
}
public static void onShareResult(ShareAdapter obj, int ret, String msg) {
final int curRet = ret;
final String curMsg = msg;
final ShareAdapter curAdapter = obj;
PluginWrapper.runOnGLThread(new Runnable() {
@Override
public void run() {
nativeOnShareResult(curAdapter, curRet, curMsg);
}
});
}
private static native void nativeOnShareResult(Object obj, int ret, String msg);
}

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.plugin;
import android.content.Context;

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "AppDelegate.h"
#include "HelloWorldScene.h"

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef _APP_DELEGATE_H_
#define _APP_DELEGATE_H_

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "HelloWorldScene.h"
#include "PluginManager.h"
@ -5,10 +28,16 @@ USING_NS_CC;
using namespace cocos2d::plugin;
const std::string s_aTestCases[] = {
"Test: Admob",
"Admob",
};
const std::string s_aTestTypes[] = {
"Banner",
"Full Screen",
};
const std::string s_aTestPoses[] = {
"Pos: Center",
"Pos: Top",
"Pos: TopLeft",
"Pos: TopRight",
@ -43,11 +72,11 @@ bool HelloWorld::init()
}
m_pAdmob = dynamic_cast<AdsAdmob*>(PluginManager::getInstance()->loadPlugin("AdsAdmob"));
TAppInfo appInfo;
appInfo["AdmobID"] = "a1516fb6b16b12f";
m_pAdmob->initAppInfo(appInfo);
m_pListener = new MyAdListener();
ProtocolAds::setAdListener(m_pListener);
TAdsDeveloperInfo devInfo;
devInfo["AdmobID"] = "a1516fb6b16b12f";
m_pAdmob->configDeveloperInfo(devInfo);
m_pListener = new MyAdsListener();
m_pAdmob->setAdsListener(m_pListener);
m_pAdmob->setDebugMode(true);
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
@ -72,19 +101,20 @@ bool HelloWorld::init()
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
CCLabelTTF* label1 = CCLabelTTF::create("ShowAdView", "Arial", 24);
CCLabelTTF* label1 = CCLabelTTF::create("ShowAds", "Arial", 24);
CCMenuItemLabel* pItemShow = CCMenuItemLabel::create(label1, this, menu_selector(HelloWorld::testShow));
pItemShow->setAnchorPoint(ccp(0.5f, 0));
pMenu->addChild(pItemShow, 0);
pItemShow->setPosition(ccpAdd(posMid, ccp(-100, -50)));
pItemShow->setPosition(ccpAdd(posMid, ccp(-100, -120)));
CCLabelTTF* label2 = CCLabelTTF::create("HideAdView", "Arial", 24);
CCLabelTTF* label2 = CCLabelTTF::create("HideAds", "Arial", 24);
CCMenuItemLabel* pItemHide = CCMenuItemLabel::create(label2, this, menu_selector(HelloWorld::testHide));
pItemHide->setAnchorPoint(ccp(0.5f, 0));
pMenu->addChild(pItemHide, 0);
pItemHide->setPosition(ccpAdd(posMid, ccp(100, -50)));
pItemHide->setPosition(ccpAdd(posMid, ccp(100, -120)));
// create optional menu
// cases item
m_pCaseItem = CCMenuItemToggle::createWithTarget(this,
menu_selector(HelloWorld::caseChanged),
CCMenuItemFont::create( s_aTestCases[0].c_str() ),
@ -94,9 +124,23 @@ bool HelloWorld::init()
{
m_pCaseItem->getSubItems()->addObject( CCMenuItemFont::create( s_aTestCases[i].c_str() ) );
}
m_pCaseItem->setPosition(ccpAdd(posMid, ccp(-150, 50)));
m_pCaseItem->setPosition(ccpAdd(posMid, ccp(-200, 120)));
pMenu->addChild(m_pCaseItem);
// type item
m_pTypeItem = CCMenuItemToggle::createWithTarget(this,
menu_selector(HelloWorld::typeChanged),
CCMenuItemFont::create( s_aTestTypes[0].c_str() ),
NULL );
int typeLen = sizeof(s_aTestTypes) / sizeof(std::string);
for (int i = 1; i < typeLen; ++i)
{
m_pTypeItem->getSubItems()->addObject( CCMenuItemFont::create( s_aTestTypes[i].c_str() ) );
}
m_pTypeItem->setPosition(ccpAdd(posMid, ccp(0, 120)));
pMenu->addChild(m_pTypeItem);
// poses item
m_pPosItem = CCMenuItemToggle::createWithTarget(this,
menu_selector(HelloWorld::posChanged),
CCMenuItemFont::create( s_aTestPoses[0].c_str() ),
@ -106,12 +150,13 @@ bool HelloWorld::init()
{
m_pPosItem->getSubItems()->addObject( CCMenuItemFont::create( s_aTestPoses[i].c_str() ) );
}
m_pPosItem->setPosition(ccpAdd(posMid, ccp(150, 50)));
m_pPosItem->setPosition(ccpAdd(posMid, ccp(200, 120)));
pMenu->addChild(m_pPosItem);
// init options
m_pAds = m_pAdmob;
m_ePos = ProtocolAds::ePosTop;
m_ePos = ProtocolAds::kPosCenter;
m_eType = ProtocolAds::kBannerAd;
this->addChild(pMenu, 1);
@ -120,15 +165,21 @@ bool HelloWorld::init()
void HelloWorld::testShow(CCObject* pSender)
{
int nSize = 0;
if (m_pAds == m_pAdmob)
{
m_pAds->showBannerAd(m_ePos, AdsAdmob::eSizeBanner);
nSize = AdsAdmob::kSizeBanner;
}
if (m_pAds)
{
m_pAds->showAds(m_eType, nSize, m_ePos);
}
}
void HelloWorld::testHide(CCObject* pSender)
{
m_pAds->hideBannerAd();
m_pAds->hideAds(m_eType);
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
@ -147,6 +198,7 @@ void HelloWorld::menuCloseCallback(CCObject* pSender)
m_pListener = NULL;
}
PluginManager::end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
@ -167,52 +219,33 @@ void HelloWorld::caseChanged(CCObject* pSender)
CCLog("case selected change to : %s", strLog.c_str());
}
void HelloWorld::typeChanged(CCObject* pSender)
{
int selectIndex = m_pTypeItem->getSelectedIndex();
m_eType = (ProtocolAds::AdsType) selectIndex;
CCLog("type selected change to : %d", m_eType);
}
void HelloWorld::posChanged(CCObject* pSender)
{
switch (m_pPosItem->getSelectedIndex())
{
case 0:
m_ePos = ProtocolAds::ePosTop;
break;
case 1:
m_ePos = ProtocolAds::ePosTopLeft;
break;
case 2:
m_ePos = ProtocolAds::ePosTopRight;
break;
case 3:
m_ePos = ProtocolAds::ePosBottom;
break;
case 4:
m_ePos = ProtocolAds::ePosBottomLeft;
break;
case 5:
m_ePos = ProtocolAds::ePosBottomRight;
break;
default:
break;
}
int selectIndex = m_pPosItem->getSelectedIndex();
m_ePos = (ProtocolAds::AdsPos) selectIndex;
CCLog("pos selected change to : %d", m_ePos);
}
void MyAdListener::onReceiveAd()
void MyAdsListener::onAdsResult(AdsResultCode code, const char* msg)
{
CCLog("My listener onReceiveAd");
CCLog("OnAdsResult, code : %d, msg : %s", code, msg);
}
void MyAdListener::onPresentScreen()
void MyAdsListener::onPlayerGetPoints(int points, ProtocolAds* pAdsPlugin)
{
CCLog("My listener onPresentScreen");
}
CCLog("Player get points : %d", points);
void MyAdListener::onFailedToReceiveAd(EAdErrorCode code, const char* msg)
{
char logStr[128] = {0};
sprintf(logStr, "My listener onFailedToReceiveAd, error code : %d, message : %s", code, msg);
CCLog(logStr);
}
// @warning should add code to give game-money to player here
void MyAdListener::onDismissScreen()
{
CCLog("My listener onDismissScreen");
// spend the points of player
if (pAdsPlugin != NULL) {
pAdsPlugin->spendPoints(points);
}
}

View File

@ -1,16 +1,37 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
#include "AdsAdmob.h"
class MyAdListener : public cocos2d::plugin::AdListener
class MyAdsListener : public cocos2d::plugin::AdsListener
{
public:
virtual void onReceiveAd();
virtual void onPresentScreen();
virtual void onFailedToReceiveAd(EAdErrorCode code, const char* msg);
virtual void onDismissScreen();
virtual void onAdsResult(cocos2d::plugin::AdsResultCode code, const char* msg);
virtual void onPlayerGetPoints(int points, cocos2d::plugin::ProtocolAds* pAdsPlugin);
};
class HelloWorld : public cocos2d::CCLayer
@ -30,18 +51,22 @@ public:
// option changed callback
void caseChanged(CCObject* pSender);
void posChanged(CCObject* pSender);
void typeChanged(CCObject* pSender);
// implement the "static node()" method manually
CREATE_FUNC(HelloWorld);
private:
cocos2d::plugin::AdsAdmob* m_pAdmob;
MyAdListener* m_pListener;
MyAdsListener* m_pListener;
cocos2d::CCMenuItemToggle* m_pCaseItem;
cocos2d::CCMenuItemToggle* m_pTypeItem;
cocos2d::CCMenuItemToggle* m_pPosItem;
cocos2d::plugin::ProtocolAds* m_pAds;
cocos2d::plugin::ProtocolAds::EBannerPos m_ePos;
cocos2d::plugin::ProtocolAds::AdsPos m_ePos;
cocos2d::plugin::ProtocolAds::AdsType m_eType;
};
#endif // __HELLOWORLD_SCENE_H__

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "AppDelegate.h"
#include "cocos2d.h"
#include "HelloWorldScene.h"

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef _APP_DELEGATE_H_
#define _APP_DELEGATE_H_

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "HelloWorldScene.h"
#include "PluginManager.h"
#include "AnalyticsFlurry.h"
@ -213,6 +236,7 @@ void HelloWorld::menuCloseCallback(CCObject* pSender)
if (g_pAnalytics)
g_pAnalytics->stopSession();
PluginManager::end();
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "AppDelegate.h"
#include "cocos2d.h"
#include "HelloWorldScene.h"

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef _APP_DELEGATE_H_
#define _APP_DELEGATE_H_
@ -37,4 +60,3 @@ public:
};
#endif // _APP_DELEGATE_H_

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "HelloWorldScene.h"
#include "PluginManager.h"
#include "AppDelegate.h"

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "MyPurchase.h"
#include "PluginManager.h"
#include "cocos2d.h"
@ -21,6 +44,7 @@ MyPurchase::~MyPurchase()
if (s_pRetListener)
{
delete s_pRetListener;
s_pRetListener = NULL;
}
}
@ -37,15 +61,22 @@ void MyPurchase::purgePurchase()
if (s_pPurchase)
{
delete s_pPurchase;
s_pPurchase = NULL;
}
PluginManager::end();
}
void MyPurchase::loadIAPPlugin()
{
if (s_pRetListener == NULL)
{
s_pRetListener = new MyPurchaseResult();
}
{
// init alipay plugin
s_pAlipay = dynamic_cast<IAPAlipay*>(PluginManager::getInstance()->loadPlugin("IAPAlipay"));
TDeveloperInfo pAlipayInfo;
TIAPDeveloperInfo pAlipayInfo;
if (pAlipayInfo.empty())
{
char msg[256] = { 0 };
@ -53,11 +84,12 @@ void MyPurchase::loadIAPPlugin()
CCMessageBox(msg, "Alipay Warning");
}
s_pAlipay->setDebugMode(true);
s_pAlipay->initDeveloperInfo(pAlipayInfo);
s_pAlipay->configDeveloperInfo(pAlipayInfo);
s_pAlipay->setResultListener(s_pRetListener);
}
{
TDeveloperInfo pNdInfo;
TIAPDeveloperInfo pNdInfo;
pNdInfo["Nd91AppId"] = "100010";
pNdInfo["Nd91AppKey"] = "C28454605B9312157C2F76F27A9BCA2349434E546A6E9C75";
pNdInfo["Nd91Orientation"] = "landscape";
@ -68,13 +100,8 @@ void MyPurchase::loadIAPPlugin()
}
s_pNd91 = dynamic_cast<IAPNd91*>(PluginManager::getInstance()->loadPlugin("IAPNd91"));
s_pNd91->setDebugMode(true);
s_pNd91->initDeveloperInfo(pNdInfo);
}
if (s_pRetListener == NULL)
{
s_pRetListener = new MyPurchaseResult();
ProtocolIAP::setResultListener(s_pRetListener);
s_pNd91->configDeveloperInfo(pNdInfo);
s_pNd91->setResultListener(s_pRetListener);
}
}
@ -113,7 +140,7 @@ void MyPurchase::payByMode(TProductInfo info, MyPayMode mode)
}
}
void MyPurchaseResult::payResult(EPayResult ret, const char* msg, TProductInfo info)
void MyPurchaseResult::onPayResult(PayResultCode ret, const char* msg, TProductInfo info)
{
char goodInfo[1024] = { 0 };
sprintf(goodInfo, "商品名称:%s\n商品价格:%s\n商品描述:%s",

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __MY_PURCHASE_H__
#define __MY_PURCHASE_H__
@ -7,7 +30,7 @@
class MyPurchaseResult : public cocos2d::plugin::PayResultListener
{
public:
virtual void payResult(cocos2d::plugin::EPayResult ret, const char* msg, cocos2d::plugin::TProductInfo info);
virtual void onPayResult(cocos2d::plugin::PayResultCode ret, const char* msg, cocos2d::plugin::TProductInfo info);
};
class MyPurchase

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "AppDelegate.h"
#include "platform/android/jni/JniHelper.h"
#include "PluginJniHelper.h"

View File

@ -0,0 +1,83 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "AppDelegate.h"
#include "cocos2d.h"
#include "HelloWorldScene.h"
#include "PluginManager.h"
#include "MySocialManager.h"
using namespace cocos2d::plugin;
USING_NS_CC;
AppDelegate::AppDelegate()
{
}
AppDelegate::~AppDelegate()
{
}
bool AppDelegate::applicationDidFinishLaunching()
{
MySocialManager::sharedSocialManager()->loadSocialPlugin();
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pEGLView->setDesignResolutionSize(960.0f, 640.0f, kResolutionNoBorder);
// turn on display FPS
pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
// create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene();
// run
pDirector->runWithScene(pScene);
return true;
}
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
CCDirector::sharedDirector()->pause();
// if you use SimpleAudioEngine, it must be pause
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->resume();
// if you use SimpleAudioEngine, it must resume here
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}

View File

@ -0,0 +1,63 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef _APP_DELEGATE_H_
#define _APP_DELEGATE_H_
#include "CCApplication.h"
/**
@brief The cocos2d Application.
The reason for implement as private inheritance is to hide some interface call by CCDirector.
*/
class AppDelegate : private cocos2d::CCApplication
{
public:
AppDelegate();
virtual ~AppDelegate();
/**
@brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching();
/**
@brief The function be called when the application enter background
@param the pointer of the application
*/
virtual void applicationDidEnterBackground();
/**
@brief The function be called when the application enter foreground
@param the pointer of the application
*/
virtual void applicationWillEnterForeground();
static void loadAnalyticsPlugin();
};
#endif // _APP_DELEGATE_H_

View File

@ -0,0 +1,150 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "HelloWorldScene.h"
#include "PluginManager.h"
#include "AppDelegate.h"
#include "MySocialManager.h"
using namespace cocos2d;
using namespace cocos2d::plugin;
enum {
TAG_SHARE_BY_TWWITER = 100,
};
typedef struct tagEventMenuItem {
std::string id;
int tag;
}EventMenuItem;
static EventMenuItem s_EventMenuItem[] = {
{"twitter.jpeg", TAG_SHARE_BY_TWWITER}
};
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
CCSize size = CCDirector::sharedDirector()->getVisibleSize();
CCSprite* pBackground = CCSprite::create("background.png");
pBackground->setPosition(ccp(size.width / 2, size.height / 2));
addChild(pBackground);
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
CCPoint posBR = ccp(pEGLView->getVisibleOrigin().x + pEGLView->getVisibleSize().width, pEGLView->getVisibleOrigin().y);
CCPoint posBC = ccp(pEGLView->getVisibleOrigin().x + pEGLView->getVisibleSize().width/2, pEGLView->getVisibleOrigin().y);
CCPoint posTL = ccp(pEGLView->getVisibleOrigin().x, pEGLView->getVisibleOrigin().y + pEGLView->getVisibleSize().height);
// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback) );
pCloseItem->setPosition( ccp(posBR.x - 20, posBR.y + 20) );
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition( CCPointZero );
this->addChild(pMenu, 1);
CCPoint posStep = ccp(220, -150);
CCPoint beginPos = ccpAdd(posTL, ccpMult(posStep, 0.5f));
int line = 0;
int row = 0;
for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) {
CCMenuItemImage* pMenuItem = CCMenuItemImage::create(s_EventMenuItem[i].id.c_str(), s_EventMenuItem[i].id.c_str(),
this, menu_selector(HelloWorld::eventMenuCallback));
pMenu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag);
CCPoint pos = ccpAdd(beginPos, ccp(posStep.x * row, posStep.y * line));
CCSize itemSize = pMenuItem->getContentSize();
if ((pos.x + itemSize.width / 2) > posBR.x)
{
line += 1;
row = 0;
pos = ccpAdd(beginPos, ccp(posStep.x * row, posStep.y * line));
}
row += 1;
pMenuItem->setPosition(pos);
}
CCLabelTTF* label = CCLabelTTF::create("Reload all plugins", "Arial", 24);
CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(HelloWorld::reloadPluginMenuCallback));
pMenuItem->setAnchorPoint(ccp(0.5f, 0));
pMenu->addChild(pMenuItem, 0);
pMenuItem->setPosition(posBC);
return true;
}
void HelloWorld::reloadPluginMenuCallback(CCObject* pSender)
{
MySocialManager::sharedSocialManager()->unloadSocialPlugin();
MySocialManager::sharedSocialManager()->loadSocialPlugin();
}
void HelloWorld::eventMenuCallback(CCObject* pSender)
{
CCMenuItemLabel* pMenuItem = (CCMenuItemLabel*)pSender;
TShareInfo pInfo;
pInfo["SharedText"] = "MyFirst tweet!";
// pInfo["SharedImagePath"] = "Full/path/to/image";
MySocialManager::MyShareMode mode = (MySocialManager::MyShareMode) (pMenuItem->getTag() - TAG_SHARE_BY_TWWITER + 1);
MySocialManager::sharedSocialManager()->shareByMode(pInfo, mode);
}
void HelloWorld::menuCloseCallback(CCObject* pSender)
{
MySocialManager::purgeManager();
CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}

View File

@ -0,0 +1,47 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::CCLayer
{
public:
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// there's no 'id' in cpp, so we recommand to return the exactly class pointer
static cocos2d::CCScene* scene();
// a selector callback
void menuCloseCallback(CCObject* pSender);
void eventMenuCallback(CCObject* pSender);
void reloadPluginMenuCallback(CCObject* pSender);
// implement the "static node()" method manually
CREATE_FUNC(HelloWorld);
};
#endif // __HELLOWORLD_SCENE_H__

View File

@ -0,0 +1,127 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "MySocialManager.h"
#include "PluginManager.h"
#include "cocos2d.h"
using namespace cocos2d::plugin;
using namespace cocos2d;
MySocialManager* MySocialManager::s_pManager = NULL;
MySocialManager::MySocialManager()
: s_pRetListener(NULL)
, s_pTwitter(NULL)
{
}
MySocialManager::~MySocialManager()
{
unloadSocialPlugin();
if (s_pRetListener)
{
delete s_pRetListener;
s_pRetListener = NULL;
}
}
MySocialManager* MySocialManager::sharedSocialManager()
{
if (s_pManager == NULL) {
s_pManager = new MySocialManager();
}
return s_pManager;
}
void MySocialManager::purgeManager()
{
if (s_pManager)
{
delete s_pManager;
s_pManager = NULL;
}
PluginManager::end();
}
void MySocialManager::loadSocialPlugin()
{
if (s_pRetListener == NULL)
{
s_pRetListener = new MyShareResult();
}
{
// init twitter plugin
s_pTwitter = dynamic_cast<SocialTwitter*>(PluginManager::getInstance()->loadPlugin("SocialTwitter"));
TSocialDeveloperInfo pTwitterInfo;
/* Warning: must set your twiiter dev info here */
// pTwitterInfo["TwitterKey"] = "your consumerkey";
// pTwitterInfo["TwitterSecret"] = "your consumersecret";
if (pTwitterInfo.empty())
{
char msg[256] = { 0 };
sprintf(msg, "Developer info is empty. PLZ fill your twitter info in %s(nearby line %d)", __FILE__, __LINE__);
CCMessageBox(msg, "Twitter Warning");
}
s_pTwitter->setDebugMode(true);
s_pTwitter->configDeveloperInfo(pTwitterInfo);
s_pTwitter->setResultListener(s_pRetListener);
}
}
void MySocialManager::unloadSocialPlugin()
{
if (s_pTwitter)
{
PluginManager::getInstance()->unloadPlugin("SocialTwitter");
s_pTwitter = NULL;
}
}
void MySocialManager::shareByMode(TShareInfo info, MyShareMode mode)
{
ProtocolSocial* pShare = NULL;
switch(mode)
{
case eTwitter:
pShare = s_pTwitter;
break;
default:
break;
}
if (pShare) {
pShare->share(info);
}
}
void MyShareResult::onShareResult(ShareResultCode ret, const char* msg)
{
char shareStatus[1024] = { 0 };
sprintf(shareStatus, "Share %s", (ret == kShareSuccess)? "Successed" : "Failed");
CCMessageBox(msg, shareStatus);
}

View File

@ -0,0 +1,60 @@
/****************************************************************************
Copyright (c) 2012-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __MY_SOCIAL_MANAGER_H__
#define __MY_SOCIAL_MANAGER_H__
#include "SocialTwitter.h"
class MyShareResult : public cocos2d::plugin::ShareResultListener
{
public:
virtual void onShareResult(cocos2d::plugin::ShareResultCode ret, const char* msg);
};
class MySocialManager
{
public:
static MySocialManager* sharedSocialManager();
static void purgeManager();
typedef enum {
eNoneMode = 0,
eTwitter,
} MyShareMode;
void unloadSocialPlugin();
void loadSocialPlugin();
void shareByMode(cocos2d::plugin::TShareInfo info, MyShareMode mode);
private:
MySocialManager();
virtual ~MySocialManager();
static MySocialManager* s_pManager;
cocos2d::plugin::SocialTwitter* s_pTwitter;
MyShareResult* s_pRetListener;
};
#endif // __MY_SOCIAL_MANAGER_H__

Some files were not shown because too many files have changed in this diff Show More