mirror of https://github.com/axmolengine/axmol.git
247 lines
7.0 KiB
C++
247 lines
7.0 KiB
C++
/****************************************************************************
|
|
Copyright (c) 2012-2013 cocos2d-x.org
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
****************************************************************************/
|
|
#include "AnalyticsFlurry.h"
|
|
#include "PluginJniHelper.h"
|
|
#include <android/log.h>
|
|
#include "PluginUtils.h"
|
|
#include "PluginJavaData.h"
|
|
|
|
#if 1
|
|
#define LOG_TAG "AnalyticsFlurry"
|
|
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
|
#else
|
|
#define LOGD(...)
|
|
#endif
|
|
|
|
namespace cocos2d { namespace plugin {
|
|
|
|
PLUGIN_REGISTER_IMPL(AnalyticsFlurry)
|
|
|
|
AnalyticsFlurry::~AnalyticsFlurry()
|
|
{
|
|
LOGD("AnalyticsFlurry destructor");
|
|
}
|
|
|
|
bool AnalyticsFlurry::init()
|
|
{
|
|
return PluginUtils::initJavaPlugin(this, "org.cocos2dx.plugin.AnalyticsFlurry");
|
|
}
|
|
|
|
void AnalyticsFlurry::setReportLocation(bool enabled)
|
|
{
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
PluginJniMethodInfo t;
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
, pData->jclassName.c_str()
|
|
, "setReportLocation"
|
|
, "(Z)V"))
|
|
{
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID, enabled);
|
|
t.env->DeleteLocalRef(t.classID);
|
|
}
|
|
}
|
|
|
|
void AnalyticsFlurry::logPageView()
|
|
{
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
PluginJniMethodInfo t;
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
, pData->jclassName.c_str()
|
|
, "logPageView"
|
|
, "()V"))
|
|
{
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID);
|
|
t.env->DeleteLocalRef(t.classID);
|
|
}
|
|
}
|
|
|
|
void AnalyticsFlurry::setVersionName(const char* versionName)
|
|
{
|
|
return_if_fails(versionName != NULL && strlen(versionName) > 0);
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
PluginJniMethodInfo t;
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
, pData->jclassName.c_str()
|
|
, "setVersionName"
|
|
, "(Ljava/lang/String;)V"))
|
|
{
|
|
jstring jversionName = t.env->NewStringUTF(versionName);
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID, jversionName);
|
|
t.env->DeleteLocalRef(jversionName);
|
|
t.env->DeleteLocalRef(t.classID);
|
|
}
|
|
}
|
|
|
|
void AnalyticsFlurry::setAge(int age)
|
|
{
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
PluginJniMethodInfo t;
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
, pData->jclassName.c_str()
|
|
, "setAge"
|
|
, "(I)V"))
|
|
{
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID, age);
|
|
t.env->DeleteLocalRef(t.classID);
|
|
}
|
|
}
|
|
|
|
void AnalyticsFlurry::setGender(Gender gender)
|
|
{
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
PluginJniMethodInfo t;
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
, pData->jclassName.c_str()
|
|
, "setGender"
|
|
, "(B)V"))
|
|
{
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID, (jbyte)gender);
|
|
t.env->DeleteLocalRef(t.classID);
|
|
}
|
|
}
|
|
|
|
void AnalyticsFlurry::setUserId(const char* userId)
|
|
{
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
return_if_fails(userId != NULL && strlen(userId) > 0);
|
|
PluginJniMethodInfo t;
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
, pData->jclassName.c_str()
|
|
, "setUserId"
|
|
, "(Ljava/lang/String;)V"))
|
|
{
|
|
jstring juserId = t.env->NewStringUTF(userId);
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID, juserId);
|
|
t.env->DeleteLocalRef(juserId);
|
|
t.env->DeleteLocalRef(t.classID);
|
|
}
|
|
}
|
|
|
|
void AnalyticsFlurry::setUseHttps(bool useHttps)
|
|
{
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
PluginJniMethodInfo t;
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
, pData->jclassName.c_str()
|
|
, "setUseHttps"
|
|
, "(Z)V"))
|
|
{
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID, useHttps);
|
|
t.env->DeleteLocalRef(t.classID);
|
|
}
|
|
}
|
|
|
|
void AnalyticsFlurry::logTimedEventBegin(const char* eventId)
|
|
{
|
|
ProtocolAnalytics::logTimedEventBegin(eventId);
|
|
}
|
|
|
|
void AnalyticsFlurry::logTimedEventBegin(const char* eventId, LogEventParamMap* paramMap)
|
|
{
|
|
return_if_fails(eventId != NULL && strlen(eventId) > 0);
|
|
|
|
if (paramMap == NULL)
|
|
{
|
|
ProtocolAnalytics::logTimedEventBegin(eventId);
|
|
}
|
|
else
|
|
{
|
|
PluginJavaData* pData = PluginUtils::getPluginJavaData(this);
|
|
PluginJniMethodInfo t;
|
|
if (PluginJniHelper::getMethodInfo(t
|
|
, pData->jclassName.c_str()
|
|
, "logTimedEventBegin"
|
|
, "(Ljava/lang/String;Ljava/util/Hashtable;)V"))
|
|
{
|
|
jstring jeventId = t.env->NewStringUTF(eventId);
|
|
jobject jparamMap= PluginUtils::createJavaMapObject(t, paramMap);
|
|
t.env->CallVoidMethod(pData->jobj, t.methodID, jeventId, jparamMap);
|
|
t.env->DeleteLocalRef(jeventId);
|
|
t.env->DeleteLocalRef(jparamMap);
|
|
t.env->DeleteLocalRef(t.classID);
|
|
}
|
|
}
|
|
}
|
|
|
|
/** override methods of base class */
|
|
/** Start a new session. */
|
|
void AnalyticsFlurry::startSession(const char* appKey)
|
|
{
|
|
ProtocolAnalytics::startSession(appKey);
|
|
}
|
|
|
|
/** Stop a session. */
|
|
void AnalyticsFlurry::stopSession()
|
|
{
|
|
ProtocolAnalytics::stopSession();
|
|
}
|
|
|
|
/** Set the timeout for expiring a session. */
|
|
void AnalyticsFlurry::setSessionContinueMillis(long millis)
|
|
{
|
|
ProtocolAnalytics::setSessionContinueMillis(millis);
|
|
}
|
|
|
|
/** Whether to catch uncaught exceptions to server.*/
|
|
void AnalyticsFlurry::setCaptureUncaughtException(bool enabled)
|
|
{
|
|
ProtocolAnalytics::setCaptureUncaughtException(enabled);
|
|
}
|
|
|
|
const char* AnalyticsFlurry::getSDKVersion()
|
|
{
|
|
return ProtocolAnalytics::getSDKVersion();
|
|
}
|
|
|
|
/** Set whether needs to output logs to console.*/
|
|
void AnalyticsFlurry::setDebugMode(bool debug)
|
|
{
|
|
ProtocolAnalytics::setDebugMode(debug);
|
|
}
|
|
|
|
/** log an error */
|
|
void AnalyticsFlurry::logError(const char* errorId, const char* message)
|
|
{
|
|
ProtocolAnalytics::logError(errorId, message);
|
|
}
|
|
|
|
/** log an event. */
|
|
void AnalyticsFlurry::logEvent(const char* eventId, LogEventParamMap* paramMap)
|
|
{
|
|
ProtocolAnalytics::logEvent(eventId, paramMap);
|
|
}
|
|
|
|
/** end a timed event */
|
|
void AnalyticsFlurry::logTimedEventEnd(const char* eventId)
|
|
{
|
|
ProtocolAnalytics::logTimedEventEnd(eventId);
|
|
}
|
|
|
|
void AnalyticsFlurry::logTimedEventEnd(const char* eventId, LogEventParamMap* paramMap)
|
|
{
|
|
ProtocolAnalytics::logTimedEventEnd(eventId);
|
|
}
|
|
|
|
}} // namespace cocos2d { namespace plugin {
|