2013-04-25 17:33:42 +08:00
|
|
|
/****************************************************************************
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2013-04-22 10:38:14 +08:00
|
|
|
#include "ProtocolAds.h"
|
|
|
|
#include "PluginJniHelper.h"
|
|
|
|
#include <android/log.h>
|
|
|
|
#include "PluginUtils.h"
|
|
|
|
#include "PluginJavaData.h"
|
|
|
|
|
|
|
|
namespace cocos2d { namespace plugin {
|
|
|
|
|
|
|
|
extern "C" {
|
2013-05-27 13:58:31 +08:00
|
|
|
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_AdsWrapper_nativeOnAdsResult(JNIEnv* env, jobject thiz, jstring className, jint ret, jstring msg) {
|
2013-04-22 10:38:14 +08:00
|
|
|
std::string strMsg = PluginJniHelper::jstring2string(msg);
|
2013-05-16 11:45:46 +08:00
|
|
|
std::string strClassName = PluginJniHelper::jstring2string(className);
|
|
|
|
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
|
2013-05-24 17:34:01 +08:00
|
|
|
PluginUtils::outputLog("ProtocolAds", "nativeOnAdsResult(), Get plugin ptr : %p", pPlugin);
|
2013-04-26 17:16:06 +08:00
|
|
|
if (pPlugin != NULL)
|
|
|
|
{
|
2013-05-24 17:34:01 +08:00
|
|
|
PluginUtils::outputLog("ProtocolAds", "nativeOnAdsResult(), Get plugin name : %s", pPlugin->getPluginName());
|
2013-04-26 17:16:06 +08:00
|
|
|
ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin);
|
|
|
|
if (pAds != NULL)
|
|
|
|
{
|
2013-07-26 15:51:06 +08:00
|
|
|
AdsListener* listener = pAds->getAdsListener();
|
|
|
|
if (listener)
|
|
|
|
{
|
|
|
|
listener->onAdsResult((AdsResultCode) ret, strMsg.c_str());
|
|
|
|
}
|
2013-04-26 17:16:06 +08:00
|
|
|
}
|
|
|
|
}
|
2013-04-22 10:38:14 +08:00
|
|
|
}
|
|
|
|
|
2013-05-27 13:58:31 +08:00
|
|
|
JNIEXPORT void JNICALL Java_org_cocos2dx_plugin_AdsWrapper_nativeOnPlayerGetPoints(JNIEnv* env, jobject thiz, jstring className, jint points) {
|
2013-05-16 11:45:46 +08:00
|
|
|
std::string strClassName = PluginJniHelper::jstring2string(className);
|
|
|
|
PluginProtocol* pPlugin = PluginUtils::getPluginPtr(strClassName);
|
2013-05-24 17:34:01 +08:00
|
|
|
PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin ptr : %p", pPlugin);
|
2013-04-26 17:16:06 +08:00
|
|
|
if (pPlugin != NULL)
|
|
|
|
{
|
2013-05-24 17:34:01 +08:00
|
|
|
PluginUtils::outputLog("ProtocolAds", "nativeOnPlayerGetPoints(), Get plugin name : %s", pPlugin->getPluginName());
|
2013-04-26 17:16:06 +08:00
|
|
|
ProtocolAds* pAds = dynamic_cast<ProtocolAds*>(pPlugin);
|
|
|
|
if (pAds != NULL)
|
|
|
|
{
|
2013-07-26 15:51:06 +08:00
|
|
|
AdsListener* listener = pAds->getAdsListener();
|
|
|
|
if (listener)
|
|
|
|
{
|
|
|
|
listener->onPlayerGetPoints(pAds, points);
|
|
|
|
}
|
2013-04-26 17:16:06 +08:00
|
|
|
}
|
|
|
|
}
|
2013-04-22 10:38:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ProtocolAds::ProtocolAds()
|
2013-06-20 16:31:12 +08:00
|
|
|
: _listener(NULL)
|
2013-04-22 10:38:14 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ProtocolAds::~ProtocolAds()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-26 17:16:06 +08:00
|
|
|
void ProtocolAds::configDeveloperInfo(TAdsDeveloperInfo devInfo)
|
2013-04-22 10:38:14 +08:00
|
|
|
{
|
2013-04-26 17:16:06 +08:00
|
|
|
if (devInfo.empty())
|
2013-04-22 10:38:14 +08:00
|
|
|
{
|
2013-05-24 17:34:01 +08:00
|
|
|
PluginUtils::outputLog("ProtocolAds", "The application info is empty!");
|
2013-04-22 10:38:14 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
|
|
PluginJniMethodInfo t;
|
|
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
|
|
, pData->jclassName.c_str()
|
2013-04-26 17:16:06 +08:00
|
|
|
, "configDeveloperInfo"
|
2013-04-22 10:38:14 +08:00
|
|
|
, "(Ljava/util/Hashtable;)V"))
|
|
|
|
{
|
|
|
|
// generate the hashtable from map
|
2013-05-28 18:10:09 +08:00
|
|
|
jobject obj_Map = PluginUtils::createJavaMapObject(&devInfo);
|
2013-04-22 10:38:14 +08:00
|
|
|
|
|
|
|
// invoke java method
|
|
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map);
|
|
|
|
t.env->DeleteLocalRef(obj_Map);
|
|
|
|
t.env->DeleteLocalRef(t.classID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:51:06 +08:00
|
|
|
void ProtocolAds::showAds(TAdsInfo info, AdsPos pos)
|
2013-04-22 10:38:14 +08:00
|
|
|
{
|
|
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
|
|
PluginJniMethodInfo t;
|
|
|
|
|
2013-05-24 17:34:01 +08:00
|
|
|
PluginUtils::outputLog("ProtocolAds", "Class name : %s", pData->jclassName.c_str());
|
2013-04-22 10:38:14 +08:00
|
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
|
|
, pData->jclassName.c_str()
|
2013-04-26 17:16:06 +08:00
|
|
|
, "showAds"
|
2013-07-26 15:51:06 +08:00
|
|
|
, "(Ljava/util/Hashtable;I)V"))
|
2013-04-22 10:38:14 +08:00
|
|
|
{
|
2013-07-26 15:51:06 +08:00
|
|
|
jobject obj_Map = PluginUtils::createJavaMapObject(&info);
|
|
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map, pos);
|
|
|
|
t.env->DeleteLocalRef(obj_Map);
|
2013-04-22 10:38:14 +08:00
|
|
|
t.env->DeleteLocalRef(t.classID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:51:06 +08:00
|
|
|
void ProtocolAds::hideAds(TAdsInfo info)
|
2013-04-22 10:38:14 +08:00
|
|
|
{
|
2013-07-26 15:51:06 +08:00
|
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
|
|
PluginJniMethodInfo t;
|
|
|
|
|
|
|
|
PluginUtils::outputLog("ProtocolAds", "Class name : %s", pData->jclassName.c_str());
|
|
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
|
|
, pData->jclassName.c_str()
|
|
|
|
, "hideAds"
|
|
|
|
, "(Ljava/util/Hashtable;)V"))
|
|
|
|
{
|
|
|
|
jobject obj_Map = PluginUtils::createJavaMapObject(&info);
|
|
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID, obj_Map);
|
|
|
|
t.env->DeleteLocalRef(obj_Map);
|
|
|
|
t.env->DeleteLocalRef(t.classID);
|
|
|
|
}
|
2013-04-26 17:16:06 +08:00
|
|
|
}
|
|
|
|
|
2013-06-18 15:53:56 +08:00
|
|
|
void ProtocolAds::queryPoints()
|
|
|
|
{
|
|
|
|
PluginUtils::callJavaFunctionWithName(this, "queryPoints");
|
|
|
|
}
|
|
|
|
|
2013-04-26 17:16:06 +08:00
|
|
|
void ProtocolAds::spendPoints(int points)
|
|
|
|
{
|
2013-05-23 17:57:55 +08:00
|
|
|
PluginUtils::callJavaFunctionWithName_oneParam(this, "spendPoints", "(I)V", points);
|
2013-04-22 10:38:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}} // namespace cocos2d { namespace plugin {
|