Skip to content

Commit

Permalink
Merge pull request #25 from adjust/v4120
Browse files Browse the repository at this point in the history
Version 4.12.0
  • Loading branch information
uerceg authored Mar 5, 2018
2 parents 9f0da23 + 2b45808 commit d16eed5
Show file tree
Hide file tree
Showing 34 changed files with 1,414 additions and 342 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# OS X
.DS_Store

# vi swap files
*.swp

# Nuget
nuget
*.nupkg
Expand Down
5 changes: 3 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[submodule "ext/Android/sdk"]
path = ext/Android/sdk
url = git@github.com:adjust/android_sdk.git
branch = cocos2dx
branch = master
[submodule "ext/iOS/sdk"]
path = ext/iOS/sdk
url = git@github.com:adjust/ios_sdk.git
branch = cocos2dx
branch = master
[submodule "ext/Windows/sdk"]
path = ext/Windows/sdk
url = git@github.com:adjust/windows_sdk.git
branch = master
2 changes: 2 additions & 0 deletions Adjust/ADJConfig2dx.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ADJConfig2dx {

void setUserAgent(std::string userAgent);
void setDefaultTracker(std::string defaultTracker);
void setAppSecret(long secretId, long info1, long info2, long info3, long info4);
void setIsDeviceKnown(bool isDeviceKnown);

void setAttributionCallback(void(*callbackMethod)(AdjustAttribution2dx attribution));
void setEventSuccessCallback(void(*callbackMethod)(AdjustEventSuccess2dx eventSuccess));
Expand Down
8 changes: 8 additions & 0 deletions Adjust/ADJConfig2dx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@
return config;
}

void ADJConfig2dx::setAppSecret(long secretId, long info1, long info2, long info3, long info4) {
[((ADJConfig *)config) setAppSecret:secretId info1:info1 info2:info2 info3:info3 info4:info4];
}

void ADJConfig2dx::setIsDeviceKnown(bool isDeviceKnown) {
[((ADJConfig *)config) setIsDeviceKnown:isDeviceKnown];
}

void(*ADJConfig2dx::getAttributionCallback())(AdjustAttribution2dx) {
return attributionCallback;
}
Expand Down
2 changes: 1 addition & 1 deletion Adjust/ADJEvent2dx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@

void* ADJEvent2dx::getEvent() {
return event;
}
}
174 changes: 121 additions & 53 deletions Adjust/Adjust2dx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ void Adjust2dx::start(AdjustConfig2dx adjustConfig) {
}

miOnCreate.env->CallStaticVoidMethod(miOnCreate.classID, miOnCreate.methodID, adjustConfig.getConfig());

onResume();

cocos2d::JniHelper::getEnv()->DeleteGlobalRef(adjustConfig.getConfig());
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
ADJAdjust2dx::appDidLaunch(adjustConfig.getConfig());
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
Expand Down Expand Up @@ -143,7 +144,7 @@ void Adjust2dx::setDeviceToken(std::string deviceToken) {

miSetPushToken.env->DeleteLocalRef(jPushToken);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

#endif
}

Expand All @@ -159,7 +160,7 @@ void Adjust2dx::sendFirstPackages() {

miSendFirstPackages.env->CallStaticVoidMethod(miSendFirstPackages.classID, miSendFirstPackages.methodID);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

#endif
}

Expand All @@ -181,7 +182,7 @@ void Adjust2dx::addSessionCallbackParameter(std::string key, std::string value)
miAddSessionCallbackParameter.env->DeleteLocalRef(jKey);
miAddSessionCallbackParameter.env->DeleteLocalRef(jValue);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

#endif
}

Expand All @@ -203,7 +204,7 @@ void Adjust2dx::addSessionPartnerParameter(std::string key, std::string value) {
miAddSessionPartnerParameter.env->DeleteLocalRef(jKey);
miAddSessionPartnerParameter.env->DeleteLocalRef(jValue);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

#endif
}

Expand All @@ -223,7 +224,7 @@ void Adjust2dx::removeSessionCallbackParameter(std::string key) {

miRemoveSessionCallbackParameter.env->DeleteLocalRef(jKey);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

#endif
}

Expand All @@ -243,7 +244,7 @@ void Adjust2dx::removeSessionPartnerParameter(std::string key) {

miRemoveSessionPartnerParameter.env->DeleteLocalRef(jKey);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

#endif
}

Expand All @@ -259,7 +260,7 @@ void Adjust2dx::resetSessionCallbackParameters() {

miResetSessionCallbackParameters.env->CallStaticVoidMethod(miResetSessionCallbackParameters.classID, miResetSessionCallbackParameters.methodID);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

#endif
}

Expand All @@ -275,7 +276,7 @@ void Adjust2dx::resetSessionPartnerParameters() {

miResetSessionPartnerParameters.env->CallStaticVoidMethod(miResetSessionPartnerParameters.classID, miResetSessionPartnerParameters.methodID);
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

#endif
}

Expand All @@ -302,7 +303,7 @@ std::string Adjust2dx::getAdid() {

return adid;
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

#endif
}

Expand Down Expand Up @@ -427,98 +428,165 @@ AdjustAttribution2dx Adjust2dx::getAttribution() {

return attribution2dx;
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

#endif
}


#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
void Adjust2dx::onResume() {
cocos2d::JniMethodInfo miOnResume;

if (!cocos2d::JniHelper::getStaticMethodInfo(miOnResume, "com/adjust/sdk/Adjust", "onResume", "()V")) {
return;
}

miOnResume.env->CallStaticVoidMethod(miOnResume.classID, miOnResume.methodID);
}

void Adjust2dx::onPause() {
cocos2d::JniMethodInfo miOnPause;

if (!cocos2d::JniHelper::getStaticMethodInfo(miOnPause, "com/adjust/sdk/Adjust", "onPause", "()V")) {
return;
}

miOnPause.env->CallStaticVoidMethod(miOnPause.classID, miOnPause.methodID);
#endif
}

void Adjust2dx::setReferrer(std::string referrer) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
cocos2d::JniMethodInfo miSetReferrer;

if (!cocos2d::JniHelper::getStaticMethodInfo(miSetReferrer, "com/adjust/sdk/Adjust", "setReferrer", "(Ljava/lang/String;)V")) {
if (!cocos2d::JniHelper::getStaticMethodInfo(miSetReferrer, "com/adjust/sdk/Adjust", "setReferrer", "(Ljava/lang/String;Landroid/content/Context;)V")) {
return;
}

jstring jReferrer = miSetReferrer.env->NewStringUTF(referrer.c_str());

miSetReferrer.env->CallStaticVoidMethod(miSetReferrer.classID, miSetReferrer.methodID, jReferrer);


cocos2d::JniMethodInfo miGetContext;
if (!cocos2d::JniHelper::getStaticMethodInfo(miGetContext, "org/cocos2dx/lib/Cocos2dxActivity", "getContext", "()Landroid/content/Context;")) {
return;
}

// Get context and initialize config object.
jobject jContext = (jobject)miGetContext.env->CallStaticObjectMethod(miGetContext.classID, miGetContext.methodID);

miSetReferrer.env->CallStaticVoidMethod(miSetReferrer.classID, miSetReferrer.methodID, jReferrer, jContext);

miSetReferrer.env->DeleteLocalRef(jReferrer);
miGetContext.env->DeleteLocalRef(jContext);
#endif
}

void Adjust2dx::getGoogleAdId(void (*adIdCallback)(std::string adId)) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
setAdIdCallbackMethod(adIdCallback);

cocos2d::JniMethodInfo miGetAdIdCallback;

if (!cocos2d::JniHelper::getStaticMethodInfo(miGetAdIdCallback, "com/adjust/sdk/Adjust", "getGoogleAdId", "(Landroid/content/Context;Lcom/adjust/sdk/OnDeviceIdsRead;)V")) {
return;
}

cocos2d::JniMethodInfo miInit;

if (!cocos2d::JniHelper::getMethodInfo(miInit, "com/adjust/sdk/Adjust2dxAdIdCallback", "<init>", "()V")) {
return;
}

cocos2d::JniMethodInfo miGetContext;

if (!cocos2d::JniHelper::getStaticMethodInfo(miGetContext, "org/cocos2dx/lib/Cocos2dxActivity", "getContext", "()Landroid/content/Context;")) {
return;
}

jclass clsAdjust2dxAdIdCallback = miInit.env->FindClass("com/adjust/sdk/Adjust2dxAdIdCallback");

jmethodID midInit = miInit.env->GetMethodID(clsAdjust2dxAdIdCallback, "<init>", "()V");
jobject jCallbackProxy = miInit.env->NewObject(clsAdjust2dxAdIdCallback, midInit);

// Get context and initialize config object.
jobject jContext = (jobject)miGetContext.env->CallStaticObjectMethod(miGetContext.classID, miGetContext.methodID);

miGetAdIdCallback.env->CallStaticVoidMethod(miGetAdIdCallback.classID, miGetAdIdCallback.methodID, jContext, jCallbackProxy);

miGetContext.env->DeleteLocalRef(jContext);
miInit.env->DeleteLocalRef(jCallbackProxy);
#endif
}

std::string Adjust2dx::getAmazonAdId() {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
cocos2d::JniMethodInfo miGetAmazonAdid;

if (!cocos2d::JniHelper::getStaticMethodInfo(miGetAmazonAdid, "com/adjust/sdk/Adjust", "getAmazonAdId", "(Landroid/content/Context;)Ljava/lang/String;")) {
return "";
}

cocos2d::JniMethodInfo miGetContext;
if (!cocos2d::JniHelper::getStaticMethodInfo(miGetContext, "org/cocos2dx/lib/Cocos2dxActivity", "getContext", "()Landroid/content/Context;")) {
return "";
}

// Get context and initialize config object.
jobject jContext = (jobject)miGetContext.env->CallStaticObjectMethod(miGetContext.classID, miGetContext.methodID);

jstring jAdid = (jstring)miGetAmazonAdid.env->CallStaticObjectMethod(miGetAmazonAdid.classID, miGetAmazonAdid.methodID, jContext);

std::string adid = "";

if (NULL != jAdid) {
const char *adidCStr = miGetAmazonAdid.env->GetStringUTFChars(jAdid, NULL);
adid = std::string(adidCStr);
miGetAmazonAdid.env->ReleaseStringUTFChars(jAdid, adidCStr);
miGetAmazonAdid.env->DeleteLocalRef(jAdid);
}

miGetContext.env->DeleteLocalRef(jContext);

return adid;
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
return "";
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
return "";
#endif
}

void Adjust2dx::onResume() {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
cocos2d::JniMethodInfo miOnResume;

if (!cocos2d::JniHelper::getStaticMethodInfo(miOnResume, "com/adjust/sdk/Adjust", "onResume", "()V")) {
return;
}

miOnResume.env->CallStaticVoidMethod(miOnResume.classID, miOnResume.methodID);
#endif
}

void Adjust2dx::onPause() {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
cocos2d::JniMethodInfo miOnPause;

if (!cocos2d::JniHelper::getStaticMethodInfo(miOnPause, "com/adjust/sdk/Adjust", "onPause", "()V")) {
return;
}

miOnPause.env->CallStaticVoidMethod(miOnPause.classID, miOnPause.methodID);
#endif
}
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

std::string Adjust2dx::getIdfa() {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
return ADJAdjust2dx::getIdfa();
}
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
return "";
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
return "";
#endif
}

std::string Adjust2dx::getWindowsAdId() {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
Platform::String^ managedAdId = WRTAdjust::GetWindowsAdId();
std::wstring wstrAdId(managedAdId->Begin());
std::string adId(wstrAdId.begin(), wstrAdId.end());

return adId;
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
return "";
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
return "";
#endif
}

void Adjust2dx::applicationPaused() {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
WRTAdjust::ApplicationDeactivated();
#endif
}

void Adjust2dx::applicationResumed() {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
WRTAdjust::ApplicationActivated();
}
#endif
}
16 changes: 9 additions & 7 deletions Adjust/Adjust2dx.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ class Adjust2dx {

static std::string getAdid();
static AdjustAttribution2dx getAttribution();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
static void onResume();
static void onPause();

// Android-specific
static void setReferrer(std::string referrer);
static void getGoogleAdId(void (*adIdCallback)(std::string adId));
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
static std::string getAmazonAdId();
static void onResume();
static void onPause();

// iOS-specific
static std::string getIdfa();
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)

// Windows-specific
static std::string getWindowsAdId();
static void applicationPaused();
static void applicationResumed();
#endif
};

#endif /* ADJUST_ADJUST2DX_H_ */
Loading

0 comments on commit d16eed5

Please sign in to comment.