Refactor the implementation of plugin protocols on android.

This commit is contained in:
zhangbin 2013-05-24 17:34:01 +08:00
parent 514f7fe5d5
commit c89bf0f1a8
25 changed files with 523 additions and 554 deletions

View File

@ -22,20 +22,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "PluginManager.h"
#include <map>
#include <string>
#include "PluginFactory.h"
namespace cocos2d { namespace plugin {
typedef struct tagPluginInfo
{
PluginCreator pfnCreator;
PluginProtocol* pInstance;
}PluginInfo;
typedef std::map<std::string, PluginInfo> PluginCreatorMap;
typedef std::pair<std::string, PluginInfo> PluginCreatorPair;
static PluginCreatorMap* s_pCreatorMap = NULL;
static PluginManager* s_pPluginManager = NULL;
PluginManager::PluginManager(void)
@ -44,14 +34,15 @@ PluginManager::PluginManager(void)
PluginManager::~PluginManager()
{
PluginCreatorMap::iterator it = s_pCreatorMap->begin();
for (;it != s_pCreatorMap->end();++it)
std::map<std::string, PluginProtocol*>::iterator it = m_pluginsMap.begin();
for (;it != m_pluginsMap.end();++it)
{
if (it->second.pInstance != NULL) {
delete it->second.pInstance;
it->second.pInstance = NULL;
if (it->second != NULL) {
delete it->second;
it->second = NULL;
}
}
m_pluginsMap.clear();
}
PluginManager* PluginManager::getInstance()
@ -70,6 +61,8 @@ void PluginManager::end()
delete s_pPluginManager;
s_pPluginManager = NULL;
}
PluginFactory::purgeFactory();
}
PluginProtocol* PluginManager::loadPlugin(const char* name)
@ -77,18 +70,16 @@ PluginProtocol* PluginManager::loadPlugin(const char* name)
PluginProtocol* pRet = NULL;
do {
if (name == NULL || strlen(name) == 0) break;
PluginCreatorMap::iterator it = s_pCreatorMap->find(name);
if (it != s_pCreatorMap->end())
std::map<std::string, PluginProtocol*>::iterator it = m_pluginsMap.find(name);
if (it != m_pluginsMap.end())
{
if (it->second.pInstance == NULL) {
it->second.pInstance = it->second.pfnCreator();
if (it->second == NULL) {
it->second = PluginFactory::getInstance()->createPlugin(name);
}
else {
// LOGD("The plugin has been loaded, return the loaded instance directly.");
}
pRet = it->second.pInstance;
pRet = it->second;
}
} while (false);
return pRet;
}
@ -96,28 +87,15 @@ void PluginManager::unloadPlugin(const char* name)
{
do {
if (name == NULL || strlen(name) == 0) break;
PluginCreatorMap::iterator it = s_pCreatorMap->find(name);
if (it != s_pCreatorMap->end())
std::map<std::string, PluginProtocol*>::iterator it = m_pluginsMap.find(name);
if (it != m_pluginsMap.end())
{
if (it->second.pInstance != NULL) {
delete it->second.pInstance;
it->second.pInstance = NULL;
if (it->second != NULL) {
delete it->second;
it->second = NULL;
}
}
} while (false);
}
bool PluginManager::registerPlugin(const char* name, PluginCreator pfnCreator)
{
if (s_pCreatorMap == NULL) {
static PluginCreatorMap s_CreatorMap;
s_pCreatorMap = &s_CreatorMap;
}
PluginInfo info;
info.pfnCreator = pfnCreator;
info.pInstance = NULL;
s_pCreatorMap->insert(PluginCreatorPair(name, info));
return true;
}
}} //namespace cocos2d { namespace plugin {

View File

@ -21,14 +21,31 @@ 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"
#ifndef __CCX_PLUGIN_FACTORY_H__
#define __CCX_PLUGIN_FACTORY_H__
namespace cocos2d { namespace plugin {
RegisterPlugin::RegisterPlugin(const char* name, PluginCreator pfnCreator)
class PluginProtocol;
class PluginManager;
class PluginFactory
{
PluginManager::getInstance()->registerPlugin(name, pfnCreator);
}
public:
virtual ~PluginFactory();
/** Get singleton of PluginFactory */
static PluginFactory* getInstance();
/** Destory the instance of PluginFactory */
static void purgeFactory();
private:
friend class PluginManager;
PluginFactory(void);
/** create the plugin by name */
PluginProtocol* createPlugin(const char* name);
};
}} //namespace cocos2d { namespace plugin {
#endif /* __CCX_PLUGIN_FACTORY_H__ */

View File

@ -25,7 +25,8 @@ THE SOFTWARE.
#define __CCX_PLUGINMANAGER_H__
#include "PluginProtocol.h"
#include "RegisterPlugin.h"
#include <map>
#include <string>
namespace cocos2d { namespace plugin {
@ -42,10 +43,10 @@ public:
PluginProtocol* loadPlugin(const char* name);
/** unload the plugin by name */
void unloadPlugin(const char* name);
private:
friend class RegisterPlugin;
bool registerPlugin(const char* name, PluginCreator pfnCreator);
PluginManager(void);
std::map<std::string, PluginProtocol*> m_pluginsMap;
};
}} //namespace cocos2d { namespace plugin {

View File

@ -24,7 +24,6 @@ THE SOFTWARE.
#ifndef __CCX_IPLUGIN_H__
#define __CCX_IPLUGIN_H__
#include "RegisterPlugin.h"
#include "PluginParam.h"
namespace cocos2d { namespace plugin {
@ -32,31 +31,38 @@ namespace cocos2d { namespace plugin {
/**
The super class for all plugins.
*/
class PluginFactory;
class PluginProtocol
{
public:
virtual ~PluginProtocol() {}
virtual bool init() { return true; }
void setUserData(void* userData) { m_pUserData = userData; }
void* getUserData() { return m_pUserData; }
void callFuncWithParam(const char* funcName, PluginParam* param);
virtual ~PluginProtocol();
/**
@brief plug-in info methods(name, version, SDK version)
*/
virtual const char* getPluginName() = 0;
virtual const char* getPluginVersion() = 0;
inline const char* getPluginName() { return m_pPluginName; }
const char* getPluginVersion();
const char* getSDKVersion();
/**
@brief switch debug plug-in on/off
*/
virtual void setDebugMode(bool bDebug) {}
void setDebugMode(bool bDebug);
/**
* @brief methods for reflections
*/
void callFuncWithParam(const char* funcName, PluginParam* param);
protected:
PluginProtocol() {}
void* m_pUserData;
private:
friend class PluginFactory;
inline void setPluginName(const char* name) {
m_pPluginName = name;
}
const char* m_pPluginName;
};
}} //namespace cocos2d { namespace plugin {

View File

@ -66,6 +66,8 @@ public:
class ProtocolAds : public PluginProtocol
{
public:
ProtocolAds();
virtual ~ProtocolAds();
typedef enum {
kBannerAd = 0,
@ -82,11 +84,6 @@ public:
kPosBottomRight,
} AdsPos;
/**
@brief plugin initialization
*/
virtual bool init();
/**
@brief config the application info
@param devInfo This parameter is the info of aplication,
@ -94,7 +91,7 @@ public:
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void configDeveloperInfo(TAdsDeveloperInfo devInfo);
void configDeveloperInfo(TAdsDeveloperInfo devInfo);
/**
@brief show adview
@ -106,26 +103,20 @@ public:
@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);
void showAds(AdsType type, int sizeEnum = 0, AdsPos pos = kPosCenter);
/**
@brief Hide the adview
@param type The adview type need to hide.
*/
virtual void hideAds(AdsType type);
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.
@param debug If true debug mode enabled, or debug mode disabled.
*/
virtual void setDebugMode(bool debug);
void spendPoints(int points);
/**
@brief set the Ads listener
@ -136,15 +127,6 @@ public:
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();
virtual const char* getPluginName() = 0;
protected:
ProtocolAds();
public:
virtual ~ProtocolAds();
protected:
AdsListener* m_pListener;
};

View File

@ -36,78 +36,59 @@ typedef std::map< std::string, std::string > LogEventParamMap;
class ProtocolAnalytics : public PluginProtocol
{
public:
ProtocolAnalytics();
virtual ~ProtocolAnalytics();
/**
@brief plugin initialization
*/
virtual bool init();
/**
@brief Start a new session.
@param appKey The identity of the application.
*/
virtual void startSession(const char* appKey);
void startSession(const char* appKey);
/**
@brief Stop a session.
@warning This interface only worked on android
*/
virtual void stopSession();
/**
@brief Set whether needs to output logs to console.
@param debug if true debug mode enabled, or debug mode disabled.
@note It must be invoked before calling startSession.
*/
virtual void setDebugMode(bool debug);
void stopSession();
/**
@brief Set the timeout for expiring a session.
@param millis In milliseconds as the unit of time.
@note It must be invoked before calling startSession.
*/
virtual void setSessionContinueMillis(long millis);
void setSessionContinueMillis(long millis);
/**
@brief log an error
@param errorId The identity of error
@param message Extern message for the error
*/
virtual void logError(const char* errorId, const char* message);
void logError(const char* errorId, const char* message);
/**
@brief log an event.
@param eventId The identity of event
@param paramMap Extern parameters of the event, use NULL if not needed.
*/
virtual void logEvent(const char* eventId, LogEventParamMap* paramMap = NULL);
void logEvent(const char* eventId, LogEventParamMap* paramMap = NULL);
/**
@brief Track an event begin.
@param eventId The identity of event
*/
virtual void logTimedEventBegin(const char* eventId);
void logTimedEventBegin(const char* eventId);
/**
@brief Track an event end.
@param eventId The identity of event
*/
virtual void logTimedEventEnd(const char* eventId);
void logTimedEventEnd(const char* eventId);
/**
@brief Whether to catch uncaught exceptions to server.
@warning This interface only worked on android.
*/
virtual void setCaptureUncaughtException(bool enabled);
virtual const char* getPluginVersion() { return "ProtocolAnalytics, v0.1.01 , subclass should override this interface!"; };
virtual const char* getSDKVersion();
virtual const char* getPluginName() = 0;
protected:
ProtocolAnalytics();
public:
virtual ~ProtocolAnalytics();
void setCaptureUncaughtException(bool enabled);
};
}} // namespace cocos2d { namespace plugin {

View File

@ -50,11 +50,8 @@ public:
class ProtocolIAP : public PluginProtocol
{
public:
/**
@brief plugin initialization
*/
virtual bool init();
ProtocolIAP();
virtual ~ProtocolIAP();
/**
@brief config the developer info
@ -63,7 +60,7 @@ public:
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void configDeveloperInfo(TIAPDeveloperInfo devInfo);
void configDeveloperInfo(TIAPDeveloperInfo devInfo);
/**
@brief pay for product
@ -74,13 +71,7 @@ public:
@warning For different plugin, the parameter should have other keys to pay.
Look at the manual of plugins.
*/
virtual void payForProduct(TProductInfo 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);
void payForProduct(TProductInfo info);
/**
@breif set the result listener
@ -94,15 +85,6 @@ public:
*/
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();
virtual const char* getPluginName() = 0;
protected:
ProtocolIAP();
public:
virtual ~ProtocolIAP();
protected:
static bool m_bPaying;

View File

@ -50,11 +50,8 @@ public:
class ProtocolSocial : public PluginProtocol
{
public:
/**
@brief plugin initialization
*/
virtual bool init();
ProtocolSocial();
virtual ~ProtocolSocial();
/**
@brief config the social developer info
@ -63,7 +60,7 @@ public:
@warning Must invoke this interface before other interfaces.
And invoked only once.
*/
virtual void configDeveloperInfo(TSocialDeveloperInfo devInfo);
void configDeveloperInfo(TSocialDeveloperInfo devInfo);
/**
@brief share information
@ -73,13 +70,7 @@ public:
@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);
void share(TShareInfo info);
/**
@breif set the result listener
@ -93,14 +84,8 @@ public:
*/
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();
const char* getPluginVersion() { return "ProtocolSocial, v0.1.0, subclass should override this interface!"; };
const char* getSDKVersion();
protected:
ShareResultListener* m_pListener;

View File

@ -0,0 +1,138 @@
/****************************************************************************
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 "PluginFactory.h"
#include "PluginUtils.h"
#include "PluginJniHelper.h"
#include "ProtocolAds.h"
#include "ProtocolAnalytics.h"
#include "ProtocolIAP.h"
#include "ProtocolSocial.h"
namespace cocos2d { namespace plugin {
enum {
kPluginAds = 1,
kPluginAnalytics,
kPluginIAP,
kPluginSocial,
};
#define ANDROID_PLUGIN_TYPE_FIELD "PluginType"
#define ANDROID_PLUGIN_PACKAGE_PREFIX "org/cocos2dx/plugins/"
#define BREAK_IF(cond) if(cond) break
static PluginFactory* s_pFactory = NULL;
PluginFactory::PluginFactory()
{
}
PluginFactory::~PluginFactory()
{
}
PluginFactory* PluginFactory::getInstance()
{
if (NULL == s_pFactory)
{
s_pFactory = new PluginFactory();
}
return s_pFactory;
}
void PluginFactory::purgeFactory()
{
if (NULL != s_pFactory)
{
delete s_pFactory;
s_pFactory = NULL;
}
}
/** create the plugin by name */
PluginProtocol* PluginFactory::createPlugin(const char* name)
{
PluginProtocol* pRet = NULL;
do
{
if (name == NULL || strlen(name) == 0) break;
std::string jClassName = ANDROID_PLUGIN_PACKAGE_PREFIX;
jClassName.append(name);
PluginUtils::outputLog("PluginFactory", "Java class name of plugin %s is : %s", name, jClassName.c_str());
PluginJniMethodInfo t;
if (! PluginJniHelper::getStaticMethodInfo(t
, "org/cocos2dx/plugin/PluginWrapper"
, "initPlugin"
, "(Ljava/lang/String;)Ljava/lang/Object;"))
{
break;
}
jstring clsName = t.env->NewStringUTF(jClassName.c_str());
jobject jObj = t.env->CallStaticObjectMethod(t.classID, t.methodID, clsName);
t.env->DeleteLocalRef(clsName);
t.env->DeleteLocalRef(t.classID);
BREAK_IF(jObj == NULL);
jclass jcls = t.env->FindClass(jClassName.c_str());
jfieldID fid_Type = t.env->GetFieldID(jcls, ANDROID_PLUGIN_TYPE_FIELD, "I");
BREAK_IF(fid_Type == NULL);
int curType = t.env->GetIntField(jObj, fid_Type);
PluginUtils::outputLog("PluginFactory", "The type of plugin %s is : %d", name, curType);
switch (curType)
{
case kPluginAds:
pRet = new ProtocolAds();
break;
case kPluginAnalytics:
pRet = new ProtocolAnalytics();
break;
case kPluginIAP:
pRet = new ProtocolIAP();
break;
case kPluginSocial:
pRet = new ProtocolSocial();
break;
default:
break;
}
if (pRet != NULL)
{
pRet->setPluginName(name);
PluginUtils::initJavaPlugin(pRet, jObj, jClassName.c_str());
}
} while(0);
return pRet;
}
}} //namespace cocos2d { namespace plugin {

View File

@ -26,6 +26,50 @@ THE SOFTWARE.
namespace cocos2d { namespace plugin {
PluginProtocol::~PluginProtocol()
{
PluginUtils::erasePluginJavaData(this);
}
const char* PluginProtocol::getPluginVersion()
{
std::string verName;
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
PluginJniMethodInfo t;
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "getPluginVersion"
, "()Ljava/lang/String;"))
{
jstring ret = (jstring)(t.env->CallObjectMethod(pData->jobj, t.methodID));
verName = PluginJniHelper::jstring2string(ret);
}
return verName.c_str();
}
const char* PluginProtocol::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 PluginProtocol::setDebugMode(bool isDebugMode)
{
PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", isDebugMode);
}
void PluginProtocol::callFuncWithParam(const char* funcName, PluginParam* param)
{
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);

View File

@ -31,23 +31,6 @@ namespace cocos2d { namespace plugin {
#define JAVAVM cocos2d::PluginJniHelper::getJavaVM()
static cocos2d::plugin::PluginProtocol* s_pPluginInstance = NULL;
extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_PluginWrapper_nativeInitPlugin(JNIEnv* env, jobject thiz, jobject obj, jstring className)
{
if (s_pPluginInstance != NULL) {
cocos2d::plugin::PluginJavaData* pUserData = new cocos2d::plugin::PluginJavaData();
pUserData->jobj = env->NewGlobalRef(obj);
pUserData->jclassName = cocos2d::PluginJniHelper::jstring2string(className);
cocos2d::plugin::PluginUtils::setPluginJavaData(s_pPluginInstance, pUserData);
s_pPluginInstance = NULL;
}
}
}
jobject PluginUtils::createJavaMapObject(PluginJniMethodInfo&t, std::map<std::string, std::string>* paramMap)
{
jclass class_Hashtable = t.env->FindClass("java/util/Hashtable");
@ -65,24 +48,12 @@ jobject PluginUtils::createJavaMapObject(PluginJniMethodInfo&t, std::map<std::st
return obj_Map;
}
bool PluginUtils::initJavaPlugin(PluginProtocol* pPlugin, const char* className)
void PluginUtils::initJavaPlugin(PluginProtocol* pPlugin, jobject jObj, const char* className)
{
return_val_if_fails(className != NULL && strlen(className) > 0, false);
bool bRet = false;
PluginJniMethodInfo t;
s_pPluginInstance = pPlugin;
if (PluginJniHelper::getStaticMethodInfo(t
, "org/cocos2dx/plugin/PluginWrapper"
, "initPlugin"
, "(Ljava/lang/String;)Z"))
{
jstring jclassName = t.env->NewStringUTF(className);
bRet = (bool)t.env->CallStaticBooleanMethod(t.classID, t.methodID, jclassName);
t.env->DeleteLocalRef(jclassName);
t.env->DeleteLocalRef(t.classID);
}
return bRet;
cocos2d::plugin::PluginJavaData* pUserData = new cocos2d::plugin::PluginJavaData();
pUserData->jobj = PluginUtils::getEnv()->NewGlobalRef(jObj);
pUserData->jclassName = className;
cocos2d::plugin::PluginUtils::setPluginJavaData(pPlugin, pUserData);
}
JNIEnv* PluginUtils::getEnv()

View File

@ -25,7 +25,6 @@ THE SOFTWARE.
#define __PLUGIN_UTILS_H__
#include "PluginJniHelper.h"
#include <android/log.h>
#include "PluginJavaData.h"
#include "PluginProtocol.h"
#include <map>
@ -40,7 +39,7 @@ class PluginUtils
{
public:
static jobject createJavaMapObject(PluginJniMethodInfo&t, std::map<std::string, std::string>* paramMap);
static bool initJavaPlugin(PluginProtocol* pPlugin, const char* className);
static void initJavaPlugin(PluginProtocol* pPlugin, jobject jObj, const char* className);
static JNIEnv* getEnv();
static PluginJavaData* getPluginJavaData(PluginProtocol* pKeyObj);

View File

@ -27,13 +27,6 @@ THE SOFTWARE.
#include "PluginUtils.h"
#include "PluginJavaData.h"
#if 1
#define LOG_TAG "ProtocolAds"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#else
#define LOGD(...)
#endif
namespace cocos2d { namespace plugin {
extern "C" {
@ -41,10 +34,10 @@ extern "C" {
std::string strMsg = PluginJniHelper::jstring2string(msg);
std::string strClassName = PluginJniHelper::jstring2string(className);
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
LOGD("nativeOnAdsResult(), Get plugin ptr : %p", pPlugin);
PluginUtils::outputLog("ProtocolAds", "nativeOnAdsResult(), Get plugin ptr : %p", pPlugin);
if (pPlugin != NULL)
{
LOGD("nativeOnAdsResult(), Get plugin name : %s", pPlugin->getPluginName());
PluginUtils::outputLog("ProtocolAds", "nativeOnAdsResult(), Get plugin name : %s", pPlugin->getPluginName());
ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin);
if (pAds != NULL)
{
@ -56,10 +49,10 @@ extern "C" {
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_InterfaceAds_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jstring className, jint points) {
std::string strClassName = PluginJniHelper::jstring2string(className);
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
LOGD("nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin);
PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin);
if (pPlugin != NULL)
{
LOGD("nativeOnPlayerGetPoints(), Get plugin name : %s", pPlugin->getPluginName());
PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin name : %s", pPlugin->getPluginName());
ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin);
if (pAds != NULL)
{
@ -76,19 +69,13 @@ ProtocolAds::ProtocolAds()
ProtocolAds::~ProtocolAds()
{
PluginUtils::erasePluginJavaData(this);
}
bool ProtocolAds::init()
{
return true;
}
void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo)
{
if (devInfo.empty())
{
LOGD("The application info is empty!");
PluginUtils::outputLog("ProtocolAds", "The application info is empty!");
return;
}
else
@ -116,7 +103,7 @@ void ProtocolAds::showAds(AdsType type, int sizeEnum, AdsPos pos)
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
PluginJniMethodInfo t;
LOGD("Class name : %s", pData->jclassName.c_str());
PluginUtils::outputLog("ProtocolAds", "Class name : %s", pData->jclassName.c_str());
if (PluginJniHelper::getMethodInfo(t
, pData->jclassName.c_str()
, "showAds"
@ -137,28 +124,6 @@ void ProtocolAds::spendPoints(int points)
PluginUtils::callJavaFunctionWithName_oneParam(this, "spendPoints", "(I)V", points);
}
const char* ProtocolAds::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 ProtocolAds::setDebugMode(bool debug)
{
PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", debug);
}
void ProtocolAds::setAdsListener(AdsListener* pListener)
{
m_pListener = pListener;
@ -166,7 +131,7 @@ void ProtocolAds::setAdsListener(AdsListener* pListener)
void ProtocolAds::onAdsResult(AdsResultCode code, const char* msg)
{
LOGD("ProtocolAds::adsResult invoked!");
PluginUtils::outputLog("ProtocolAds", "ProtocolAds::adsResult invoked!");
if (m_pListener != NULL)
{
m_pListener->onAdsResult(code, msg);
@ -175,7 +140,7 @@ void ProtocolAds::onAdsResult(AdsResultCode code, const char* msg)
void ProtocolAds::onPlayerGetPoints(int points)
{
LOGD("ProtocolAds::onPlayerGetPoints invoked!");
PluginUtils::outputLog("ProtocolAds", "ProtocolAds::onPlayerGetPoints invoked!");
if (m_pListener != NULL)
{
m_pListener->onPlayerGetPoints(this, points);

View File

@ -27,13 +27,6 @@ THE SOFTWARE.
#include "PluginUtils.h"
#include "PluginJavaData.h"
#if 1
#define LOG_TAG "ProtocolAnalytics"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#else
#define LOGD(...)
#endif
namespace cocos2d { namespace plugin {
static void callJavaFunctionWithName_string_map(ProtocolAnalytics* thiz, const char* funcName, const char* keyParam, LogEventParamMap* paramMap)
@ -80,12 +73,6 @@ ProtocolAnalytics::ProtocolAnalytics()
ProtocolAnalytics::~ProtocolAnalytics()
{
PluginUtils::erasePluginJavaData(this);
}
bool ProtocolAnalytics::init()
{
return true;
}
void ProtocolAnalytics::startSession(const char* appKey)
@ -117,11 +104,6 @@ void ProtocolAnalytics::setCaptureUncaughtException(bool isEnabled)
PluginUtils::callJavaFunctionWithName_oneParam(this, "setCaptureUncaughtException", "(Z)V", isEnabled);
}
void ProtocolAnalytics::setDebugMode(bool isDebugMode)
{
PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", isDebugMode);
}
void ProtocolAnalytics::logError(const char* errorId, const char* message)
{
return_if_fails(errorId != NULL && strlen(errorId) > 0);
@ -144,23 +126,6 @@ void ProtocolAnalytics::logError(const char* errorId, const char* message)
}
}
const char* ProtocolAnalytics::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 ProtocolAnalytics::logEvent(const char* eventId, LogEventParamMap* pParams/* = NULL */)
{
callJavaFunctionWithName_string_map(this, "logEvent", eventId, pParams);

View File

@ -27,13 +27,6 @@ THE SOFTWARE.
#include "PluginUtils.h"
#include "PluginJavaData.h"
#if 1
#define LOG_TAG "ProtocolIAP"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#else
#define LOGD(...)
#endif
namespace cocos2d { namespace plugin {
extern "C" {
@ -42,10 +35,10 @@ extern "C" {
std::string strMsg = PluginJniHelper::jstring2string(msg);
std::string strClassName = PluginJniHelper::jstring2string(className);
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
LOGD("nativeOnPayResult(), Get plugin ptr : %p", pPlugin);
PluginUtils::outputLog("ProtocolIAP", "nativeOnPayResult(), Get plugin ptr : %p", pPlugin);
if (pPlugin != NULL)
{
LOGD("nativeOnPayResult(), Get plugin name : %s", pPlugin->getPluginName());
PluginUtils::outputLog("ProtocolIAP", "nativeOnPayResult(), Get plugin name : %s", pPlugin->getPluginName());
ProtocolIAP* pIAP = dynamic_cast<ProtocolIAP*>(pPlugin);
if (pIAP != NULL)
{
@ -64,19 +57,13 @@ ProtocolIAP::ProtocolIAP()
ProtocolIAP::~ProtocolIAP()
{
PluginUtils::erasePluginJavaData(this);
}
bool ProtocolIAP::init()
{
return true;
}
void ProtocolIAP::configDeveloperInfo(TIAPDeveloperInfo devInfo)
{
if (devInfo.empty())
{
LOGD("The developer info is empty!");
PluginUtils::outputLog("ProtocolIAP", "The developer info is empty!");
return;
}
else
@ -103,7 +90,7 @@ void ProtocolIAP::payForProduct(TProductInfo info)
{
if (m_bPaying)
{
LOGD("Now is paying");
PluginUtils::outputLog("ProtocolIAP", "Now is paying");
return;
}
@ -113,7 +100,7 @@ void ProtocolIAP::payForProduct(TProductInfo info)
{
onPayResult(kPayFail, "Product info error");
}
LOGD("The product info is empty!");
PluginUtils::outputLog("ProtocolIAP", "The product info is empty!");
return;
}
else
@ -153,32 +140,10 @@ void ProtocolIAP::onPayResult(PayResultCode ret, const char* msg)
}
else
{
LOGD("Result listener is null!");
PluginUtils::outputLog("ProtocolIAP", "Result listener is null!");
}
m_curInfo.clear();
LOGD("Pay result is : %d(%s)", (int) ret, msg);
}
const char* ProtocolIAP::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 ProtocolIAP::setDebugMode(bool debug)
{
PluginUtils::callJavaFunctionWithName_oneParam(this, "setDebugMode", "(Z)V", debug);
PluginUtils::outputLog("ProtocolIAP", "Pay result is : %d(%s)", (int) ret, msg);
}
}} // namespace cocos2d { namespace plugin {

View File

@ -27,13 +27,6 @@ THE SOFTWARE.
#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" {
@ -42,10 +35,10 @@ extern "C" {
std::string strMsg = PluginJniHelper::jstring2string(msg);
std::string strClassName = PluginJniHelper::jstring2string(className);
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
LOGD("nativeOnShareResult(), Get plugin ptr : %p", pPlugin);
PluginUtils::outputLog("ProtocolSocial", "nativeOnShareResult(), Get plugin ptr : %p", pPlugin);
if (pPlugin != NULL)
{
LOGD("nativeOnShareResult(), Get plugin name : %s", pPlugin->getPluginName());
PluginUtils::outputLog("ProtocolSocial", "nativeOnShareResult(), Get plugin name : %s", pPlugin->getPluginName());
ProtocolSocial* pSocial = dynamic_cast<ProtocolSocial*>(pPlugin);
if (pSocial != NULL)
{
@ -62,19 +55,13 @@ ProtocolSocial::ProtocolSocial()
ProtocolSocial::~ProtocolSocial()
{
PluginUtils::erasePluginJavaData(this);
}
bool ProtocolSocial::init()
{
return true;
}
void ProtocolSocial::configDeveloperInfo(TSocialDeveloperInfo devInfo)
{
if (devInfo.empty())
{
LOGD("The developer info is empty!");
PluginUtils::outputLog("ProtocolSocial", "The developer info is empty!");
return;
}
else
@ -105,7 +92,7 @@ void ProtocolSocial::share(TShareInfo info)
{
onShareResult(kShareFail, "Share info error");
}
LOGD("The Share info is empty!");
PluginUtils::outputLog("ProtocolSocial", "The Share info is empty!");
return;
}
else
@ -141,31 +128,9 @@ void ProtocolSocial::onShareResult(ShareResultCode ret, const char* msg)
}
else
{
LOGD("Result listener is null!");
PluginUtils::outputLog("ProtocolSocial", "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_oneParam(this, "setDebugMode", "(Z)V", debug);
PluginUtils::outputLog("ProtocolSocial", "Share result is : %d(%s)", (int) ret, msg);
}
}} // namespace cocos2d { namespace plugin {

View File

@ -8,6 +8,7 @@ LOCAL_MODULE_FILENAME := libPluginProtocolStatic
LOCAL_SRC_FILES :=\
$(addprefix ../../platform/android/, \
PluginFactory.cpp \
PluginJniHelper.cpp \
PluginUtils.cpp \
ProtocolAnalytics.cpp \
@ -16,7 +17,6 @@ $(addprefix ../../platform/android/, \
ProtocolSocial.cpp \
) \
../../PluginManager.cpp \
../../RegisterPlugin.cpp \
../../PluginParam.cpp
LOCAL_CFLAGS := -Wno-psabi

View File

@ -0,0 +1,116 @@
/****************************************************************************
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.view.Gravity;
import android.view.View;
import android.view.WindowManager;
public class AdsWrapper {
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 static void addAdView(WindowManager mWm, View adView, int pos) {
WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams();
mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
mLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
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;
case POS_TOP_LEFT:
mLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
break;
case POS_TOP_RIGHT:
mLayoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
break;
case POS_BOTTOM:
mLayoutParams.gravity = Gravity.BOTTOM;
break;
case POS_BOTTOM_LEFT:
mLayoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
break;
case POS_BOTTOM_RIGHT:
mLayoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
break;
default:
break;
}
mWm.addView(adView, mLayoutParams);
}
public static void onAdsResult(InterfaceAds adapter, int code, String msg) {
final int curCode = code;
final String curMsg = msg;
final InterfaceAds curObj = adapter;
PluginWrapper.runOnGLThread(new Runnable(){
@Override
public void run() {
String name = curObj.getClass().getName();
name = name.replace('.', '/');
AdsWrapper.nativeOnAdsResult(name, curCode, curMsg);
}
});
}
private native static void nativeOnAdsResult(String className, int code, String msg);
public static void onPlayerGetPoints(InterfaceAds adapter, int points) {
final int curPoints = points;
final InterfaceAds curAdapter = adapter;
PluginWrapper.runOnGLThread(new Runnable(){
@Override
public void run() {
String name = curAdapter.getClass().getName();
name = name.replace('.', '/');
AdsWrapper.nativeOnPlayerGetPoints(name, curPoints);
}
});
}
private native static void nativeOnPlayerGetPoints(String className, int points);
}

View File

@ -21,44 +21,28 @@ 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__
package org.cocos2dx.plugin;
namespace cocos2d { namespace plugin {
import java.util.Hashtable;
class PluginProtocol;
public class IAPWrapper {
public static final int PAYRESULT_SUCCESS = 0;
public static final int PAYRESULT_FAIL = 1;
public static final int PAYRESULT_CANCEL = 2;
public static final int PAYRESULT_TIMEOUT = 3;
typedef PluginProtocol* (*PluginCreator)();
/**
@brief RegisterPlugin class is only for associating plugin name with plugin creator.
Plugin developers don't need to use this class directly.
Using the macros 'PLUGIN_REGISTER_DECL' and 'PLUGIN_REGISTER_IMPL' instead.
*/
class RegisterPlugin
{
public:
RegisterPlugin(const char* name, PluginCreator pfnCreator);
};
#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) \
RegisterPlugin type::s_registerPlugin(#type, type::createPlugin); \
PluginProtocol* type::createPlugin() { \
type* pRet = new type(); \
if (pRet) { \
if (!pRet->init()) { \
delete pRet; pRet = NULL; \
} \
} \
return pRet; \
public static void onPayResult(InterfaceIAP obj, int ret, String msg) {
final int curRet = ret;
final String curMsg = msg;
final InterfaceIAP curObj = obj;
PluginWrapper.runOnGLThread(new Runnable() {
@Override
public void run() {
String name = curObj.getClass().getName();
name = name.replace('.', '/');
nativeOnPayResult(name, curRet, curMsg);
}
});
}
private static native void nativeOnPayResult(String className, int ret, String msg);
}
}} //namespace cocos2d { namespace plugin {
#endif /* __CCX_REGISTERPLUGIN_H__ */

View File

@ -25,101 +25,15 @@ package org.cocos2dx.plugin;
import java.util.Hashtable;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
public interface InterfaceAds {
public class InterfaceAds {
public final int PluginType = 1;
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 configDeveloperInfo(Hashtable<String, String> devInfo);
public void showAds(int type, int sizeEnum, int pos);
public void hideAds(int type);
public void spendPoints(int points);
public void setDebugMode(boolean debug);
public String getSDKVersion();
}
public static void addAdView(WindowManager mWm, View adView, int pos) {
WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams();
mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
mLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
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;
case POS_TOP_LEFT:
mLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
break;
case POS_TOP_RIGHT:
mLayoutParams.gravity = Gravity.TOP | Gravity.RIGHT;
break;
case POS_BOTTOM:
mLayoutParams.gravity = Gravity.BOTTOM;
break;
case POS_BOTTOM_LEFT:
mLayoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
break;
case POS_BOTTOM_RIGHT:
mLayoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
break;
default:
break;
}
mWm.addView(adView, mLayoutParams);
}
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() {
String name = curObj.getClass().getName();
name = name.replace('.', '/');
InterfaceAds.nativeOnAdsResult(name, curCode, curMsg);
}
});
}
private native static void nativeOnAdsResult(String className, 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() {
String name = curAdapter.getClass().getName();
name = name.replace('.', '/');
InterfaceAds.nativeOnPlayerGetPoints(name, curPoints);
}
});
}
private native static void nativeOnPlayerGetPoints(String className, int points);
public void configDeveloperInfo(Hashtable<String, String> devInfo);
public void showAds(int type, int sizeEnum, int pos);
public void hideAds(int type);
public void spendPoints(int points);
public void setDebugMode(boolean debug);
public String getSDKVersion();
public String getPluginVersion();
}

View File

@ -27,6 +27,8 @@ import java.util.Hashtable;
public interface InterfaceAnalytics {
public final int PluginType = 2;
public void startSession(String appKey);
public void stopSession();
public void setSessionContinueMillis(int millis);
@ -38,4 +40,5 @@ public interface InterfaceAnalytics {
public void logTimedEventBegin(String eventId);
public void logTimedEventEnd(String eventId);
public String getSDKVersion();
public String getPluginVersion();
}

View File

@ -25,31 +25,12 @@ package org.cocos2dx.plugin;
import java.util.Hashtable;
public class InterfaceIAP {
public static final int PAYRESULT_SUCCESS = 0;
public static final int PAYRESULT_FAIL = 1;
public static final int PAYRESULT_CANCEL = 2;
public static final int PAYRESULT_TIMEOUT = 3;
public interface InterfaceIAP {
public final int PluginType = 3;
public interface IAPAdapter {
public void configDeveloperInfo(Hashtable<String, String> cpInfo);
public void payForProduct(Hashtable<String, String> cpInfo);
public void setDebugMode(boolean debug);
public String getSDKVersion();
}
public static void 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() {
String name = curObj.getClass().getName();
name = name.replace('.', '/');
nativeOnPayResult(name, curRet, curMsg);
}
});
}
private static native void nativeOnPayResult(String className, int ret, String msg);
public void configDeveloperInfo(Hashtable<String, String> cpInfo);
public void payForProduct(Hashtable<String, String> cpInfo);
public void setDebugMode(boolean debug);
public String getSDKVersion();
public String getPluginVersion();
}

View File

@ -25,31 +25,12 @@ 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 InterfaceSocial {
public final int PluginType = 4;
public interface ShareAdapter {
public void configDeveloperInfo(Hashtable<String, String> cpInfo);
public void share(Hashtable<String, String> cpInfo);
public void setDebugMode(boolean debug);
public String getSDKVersion();
}
public static void onShareResult(ShareAdapter obj, int ret, String msg) {
final int curRet = ret;
final String curMsg = msg;
final ShareAdapter curAdapter = obj;
PluginWrapper.runOnGLThread(new Runnable() {
@Override
public void run() {
String name = curAdapter.getClass().getName();
name = name.replace('.', '/');
nativeOnShareResult(name, curRet, curMsg);
}
});
}
private static native void nativeOnShareResult(String className, int ret, String msg);
public void configDeveloperInfo(Hashtable<String, String> cpInfo);
public void share(Hashtable<String, String> cpInfo);
public void setDebugMode(boolean debug);
public String getSDKVersion();
public String getPluginVersion();
}

View File

@ -30,9 +30,7 @@ import android.util.Log;
public class PluginWrapper {
public static native void nativeInitPlugin(Object instance, String className);
protected static Context sContext = null;
protected static GLSurfaceView sGLSurfaceView = null;
protected static Handler sMainThreadHandler = null;
@ -50,33 +48,33 @@ public class PluginWrapper {
sGLSurfaceView = value;
}
protected static boolean initPlugin(String classFullName)
protected static Object initPlugin(String classFullName)
{
Log.i(TAG, "class name : ----" + classFullName + "----");
Class<?> c = null;
try {
c = Class.forName(classFullName);
try {
String fullName = classFullName.replace('/', '.');
c = Class.forName(fullName);
} catch (ClassNotFoundException e) {
Log.e(TAG, "Class " + classFullName + " not found.");
e.printStackTrace();
return false;
}
return null;
}
try {
Context ctx = getContext();
if (ctx != null) {
Object o = c.getDeclaredConstructor(Context.class).newInstance(ctx);
PluginWrapper.nativeInitPlugin(o, classFullName.replace('.', '/'));
return true;
return o;
} else {
Log.e(TAG, "Plugin " + classFullName + " wasn't initialized.");
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
return null;
}
public static Context getContext() {
return sContext;
}

View File

@ -0,0 +1,48 @@
/****************************************************************************
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 SocialWrapper {
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 static void onShareResult(InterfaceSocial obj, int ret, String msg) {
final int curRet = ret;
final String curMsg = msg;
final InterfaceSocial curAdapter = obj;
PluginWrapper.runOnGLThread(new Runnable() {
@Override
public void run() {
String name = curAdapter.getClass().getName();
name = name.replace('.', '/');
nativeOnShareResult(name, curRet, curMsg);
}
});
}
private static native void nativeOnShareResult(String className, int ret, String msg);
}