-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRevMobAds_Android.cpp
213 lines (181 loc) · 4.92 KB
/
RevMobAds_Android.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "RevMobAds_Android.h"
#include <jni.h>
#include "platform/android/jni/JniHelper.h"
#include <android/log.h>
#ifndef CC_TARGET_PLATFORM
#error "CC_TARGET_PLATFORM should be defined!!!"
#endif
namespace revmob {
const char *RevMobWrapperClass = "com/revmob/cocos2dx/RevMobWrapper";
static void callStaticVoidMethod(const char *name, const char *signature, ...)
{
cocos2d::JniMethodInfo methodInfo;
if ( cocos2d::JniHelper::getStaticMethodInfo( methodInfo,
RevMobWrapperClass,
name,
signature) ) {
va_list args;
va_start(args, signature);
methodInfo.env->CallStaticVoidMethodV(methodInfo.classID, methodInfo.methodID, args);
va_end(args);
}
}
static int callStaticIntMethod(const char *name, const char *signature, ...)
{
cocos2d::JniMethodInfo methodInfo;
jint ret = 0;
if ( cocos2d::JniHelper::getStaticMethodInfo( methodInfo,
RevMobWrapperClass,
name,
signature) ) {
va_list args;
va_start(args, signature);
ret = methodInfo.env->CallStaticIntMethod(methodInfo.classID, methodInfo.methodID, args);
va_end(args);
}
return ret;
}
void RevMobAds_Android::StartSession(const char *pAppID)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
cocos2d::JniMethodInfo methodInfo;
if ( cocos2d::JniHelper::getStaticMethodInfo( methodInfo,
RevMobWrapperClass,
"startSession",
"(Ljava/lang/String;)V") ) {
jstring stringArg = methodInfo.env->NewStringUTF(pAppID);
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, stringArg);
methodInfo.env->DeleteLocalRef(stringArg);
}
#endif
}
void RevMobAds_Android::PrintEnvironmentInformation()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("printEnvironmentInformation","()V");
#endif
}
void RevMobAds_Android::SetTestingMode(TestingMode pTestingMode)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
switch (pTestingMode) {
case kTestingModeWithAds:
callStaticVoidMethod("setTestingMode","(I)V",1);
break;
case kTestingModeWithoutAds:
callStaticVoidMethod("setTestingMode","(I)V",2);
break;
case kTestingModeDisabled:
case kTestingModeUndefined:
default:
callStaticVoidMethod("setTestingMode","(I)V",0);
break;
}
#endif
}
TestingMode RevMobAds_Android::GetTestingMode()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
int mode = callStaticIntMethod("getTestingMode","()I");
switch (mode) {
case 0:
return kTestingModeDisabled;
break;
case 1:
return kTestingModeWithAds;
break;
case 2:
return kTestingModeWithoutAds;
break;
default:
return kTestingModeUndefined;
}
#else
return kTestingModeUndefined;
#endif
}
void RevMobAds_Android::ShowFullscreen()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("showFullscreen","()V");
#endif
}
void RevMobAds_Android::LoadFullscreen()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("loadFullscreen","()V");
#endif
}
void RevMobAds_Android::ShowLoadedFullscreen()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("showLoadedFullscreen","()V");
#endif
}
void RevMobAds_Android::ShowPopup()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("showPopup","()V");
#endif
}
void RevMobAds_Android::LoadPopup()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("loadPopup","()V");
#endif
}
void RevMobAds_Android::ShowLoadedPopup()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("showLoadedPopup","()V");
#endif
}
void RevMobAds_Android::ShowBanner()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("showBanner","()V");
#endif
}
void RevMobAds_Android::HideBanner()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("hideBanner","()V");
#endif
}
void RevMobAds_Android::LoadBanner()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("loadBanner","()V");
#endif
}
void RevMobAds_Android::ShowLoadedBanner()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("showLoadedBanner","()V");
#endif
}
void RevMobAds_Android::HideLoadedBanner()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("hideLodedBanner","()V");
#endif
}
void RevMobAds_Android::OpenLink()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("openLink","()V");
#endif
}
void RevMobAds_Android::LoadLink()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("loadLink","()V");
#endif
}
void RevMobAds_Android::OpenLoadedLink()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
callStaticVoidMethod("openLoadedLink","()V");
#endif
}
} /* namespace revmob */