diff --git a/plugin/jsbindings/auto/jsb_pluginx_admob_auto.cpp b/plugin/jsbindings/auto/jsb_pluginx_admob_auto.cpp new file mode 100644 index 0000000000..a1372eadd0 --- /dev/null +++ b/plugin/jsbindings/auto/jsb_pluginx_admob_auto.cpp @@ -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 +static JSBool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { + TypeTest 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(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 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); +} + diff --git a/plugin/jsbindings/auto/jsb_pluginx_admob_auto.hpp b/plugin/jsbindings/auto/jsb_pluginx_admob_auto.hpp new file mode 100644 index 0000000000..acae9ba32d --- /dev/null +++ b/plugin/jsbindings/auto/jsb_pluginx_admob_auto.hpp @@ -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 + diff --git a/plugin/jsbindings/auto/jsb_pluginx_admob_auto_api.js b/plugin/jsbindings/auto/jsb_pluginx_admob_auto_api.js new file mode 100644 index 0000000000..1c79435300 --- /dev/null +++ b/plugin/jsbindings/auto/jsb_pluginx_admob_auto_api.js @@ -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 () {}, + +}; diff --git a/plugin/jsbindings/auto/jsb_pluginx_alipay_auto.cpp b/plugin/jsbindings/auto/jsb_pluginx_alipay_auto.cpp index 7ab36bbb2b..75bc1fc9b8 100644 --- a/plugin/jsbindings/auto/jsb_pluginx_alipay_auto.cpp +++ b/plugin/jsbindings/auto/jsb_pluginx_alipay_auto.cpp @@ -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; diff --git a/plugin/jsbindings/auto/jsb_pluginx_flurry_auto.cpp b/plugin/jsbindings/auto/jsb_pluginx_flurry_auto.cpp index ee847c19fe..3a7c14ba58 100644 --- a/plugin/jsbindings/auto/jsb_pluginx_flurry_auto.cpp +++ b/plugin/jsbindings/auto/jsb_pluginx_flurry_auto.cpp @@ -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; diff --git a/plugin/jsbindings/auto/jsb_pluginx_nd91_auto.cpp b/plugin/jsbindings/auto/jsb_pluginx_nd91_auto.cpp index 2b1f7de387..4f4b45bfbf 100644 --- a/plugin/jsbindings/auto/jsb_pluginx_nd91_auto.cpp +++ b/plugin/jsbindings/auto/jsb_pluginx_nd91_auto.cpp @@ -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; diff --git a/plugin/jsbindings/auto/jsb_pluginx_protocols_auto.cpp b/plugin/jsbindings/auto/jsb_pluginx_protocols_auto.cpp index 3f27495a77..ae2a606ec0 100644 --- a/plugin/jsbindings/auto/jsb_pluginx_protocols_auto.cpp +++ b/plugin/jsbindings/auto/jsb_pluginx_protocols_auto.cpp @@ -5,7 +5,7 @@ using namespace pluginx; #include "PluginManager.h" #include "ProtocolAnalytics.h" #include "ProtocolIAP.h" -#include "ProtocolIAPOnLine.h" +#include "ProtocolAds.h" template 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(nproxy->ptr); +// cocos2d::plugin::ProtocolAds *nobj = static_cast(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 t; + TypeTest 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); } diff --git a/plugin/jsbindings/auto/jsb_pluginx_protocols_auto.hpp b/plugin/jsbindings/auto/jsb_pluginx_protocols_auto.hpp index bed1cddc4f..bb19f692fd 100644 --- a/plugin/jsbindings/auto/jsb_pluginx_protocols_auto.hpp +++ b/plugin/jsbindings/auto/jsb_pluginx_protocols_auto.hpp @@ -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 diff --git a/plugin/jsbindings/auto/jsb_pluginx_protocols_auto_api.js b/plugin/jsbindings/auto/jsb_pluginx_protocols_auto_api.js index 8c78501777..806d347b87 100644 --- a/plugin/jsbindings/auto/jsb_pluginx_protocols_auto_api.js +++ b/plugin/jsbindings/auto/jsb_pluginx_protocols_auto_api.js @@ -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 () {}, }; diff --git a/plugin/jsbindings/auto/jsb_pluginx_umeng_auto.cpp b/plugin/jsbindings/auto/jsb_pluginx_umeng_auto.cpp index e7e2780fd9..57356f1c47 100644 --- a/plugin/jsbindings/auto/jsb_pluginx_umeng_auto.cpp +++ b/plugin/jsbindings/auto/jsb_pluginx_umeng_auto.cpp @@ -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; diff --git a/plugin/jsbindings/manual/jsb_pluginx_extension_registration.cpp b/plugin/jsbindings/manual/jsb_pluginx_extension_registration.cpp index f461f8919c..ce13a11f3d 100644 --- a/plugin/jsbindings/manual/jsb_pluginx_extension_registration.cpp +++ b/plugin/jsbindings/manual/jsb_pluginx_extension_registration.cpp @@ -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); } \ No newline at end of file diff --git a/plugin/jsbindings/manual/jsb_pluginx_manual_iap.cpp b/plugin/jsbindings/manual/jsb_pluginx_manual_iap.cpp index 7ff6306b3e..a5cd5b0e3f 100644 --- a/plugin/jsbindings/manual/jsb_pluginx_manual_iap.cpp +++ b/plugin/jsbindings/manual/jsb_pluginx_manual_iap.cpp @@ -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; diff --git a/plugin/jsbindings/manual/jsb_pluginx_manual_iap.h b/plugin/jsbindings/manual/jsb_pluginx_manual_iap.h index b9bbe8105e..cb93009c82 100644 --- a/plugin/jsbindings/manual/jsb_pluginx_manual_iap.h +++ b/plugin/jsbindings/manual/jsb_pluginx_manual_iap.h @@ -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__ */ diff --git a/plugin/plugins/admob/include/AdsAdmob.h b/plugin/plugins/admob/include/AdsAdmob.h index 47e38daaf1..5f30c20d88 100644 --- a/plugin/plugins/admob/include/AdsAdmob.h +++ b/plugin/plugins/admob/include/AdsAdmob.h @@ -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. diff --git a/plugin/plugins/admob/jsb_admob.ini b/plugin/plugins/admob/jsb_admob.ini index b956fa5da4..ab93d3da10 100644 --- a/plugin/plugins/admob/jsb_admob.ini +++ b/plugin/plugins/admob/jsb_admob.ini @@ -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 diff --git a/plugin/plugins/admob/platform/android/AdsAdmob.cpp b/plugin/plugins/admob/platform/android/AdsAdmob.cpp index a0bb4a739d..1cfba3f2b7 100644 --- a/plugin/plugins/admob/platform/android/AdsAdmob.cpp +++ b/plugin/plugins/admob/platform/android/AdsAdmob.cpp @@ -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() diff --git a/plugin/plugins/admob/proj.android/src/org/cocos2dx/plugin/AdsAdmob.java b/plugin/plugins/admob/proj.android/src/org/cocos2dx/plugin/AdsAdmob.java index 1b486317f9..5395002616 100644 --- a/plugin/plugins/admob/proj.android/src/org/cocos2dx/plugin/AdsAdmob.java +++ b/plugin/plugins/admob/proj.android/src/org/cocos2dx/plugin/AdsAdmob.java @@ -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 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 appInfo) { + public void configDeveloperInfo(Hashtable 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!"); } } } diff --git a/plugin/plugins/alipay/include/IAPAlipay.h b/plugin/plugins/alipay/include/IAPAlipay.h index 852e84e204..0085e19ab3 100644 --- a/plugin/plugins/alipay/include/IAPAlipay.h +++ b/plugin/plugins/alipay/include/IAPAlipay.h @@ -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 diff --git a/plugin/plugins/alipay/platform/android/IAPAlipay.cpp b/plugin/plugins/alipay/platform/android/IAPAlipay.cpp index 24ce29d769..21657963e6 100644 --- a/plugin/plugins/alipay/platform/android/IAPAlipay.cpp +++ b/plugin/plugins/alipay/platform/android/IAPAlipay.cpp @@ -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); } /** diff --git a/plugin/plugins/alipay/proj.android/src/org/cocos2dx/plugin/IAPAlipay.java b/plugin/plugins/alipay/proj.android/src/org/cocos2dx/plugin/IAPAlipay.java index f1e08b1832..4d0dcade3d 100644 --- a/plugin/plugins/alipay/proj.android/src/org/cocos2dx/plugin/IAPAlipay.java +++ b/plugin/plugins/alipay/proj.android/src/org/cocos2dx/plugin/IAPAlipay.java @@ -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 cpInfo) { + public void configDeveloperInfo(Hashtable 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); } } diff --git a/plugin/plugins/flurry/include/AnalyticsFlurry.h b/plugin/plugins/flurry/include/AnalyticsFlurry.h index 8904e28039..6eb932e08d 100644 --- a/plugin/plugins/flurry/include/AnalyticsFlurry.h +++ b/plugin/plugins/flurry/include/AnalyticsFlurry.h @@ -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__ diff --git a/plugin/plugins/flurry/platform/android/AnalyticsFlurry.cpp b/plugin/plugins/flurry/platform/android/AnalyticsFlurry.cpp index 4334605b70..e6ce0752e8 100644 --- a/plugin/plugins/flurry/platform/android/AnalyticsFlurry.cpp +++ b/plugin/plugins/flurry/platform/android/AnalyticsFlurry.cpp @@ -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 diff --git a/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm b/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm index a7b9a22509..943586e5ee 100644 --- a/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm +++ b/plugin/plugins/flurry/platform/ios/AnalyticsFlurry.mm @@ -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" diff --git a/plugin/plugins/flurry/platform/win32/AnalyticsFlurry.cpp b/plugin/plugins/flurry/platform/win32/AnalyticsFlurry.cpp deleted file mode 100644 index d7f8837968..0000000000 --- a/plugin/plugins/flurry/platform/win32/AnalyticsFlurry.cpp +++ /dev/null @@ -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 { diff --git a/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java b/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java index f7d1b41888..f738728077 100644 --- a/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java +++ b/plugin/plugins/flurry/proj.android/src/org/cocos2dx/plugin/AnalyticsFlurry.java @@ -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; diff --git a/plugin/plugins/nd91/include/IAPNd91.h b/plugin/plugins/nd91/include/IAPNd91.h index 21f2c82bad..2b81a65124 100644 --- a/plugin/plugins/nd91/include/IAPNd91.h +++ b/plugin/plugins/nd91/include/IAPNd91.h @@ -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 diff --git a/plugin/plugins/nd91/platform/android/IAPNd91.cpp b/plugin/plugins/nd91/platform/android/IAPNd91.cpp index 373ddad2cf..664a03e9ba 100644 --- a/plugin/plugins/nd91/platform/android/IAPNd91.cpp +++ b/plugin/plugins/nd91/platform/android/IAPNd91.cpp @@ -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); } /** diff --git a/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java b/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java index 6cb6652b6b..aa2a8335af 100644 --- a/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java +++ b/plugin/plugins/nd91/proj.android/src/org/cocos2dx/plugin/IAPNd91.java @@ -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 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 cpInfo) { + public void configDeveloperInfo(Hashtable cpInfo) { LogD("initDeveloperInfo invoked " + cpInfo.toString()); final Hashtable 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); } diff --git a/plugin/plugins/twitter/include/SocialTwitter.h b/plugin/plugins/twitter/include/SocialTwitter.h new file mode 100755 index 0000000000..6487741d0c --- /dev/null +++ b/plugin/plugins/twitter/include/SocialTwitter.h @@ -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 +#include + +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__ */ diff --git a/plugin/plugins/twitter/platform/android/SocialTwitter.cpp b/plugin/plugins/twitter/platform/android/SocialTwitter.cpp new file mode 100755 index 0000000000..d6bccf398c --- /dev/null +++ b/plugin/plugins/twitter/platform/android/SocialTwitter.cpp @@ -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 { diff --git a/plugin/plugins/twitter/proj.android/.classpath b/plugin/plugins/twitter/proj.android/.classpath new file mode 100755 index 0000000000..e877b82024 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/plugin/plugins/twitter/proj.android/.project b/plugin/plugins/twitter/proj.android/.project new file mode 100755 index 0000000000..9aade58531 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/.project @@ -0,0 +1,45 @@ + + + libPluginTwitter + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + + + android + 2 + PARENT-1-PROJECT_LOC/platform/android + + + include + 2 + PARENT-1-PROJECT_LOC/include + + + diff --git a/plugin/plugins/twitter/proj.android/AndroidManifest.xml b/plugin/plugins/twitter/proj.android/AndroidManifest.xml new file mode 100755 index 0000000000..8582917b67 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/AndroidManifest.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/plugin/plugins/twitter/proj.android/ForManifest.xml b/plugin/plugins/twitter/proj.android/ForManifest.xml new file mode 100755 index 0000000000..00d34cd419 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/ForManifest.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/plugin/plugins/twitter/proj.android/build.xml b/plugin/plugins/twitter/proj.android/build.xml new file mode 100755 index 0000000000..10e9663ff5 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/build.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugin/plugins/twitter/proj.android/build_native.sh b/plugin/plugins/twitter/proj.android/build_native.sh new file mode 100755 index 0000000000..0b272b9465 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/build_native.sh @@ -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 \ No newline at end of file diff --git a/plugin/plugins/twitter/proj.android/jni/Android.mk b/plugin/plugins/twitter/proj.android/jni/Android.mk new file mode 100755 index 0000000000..e4c920eb4c --- /dev/null +++ b/plugin/plugins/twitter/proj.android/jni/Android.mk @@ -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) diff --git a/plugin/plugins/twitter/proj.android/jni/Application.mk b/plugin/plugins/twitter/proj.android/jni/Application.mk new file mode 100755 index 0000000000..e4935028c3 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/jni/Application.mk @@ -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 diff --git a/plugin/plugins/twitter/proj.android/project.properties b/plugin/plugins/twitter/proj.android/project.properties new file mode 100755 index 0000000000..9d741eed16 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/project.properties @@ -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 diff --git a/plugin/plugins/twitter/proj.android/res/.gitignore b/plugin/plugins/twitter/proj.android/res/.gitignore new file mode 100755 index 0000000000..e69de29bb2 diff --git a/plugin/plugins/twitter/proj.android/sdk/signpost-commonshttp4-1.2.1.1.jar b/plugin/plugins/twitter/proj.android/sdk/signpost-commonshttp4-1.2.1.1.jar new file mode 100755 index 0000000000..50e9838e6f Binary files /dev/null and b/plugin/plugins/twitter/proj.android/sdk/signpost-commonshttp4-1.2.1.1.jar differ diff --git a/plugin/plugins/twitter/proj.android/sdk/signpost-core-1.2.1.1.jar b/plugin/plugins/twitter/proj.android/sdk/signpost-core-1.2.1.1.jar new file mode 100755 index 0000000000..59e7537f51 Binary files /dev/null and b/plugin/plugins/twitter/proj.android/sdk/signpost-core-1.2.1.1.jar differ diff --git a/plugin/plugins/twitter/proj.android/sdk/signpost-jetty6-1.2.1.1.jar b/plugin/plugins/twitter/proj.android/sdk/signpost-jetty6-1.2.1.1.jar new file mode 100755 index 0000000000..b5d974c7ce Binary files /dev/null and b/plugin/plugins/twitter/proj.android/sdk/signpost-jetty6-1.2.1.1.jar differ diff --git a/plugin/plugins/twitter/proj.android/sdk/twitter4j-core-android-3.0.1.jar.REMOVED.git-id b/plugin/plugins/twitter/proj.android/sdk/twitter4j-core-android-3.0.1.jar.REMOVED.git-id new file mode 100644 index 0000000000..cd6a606604 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/sdk/twitter4j-core-android-3.0.1.jar.REMOVED.git-id @@ -0,0 +1 @@ +62d02b6f0d450b3b64d061280594018742ddcd27 \ No newline at end of file diff --git a/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/Consts.java b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/Consts.java new file mode 100644 index 0000000000..74b4ea8da2 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/Consts.java @@ -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; +} diff --git a/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/SocialTwitter.java b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/SocialTwitter.java new file mode 100755 index 0000000000..d539e6f016 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/SocialTwitter.java @@ -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 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 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 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(); + } + } +} diff --git a/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/TwitterApp.java b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/TwitterApp.java new file mode 100755 index 0000000000..0c36337846 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/TwitterApp.java @@ -0,0 +1,235 @@ +/** + * @author Lorensius W. L. T + * + * 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); + } + +} \ No newline at end of file diff --git a/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/TwitterDialog.java b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/TwitterDialog.java new file mode 100755 index 0000000000..68303860a6 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/TwitterDialog.java @@ -0,0 +1,182 @@ +/** + * Modified from FbDialog from Facebook SDK + * + * Lorensius W. L. T + */ +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!"); + } + }; +} diff --git a/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/TwitterSession.java b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/TwitterSession.java new file mode 100755 index 0000000000..df31682937 --- /dev/null +++ b/plugin/plugins/twitter/proj.android/src/org/cocos2dx/plugin/TwitterSession.java @@ -0,0 +1,56 @@ +/** + * @author Lorensius W. L. T + * + * 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; + } +} diff --git a/plugin/plugins/umeng/include/AnalyticsUmeng.h b/plugin/plugins/umeng/include/AnalyticsUmeng.h index 0aef482555..187fb2c619 100644 --- a/plugin/plugins/umeng/include/AnalyticsUmeng.h +++ b/plugin/plugins/umeng/include/AnalyticsUmeng.h @@ -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__ diff --git a/plugin/plugins/umeng/platform/android/AnalyticsUmeng.cpp b/plugin/plugins/umeng/platform/android/AnalyticsUmeng.cpp index 205ee0ee24..42661f095f 100644 --- a/plugin/plugins/umeng/platform/android/AnalyticsUmeng.cpp +++ b/plugin/plugins/umeng/platform/android/AnalyticsUmeng.cpp @@ -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 diff --git a/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm b/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm index 0fb2fb1444..72abc16857 100644 --- a/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm +++ b/plugin/plugins/umeng/platform/ios/AnalyticsUmeng.mm @@ -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" diff --git a/plugin/plugins/umeng/platform/win32/AnalyticsUmeng.cpp b/plugin/plugins/umeng/platform/win32/AnalyticsUmeng.cpp deleted file mode 100644 index 021bfc13c8..0000000000 --- a/plugin/plugins/umeng/platform/win32/AnalyticsUmeng.cpp +++ /dev/null @@ -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 { diff --git a/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java b/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java index 647aab482e..37185a21f9 100644 --- a/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java +++ b/plugin/plugins/umeng/proj.android/src/org/cocos2dx/plugin/AnalyticsUmeng.java @@ -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; diff --git a/plugin/protocols/PluginManager.cpp b/plugin/protocols/PluginManager.cpp index 6f73ae209b..64a3e3170d 100644 --- a/plugin/protocols/PluginManager.cpp +++ b/plugin/protocols/PluginManager.cpp @@ -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 #include diff --git a/plugin/protocols/RegisterPlugin.cpp b/plugin/protocols/RegisterPlugin.cpp index b9c66515c1..7d5f3229c2 100644 --- a/plugin/protocols/RegisterPlugin.cpp +++ b/plugin/protocols/RegisterPlugin.cpp @@ -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" diff --git a/plugin/protocols/include/PluginManager.h b/plugin/protocols/include/PluginManager.h index cedba1f40d..f618625086 100644 --- a/plugin/protocols/include/PluginManager.h +++ b/plugin/protocols/include/PluginManager.h @@ -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__ diff --git a/plugin/protocols/include/PluginProtocol.h b/plugin/protocols/include/PluginProtocol.h index 08cf1faf86..f59917e082 100644 --- a/plugin/protocols/include/PluginProtocol.h +++ b/plugin/protocols/include/PluginProtocol.h @@ -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__ */ diff --git a/plugin/protocols/include/ProtocolAds.h b/plugin/protocols/include/ProtocolAds.h index 31d4427e3b..30a15d8149 100644 --- a/plugin/protocols/include/ProtocolAds.h +++ b/plugin/protocols/include/ProtocolAds.h @@ -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 TAppInfo; +typedef std::map 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; - - virtual void onReceiveAd() {} - virtual void onPresentScreen() {} - virtual void onFailedToReceiveAd(EAdErrorCode code, const char* msg) {} - virtual void onDismissScreen() {} + /** + @brief The advertisement request result + */ + virtual void onAdsResult(AdsResultCode code, const char* msg) = 0; + + /** + @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 { diff --git a/plugin/protocols/include/ProtocolAnalytics.h b/plugin/protocols/include/ProtocolAnalytics.h index 0214bd8b08..17a7ce7809 100644 --- a/plugin/protocols/include/ProtocolAnalytics.h +++ b/plugin/protocols/include/ProtocolAnalytics.h @@ -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__ diff --git a/plugin/protocols/include/ProtocolIAP.h b/plugin/protocols/include/ProtocolIAP.h index 5ce57a0d9e..73c501c282 100644 --- a/plugin/protocols/include/ProtocolIAP.h +++ b/plugin/protocols/include/ProtocolIAP.h @@ -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 TDeveloperInfo; +typedef std::map TIAPDeveloperInfo; typedef std::map 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 { diff --git a/plugin/protocols/include/ProtocolSocial.h b/plugin/protocols/include/ProtocolSocial.h new file mode 100755 index 0000000000..c6fe7434c2 --- /dev/null +++ b/plugin/protocols/include/ProtocolSocial.h @@ -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 +#include + +namespace cocos2d { namespace plugin { + +typedef std::map TSocialDeveloperInfo; +typedef std::map 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__ ----- */ diff --git a/plugin/protocols/include/RegisterPlugin.h b/plugin/protocols/include/RegisterPlugin.h index 935bc58baa..ea59063e37 100644 --- a/plugin/protocols/include/RegisterPlugin.h +++ b/plugin/protocols/include/RegisterPlugin.h @@ -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__ */ diff --git a/plugin/protocols/jsb_protocols.ini b/plugin/protocols/jsb_protocols.ini index f65109a346..baf7dac773 100644 --- a/plugin/protocols/jsb_protocols.ini +++ b/plugin/protocols/jsb_protocols.ini @@ -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 diff --git a/plugin/protocols/platform/android/PluginJavaData.h b/plugin/protocols/platform/android/PluginJavaData.h index e40afb3b4f..5ab55ea462 100644 --- a/plugin/protocols/platform/android/PluginJavaData.h +++ b/plugin/protocols/platform/android/PluginJavaData.h @@ -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__ diff --git a/plugin/protocols/platform/android/PluginJniHelper.cpp b/plugin/protocols/platform/android/PluginJniHelper.cpp index 8006898744..d70198e2b1 100644 --- a/plugin/protocols/platform/android/PluginJniHelper.cpp +++ b/plugin/protocols/platform/android/PluginJniHelper.cpp @@ -1,5 +1,5 @@ /**************************************************************************** -Copyright (c) 2010 cocos2d-x.org +Copyright (c) 2012-2013 cocos2d-x.org http://www.cocos2d-x.org diff --git a/plugin/protocols/platform/android/PluginJniHelper.h b/plugin/protocols/platform/android/PluginJniHelper.h index 9adcdc81e6..8c48c286bc 100644 --- a/plugin/protocols/platform/android/PluginJniHelper.h +++ b/plugin/protocols/platform/android/PluginJniHelper.h @@ -1,5 +1,5 @@ /**************************************************************************** -Copyright (c) 2010-2011 cocos2d-x.org +Copyright (c) 2012-2013 cocos2d-x.org http://www.cocos2d-x.org diff --git a/plugin/protocols/platform/android/PluginUtils.cpp b/plugin/protocols/platform/android/PluginUtils.cpp index 9044ac2c80..dd9bf03227 100644 --- a/plugin/protocols/platform/android/PluginUtils.cpp +++ b/plugin/protocols/platform/android/PluginUtils.cpp @@ -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 #include @@ -96,8 +119,10 @@ JNIEnv* PluginUtils::getEnv() } std::map s_PluginObjMap; +std::map s_JObjPluginMap; typedef std::map::iterator ObjMapIter; +typedef std::map::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(pKeyObj, pData)); + s_JObjPluginMap.insert(std::pair(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); diff --git a/plugin/protocols/platform/android/PluginUtils.h b/plugin/protocols/platform/android/PluginUtils.h index 0cfdfb435a..2bb201b44b 100644 --- a/plugin/protocols/platform/android/PluginUtils.h +++ b/plugin/protocols/platform/android/PluginUtils.h @@ -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 static void callJavaFunctionWithName_oneBaseType(PluginProtocol* thiz, const char* funcName, const char* paramCode, T param) { diff --git a/plugin/protocols/platform/android/ProtocolAds.cpp b/plugin/protocols/platform/android/ProtocolAds.cpp index 9fc750ea17..6d62199175 100644 --- a/plugin/protocols/platform/android/ProtocolAds.cpp +++ b/plugin/protocols/platform/android/ProtocolAds.cpp @@ -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 @@ -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(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(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); } } diff --git a/plugin/protocols/platform/android/ProtocolAnalytics.cpp b/plugin/protocols/platform/android/ProtocolAnalytics.cpp index 366714c488..edeb4b19b9 100644 --- a/plugin/protocols/platform/android/ProtocolAnalytics.cpp +++ b/plugin/protocols/platform/android/ProtocolAnalytics.cpp @@ -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 diff --git a/plugin/protocols/platform/android/ProtocolIAP.cpp b/plugin/protocols/platform/android/ProtocolIAP.cpp index 0ecd3e0c23..a85ca0435b 100644 --- a/plugin/protocols/platform/android/ProtocolIAP.cpp +++ b/plugin/protocols/platform/android/ProtocolIAP.cpp @@ -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 @@ -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(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 { diff --git a/plugin/protocols/platform/android/ProtocolSocial.cpp b/plugin/protocols/platform/android/ProtocolSocial.cpp new file mode 100755 index 0000000000..1398008668 --- /dev/null +++ b/plugin/protocols/platform/android/ProtocolSocial.cpp @@ -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 +#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(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 { diff --git a/plugin/protocols/proj.android/jni/Android.mk b/plugin/protocols/proj.android/jni/Android.mk old mode 100644 new mode 100755 index 9e0ad021e8..5e82597a05 --- a/plugin/protocols/proj.android/jni/Android.mk +++ b/plugin/protocols/proj.android/jni/Android.mk @@ -13,6 +13,7 @@ $(addprefix ../../platform/android/, \ ProtocolAnalytics.cpp \ ProtocolIAP.cpp \ ProtocolAds.cpp \ + ProtocolSocial.cpp \ ) \ ../../PluginManager.cpp \ ../../RegisterPlugin.cpp \ diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java index 551a98e5d0..8427234475 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAds.java @@ -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 appInfo); - public void showBannerAd(int pos, int sizeEnum); - public void hideBannerAd(); + public void configDeveloperInfo(Hashtable 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(); - - public static void presentScreen() { + private native static void nativeOnAdsResult(Object obj, int code, String msg); + + 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); } diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAnalytics.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAnalytics.java index 0f85a02312..9135cd8519 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAnalytics.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceAnalytics.java @@ -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; diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java index 7da853283e..d6a9a91475 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceIAP.java @@ -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 cpInfo); + public void configDeveloperInfo(Hashtable cpInfo); public void payForProduct(Hashtable 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); } diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java new file mode 100755 index 0000000000..be6fcde97c --- /dev/null +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/InterfaceSocial.java @@ -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 cpInfo); + public void share(Hashtable 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); +} diff --git a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java index 6615d17529..3583870a19 100644 --- a/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java +++ b/plugin/protocols/proj.android/src/org/cocos2dx/plugin/PluginWrapper.java @@ -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; diff --git a/plugin/samples/HelloAds/Classes/AppDelegate.cpp b/plugin/samples/HelloAds/Classes/AppDelegate.cpp index 2acc5c1a3f..1eb01cb82e 100644 --- a/plugin/samples/HelloAds/Classes/AppDelegate.cpp +++ b/plugin/samples/HelloAds/Classes/AppDelegate.cpp @@ -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" diff --git a/plugin/samples/HelloAds/Classes/AppDelegate.h b/plugin/samples/HelloAds/Classes/AppDelegate.h index 268c6c6504..301f41163a 100644 --- a/plugin/samples/HelloAds/Classes/AppDelegate.h +++ b/plugin/samples/HelloAds/Classes/AppDelegate.h @@ -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_ diff --git a/plugin/samples/HelloAds/Classes/HelloWorldScene.cpp b/plugin/samples/HelloAds/Classes/HelloWorldScene.cpp index fefd5d45ab..c9f85329a5 100644 --- a/plugin/samples/HelloAds/Classes/HelloWorldScene.cpp +++ b/plugin/samples/HelloAds/Classes/HelloWorldScene.cpp @@ -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(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); + } } diff --git a/plugin/samples/HelloAds/Classes/HelloWorldScene.h b/plugin/samples/HelloAds/Classes/HelloWorldScene.h index 0594f38fdf..c3d22a239c 100644 --- a/plugin/samples/HelloAds/Classes/HelloWorldScene.h +++ b/plugin/samples/HelloAds/Classes/HelloWorldScene.h @@ -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__ diff --git a/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp b/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp index d4a4dc45cf..f653accc48 100644 --- a/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp +++ b/plugin/samples/HelloAnalytics/Classes/AppDelegate.cpp @@ -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" diff --git a/plugin/samples/HelloAnalytics/Classes/AppDelegate.h b/plugin/samples/HelloAnalytics/Classes/AppDelegate.h index d036940402..cb6c1f28dd 100644 --- a/plugin/samples/HelloAnalytics/Classes/AppDelegate.h +++ b/plugin/samples/HelloAnalytics/Classes/AppDelegate.h @@ -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_ diff --git a/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp b/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp index 55bdc9c73d..5dbdbadaa7 100644 --- a/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp +++ b/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.cpp @@ -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); diff --git a/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.h b/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.h index cf90652eeb..35352d5970 100644 --- a/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.h +++ b/plugin/samples/HelloAnalytics/Classes/HelloWorldScene.h @@ -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__ diff --git a/plugin/samples/HelloIAP/Classes/AppDelegate.cpp b/plugin/samples/HelloIAP/Classes/AppDelegate.cpp index 318108b06a..70b1b98233 100644 --- a/plugin/samples/HelloIAP/Classes/AppDelegate.cpp +++ b/plugin/samples/HelloIAP/Classes/AppDelegate.cpp @@ -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" diff --git a/plugin/samples/HelloIAP/Classes/AppDelegate.h b/plugin/samples/HelloIAP/Classes/AppDelegate.h index d036940402..8be63283dc 100644 --- a/plugin/samples/HelloIAP/Classes/AppDelegate.h +++ b/plugin/samples/HelloIAP/Classes/AppDelegate.h @@ -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_ - diff --git a/plugin/samples/HelloIAP/Classes/HelloWorldScene.cpp b/plugin/samples/HelloIAP/Classes/HelloWorldScene.cpp index e23b06d8b2..d9fbfaa92a 100644 --- a/plugin/samples/HelloIAP/Classes/HelloWorldScene.cpp +++ b/plugin/samples/HelloIAP/Classes/HelloWorldScene.cpp @@ -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" diff --git a/plugin/samples/HelloIAP/Classes/HelloWorldScene.h b/plugin/samples/HelloIAP/Classes/HelloWorldScene.h index cf90652eeb..35352d5970 100644 --- a/plugin/samples/HelloIAP/Classes/HelloWorldScene.h +++ b/plugin/samples/HelloIAP/Classes/HelloWorldScene.h @@ -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__ diff --git a/plugin/samples/HelloIAP/Classes/MyPurchase.cpp b/plugin/samples/HelloIAP/Classes/MyPurchase.cpp index b439333e80..213909a207 100644 --- a/plugin/samples/HelloIAP/Classes/MyPurchase.cpp +++ b/plugin/samples/HelloIAP/Classes/MyPurchase.cpp @@ -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(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(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", diff --git a/plugin/samples/HelloIAP/Classes/MyPurchase.h b/plugin/samples/HelloIAP/Classes/MyPurchase.h index ebd23dd334..df863f009c 100644 --- a/plugin/samples/HelloIAP/Classes/MyPurchase.h +++ b/plugin/samples/HelloIAP/Classes/MyPurchase.h @@ -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 diff --git a/plugin/samples/HelloIAP/proj.android/jni/hellocpp/main.cpp b/plugin/samples/HelloIAP/proj.android/jni/hellocpp/main.cpp index ee1079c797..c10543c193 100644 --- a/plugin/samples/HelloIAP/proj.android/jni/hellocpp/main.cpp +++ b/plugin/samples/HelloIAP/proj.android/jni/hellocpp/main.cpp @@ -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" diff --git a/plugin/samples/HelloSocial/Classes/AppDelegate.cpp b/plugin/samples/HelloSocial/Classes/AppDelegate.cpp new file mode 100755 index 0000000000..69c643a5a1 --- /dev/null +++ b/plugin/samples/HelloSocial/Classes/AppDelegate.cpp @@ -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(); +} diff --git a/plugin/samples/HelloSocial/Classes/AppDelegate.h b/plugin/samples/HelloSocial/Classes/AppDelegate.h new file mode 100755 index 0000000000..cb6c1f28dd --- /dev/null +++ b/plugin/samples/HelloSocial/Classes/AppDelegate.h @@ -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_ + diff --git a/plugin/samples/HelloSocial/Classes/HelloWorldScene.cpp b/plugin/samples/HelloSocial/Classes/HelloWorldScene.cpp new file mode 100755 index 0000000000..e9cde26419 --- /dev/null +++ b/plugin/samples/HelloSocial/Classes/HelloWorldScene.cpp @@ -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 +} diff --git a/plugin/samples/HelloSocial/Classes/HelloWorldScene.h b/plugin/samples/HelloSocial/Classes/HelloWorldScene.h new file mode 100755 index 0000000000..35352d5970 --- /dev/null +++ b/plugin/samples/HelloSocial/Classes/HelloWorldScene.h @@ -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__ diff --git a/plugin/samples/HelloSocial/Classes/MySocialManager.cpp b/plugin/samples/HelloSocial/Classes/MySocialManager.cpp new file mode 100755 index 0000000000..439c11a535 --- /dev/null +++ b/plugin/samples/HelloSocial/Classes/MySocialManager.cpp @@ -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(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); +} diff --git a/plugin/samples/HelloSocial/Classes/MySocialManager.h b/plugin/samples/HelloSocial/Classes/MySocialManager.h new file mode 100755 index 0000000000..4dc4ff7525 --- /dev/null +++ b/plugin/samples/HelloSocial/Classes/MySocialManager.h @@ -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__ diff --git a/plugin/samples/HelloSocial/Resources/background.png.REMOVED.git-id b/plugin/samples/HelloSocial/Resources/background.png.REMOVED.git-id new file mode 100644 index 0000000000..15b10523a1 --- /dev/null +++ b/plugin/samples/HelloSocial/Resources/background.png.REMOVED.git-id @@ -0,0 +1 @@ +b2e4ae6ce873ef4a74cf0230693ef26e939d2778 \ No newline at end of file diff --git a/plugin/samples/HelloSocial/proj.android/.classpath b/plugin/samples/HelloSocial/proj.android/.classpath new file mode 100755 index 0000000000..78f3e75cff --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/.classpath @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/plugin/samples/HelloSocial/proj.android/.project b/plugin/samples/HelloSocial/proj.android/.project new file mode 100755 index 0000000000..5227238c68 --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/.project @@ -0,0 +1,45 @@ + + + HelloSocial + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + + + Classes + 2 + PARENT-1-PROJECT_LOC/Classes + + + plugin-x + 2 + PARENT-3-PROJECT_LOC/publish + + + diff --git a/plugin/samples/HelloSocial/proj.android/AndroidManifest.xml b/plugin/samples/HelloSocial/proj.android/AndroidManifest.xml new file mode 100755 index 0000000000..68fe456fce --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + diff --git a/plugin/samples/HelloSocial/proj.android/ant.properties b/plugin/samples/HelloSocial/proj.android/ant.properties new file mode 100755 index 0000000000..b0971e891e --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/ant.properties @@ -0,0 +1,17 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked into Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. + diff --git a/plugin/samples/HelloSocial/proj.android/build.xml b/plugin/samples/HelloSocial/proj.android/build.xml new file mode 100755 index 0000000000..b3f20e0181 --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/build.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugin/samples/HelloSocial/proj.android/build_native.sh b/plugin/samples/HelloSocial/proj.android/build_native.sh new file mode 100755 index 0000000000..0e800b7d70 --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/build_native.sh @@ -0,0 +1,81 @@ +APPNAME="HelloSocial" + +# options + +buildexternalsfromsource= + +usage(){ +cat << EOF +usage: $0 [options] + +Build C/C++ code for $APPNAME using Android NDK + +OPTIONS: +-s Build externals from source +-h this help +EOF +} + +while getopts "sh" OPTION; do +case "$OPTION" in +s) +buildexternalsfromsource=1 +;; +h) +usage +exit 0 +;; +esac +done + +# paths + +if [ -z "${NDK_ROOT+aaa}" ];then +echo "please define NDK_ROOT" +exit 1 +fi + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# ... use paths relative to current directory +PLUGIN_ROOT="$DIR/../../.." +COCOS2DX_ROOT="$DIR/../../../.." +APP_ROOT="$DIR/.." +APP_ANDROID_ROOT="$DIR" + +echo "PLUGIN_ROOT = $PLUGIN_ROOT" +echo "NDK_ROOT = $NDK_ROOT" +echo "COCOS2DX_ROOT = $COCOS2DX_ROOT" +echo "APP_ROOT = $APP_ROOT" +echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT" +echo "---------------------------------------------------------" + +# make sure assets is exist +if [ -d "$APP_ANDROID_ROOT"/assets ]; then + rm -rf "$APP_ANDROID_ROOT"/assets +fi + +mkdir "$APP_ANDROID_ROOT"/assets + +# copy resources +for file in "$APP_ROOT"/Resources/* +do +if [ -d "$file" ]; then + cp -rf "$file" "$APP_ANDROID_ROOT"/assets +fi + +if [ -f "$file" ]; then + cp "$file" "$APP_ANDROID_ROOT"/assets +fi +done + +if [[ "$buildexternalsfromsource" ]]; then + echo "Building external dependencies from source" + set -x + "$NDK_ROOT"/ndk-build -j 4 -C "$APP_ANDROID_ROOT" $* \ + "NDK_MODULE_PATH=${PLUGIN_ROOT}/publish:${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source" +else + echo "Using prebuilt externals" + set -x + "$NDK_ROOT"/ndk-build -j 4 -C "$APP_ANDROID_ROOT" $* \ + "NDK_MODULE_PATH=${PLUGIN_ROOT}/publish:${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt" +fi diff --git a/plugin/samples/HelloSocial/proj.android/jni/Android.mk b/plugin/samples/HelloSocial/proj.android/jni/Android.mk new file mode 100755 index 0000000000..c7af7ea16e --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/jni/Android.mk @@ -0,0 +1,24 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := game_shared + +LOCAL_MODULE_FILENAME := libgame + +LOCAL_SRC_FILES := hellocpp/main.cpp \ + ../../Classes/AppDelegate.cpp \ + ../../Classes/HelloWorldScene.cpp \ + ../../Classes/MySocialManager.cpp + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes + +LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static \ + PluginTwitterStatic \ + PluginProtocolStatic + +include $(BUILD_SHARED_LIBRARY) + +$(call import-module,cocos2dx) \ +$(call import-module,plugins/twitter/android) \ +$(call import-module,protocols/android) diff --git a/plugin/samples/HelloSocial/proj.android/jni/Application.mk b/plugin/samples/HelloSocial/proj.android/jni/Application.mk new file mode 100755 index 0000000000..d16d4facd2 --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/jni/Application.mk @@ -0,0 +1,2 @@ +APP_STL := gnustl_static +APP_CPPFLAGS += -frtti \ No newline at end of file diff --git a/plugin/samples/HelloSocial/proj.android/jni/hellocpp/main.cpp b/plugin/samples/HelloSocial/proj.android/jni/hellocpp/main.cpp new file mode 100755 index 0000000000..ee1079c797 --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/jni/hellocpp/main.cpp @@ -0,0 +1,47 @@ +#include "AppDelegate.h" +#include "platform/android/jni/JniHelper.h" +#include "PluginJniHelper.h" +#include +#include + +#include "HelloWorldScene.h" + +#define LOG_TAG "main" +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) + +using namespace cocos2d; + +extern "C" +{ + +jint JNI_OnLoad(JavaVM *vm, void *reserved) +{ + JniHelper::setJavaVM(vm); + PluginJniHelper::setJavaVM(vm); + + return JNI_VERSION_1_4; +} + +void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) +{ + if (!CCDirector::sharedDirector()->getOpenGLView()) + { + CCEGLView *view = CCEGLView::sharedOpenGLView(); + view->setFrameSize(w, h); + + AppDelegate *pAppDelegate = new AppDelegate(); + CCApplication::sharedApplication()->run(); + } + else + { + ccDrawInit(); + ccGLInvalidateStateCache(); + + CCShaderCache::sharedShaderCache()->reloadDefaultShaders(); + CCTextureCache::reloadAllTextures(); + CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL); + CCDirector::sharedDirector()->setGLDefaultValues(); + } +} + +} diff --git a/plugin/samples/HelloSocial/proj.android/proguard-project.txt b/plugin/samples/HelloSocial/proj.android/proguard-project.txt new file mode 100755 index 0000000000..b60ae7ea07 --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/plugin/samples/HelloSocial/proj.android/project.properties b/plugin/samples/HelloSocial/proj.android/project.properties new file mode 100755 index 0000000000..859630e465 --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/project.properties @@ -0,0 +1,15 @@ +# 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-8 +android.library.reference.1=../../../../cocos2dx/platform/android/java diff --git a/plugin/samples/HelloSocial/proj.android/res/values/strings.xml b/plugin/samples/HelloSocial/proj.android/res/values/strings.xml new file mode 100755 index 0000000000..320a39b235 --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/res/values/strings.xml @@ -0,0 +1,4 @@ + + + HelloSocial + diff --git a/plugin/samples/HelloSocial/proj.android/src/org/cocos2dx/helloSocial/HelloSocial.java b/plugin/samples/HelloSocial/proj.android/src/org/cocos2dx/helloSocial/HelloSocial.java new file mode 100755 index 0000000000..cc2a90bf8e --- /dev/null +++ b/plugin/samples/HelloSocial/proj.android/src/org/cocos2dx/helloSocial/HelloSocial.java @@ -0,0 +1,43 @@ +/**************************************************************************** +Copyright (c) 2010-2012 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.helloSocial; + +import org.cocos2dx.lib.Cocos2dxActivity; +import org.cocos2dx.lib.Cocos2dxGLSurfaceView; +import org.cocos2dx.plugin.PluginWrapper; + +import android.os.Bundle; + +public class HelloSocial extends Cocos2dxActivity{ + + protected void onCreate(Bundle savedInstanceState){ + super.onCreate(savedInstanceState); + PluginWrapper.init(this); + PluginWrapper.setGLSurfaceView(Cocos2dxGLSurfaceView.getInstance()); + } + + static { + System.loadLibrary("game"); + } +} diff --git a/plugin/tools/android/build_common.xml b/plugin/tools/android/build_common.xml old mode 100644 new mode 100755 diff --git a/plugin/tools/config.sh b/plugin/tools/config.sh index 704df1e450..633aa08126 100755 --- a/plugin/tools/config.sh +++ b/plugin/tools/config.sh @@ -1,7 +1,8 @@ #define plugins array export ALL_PLUGINS=("flurry" "umeng" \ "alipay" "nd91" \ -"admob") +"admob" \ +"twitter") # define the plugin root directory & publish target directory export TARGET_DIR_NAME="publish" diff --git a/plugin/tools/tojs/genbindings-all.sh b/plugin/tools/tojs/genbindings-all.sh index 15aff34a92..9a332771f3 100755 --- a/plugin/tools/tojs/genbindings-all.sh +++ b/plugin/tools/tojs/genbindings-all.sh @@ -1,6 +1,6 @@ #!/bin/bash -PLUGIN_NAME=("alipay" "flurry" "nd91" "umeng") +PLUGIN_NAME=("alipay" "flurry" "nd91" "umeng" "admob") DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # ... use paths relative to current directory