forked from adctl/adctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadctl.h
More file actions
executable file
·291 lines (231 loc) · 9.67 KB
/
adctl.h
File metadata and controls
executable file
·291 lines (231 loc) · 9.67 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#ifndef ADMOBBANNERCTL_H
#define ADMOBBANNERCTL_H
#include <QObject>
#include <QPoint>
#include <QVariant>
#include <QSize>
#include <QtQml> //place here to avoid include for registration
#define REGISTER_ADCTL qmlRegisterType<AdCtl>("adctl",1,0,"AdCtl")
class IQtAdMobBanner;
class IQtAdMobInterstitial;
class QTimer;
class AdCtl_platform_interface;
class GAnalytics;
class AdCtl : public QObject
{
Q_OBJECT
//enabled properties
Q_PROPERTY(bool isInitialized READ initialized)
Q_PROPERTY(bool adMobBannerEnabled READ AdMobBannerEnabled WRITE setAdMobBannerEnabled NOTIFY adMobBannerEnabledChanged)
Q_PROPERTY(bool adMobIinterstitialEnabled READ AdMobIinterstitialEnabled WRITE setAdMobIinterstitialEnabled NOTIFY adMobIinterstitialEnabledChanged)
Q_PROPERTY(bool startAdBannerEnabled READ StartAdBannerEnabled WRITE setStartAdBannerEnabled NOTIFY startAdBannerEnabledChanged)
Q_PROPERTY(bool gAnalyticsEnabled READ GAnalyticsEnabled WRITE setGAnalyticsEnabled NOTIFY gAnalyticsEnabledChanged)
//AdMob width and height
Q_PROPERTY(int adMobBannerHeight READ AdMobBannerHeight NOTIFY adMobBannerHeightChanged)
Q_PROPERTY(int adMobBannerWidth READ AdMobBannerWidth NOTIFY adMobBannerWidthChanged)
//AdMob position
Q_PROPERTY(QPoint adMobBannerPosition READ AdMobBannerPosition WRITE setAdMobBannerPosition)
//StartAd width and height
Q_PROPERTY(int startAdBannerHeight READ StartAdBannerHeight NOTIFY startAdBannerHeightChanged)
Q_PROPERTY(int startAdBannerWidth READ StartAdBannerWidth NOTIFY startAdBannerWidthChanged)
//StartAd position
Q_PROPERTY(QPoint startAdBannerPosition READ StartAdBannerPosition WRITE setStartAdBannerPosition)
//StartAd size
Q_PROPERTY(QSize startAdBannerSize READ StartAdBannerSize WRITE setStartAdBannerSize)
//Get real positions
Q_PROPERTY(int adMobBannerRealX READ adMobBannerRealX)
Q_PROPERTY(int AdMobBannerRealY READ adMobBannerRealY)
Q_PROPERTY(int startAdBannerRealX READ startAdBannerRealX)
Q_PROPERTY(int startAdBannerRealY READ startAdBannerRealY)
Q_PROPERTY(bool adMobBannerVisible READ AdMobBannerVisible WRITE setAdMobBannerVisible NOTIFY adMobBannerVisibleChanged)
Q_PROPERTY(bool adMobIinterstitialVisible READ AdMobIinterstitialVisible WRITE setAdMobIinterstitialVisible NOTIFY adMobIinterstitialVisibleChanged)
Q_PROPERTY(bool startAdBannerVisible READ StartAdBannerVisible WRITE setStartAdBannerVisible NOTIFY startAdBannerVisibleChanged)
//ID's for banners and analytics
Q_PROPERTY(QString adMobBannerId READ getBannerAdMobId WRITE setAdMobBannerId NOTIFY adMobBannerIdChanged)
Q_PROPERTY(QString adMobInterstitialId READ getInterstitialAdMobId WRITE setAdMobInterstitialId NOTIFY adMobInterstitialIdChanged)
Q_PROPERTY(QString startAdId READ getStartAdId WRITE setStartAdId NOTIFY startAdIdChanged)
Q_PROPERTY(QString gAnalyticsId READ getGAnaliticsId WRITE setGAnalyticsId NOTIFY gAnalyticsIdChanged)
//list of test devices
Q_PROPERTY(QStringList testDevices READ getTestDevices WRITE setTestDevices NOTIFY testDevicesChanged)
//Google Play Game Services
Q_PROPERTY(bool gpgsSignedIn READ isGPGSSignedIn WRITE setGPGSSignedIn NOTIFY gpgsSignedInChanged)
public:
explicit AdCtl(QObject *parent = 0);
~AdCtl();
// Do not forget to declare your class to the QML system.
static void declareQML() {
qmlRegisterType<AdCtl>("ru.forsk.adctl", 1, 0, "AdCtl");
}
signals:
//StartAd and AdMob showed and sizes
void adMobBannerShowed();
void startAdBannerShowed();
void adMobBannerHeightChanged(int height);
void adMobBannerWidthChanged(int width);
void startAdBannerHeightChanged(int height);
void startAdBannerWidthChanged(int width);
void gpgsSignedInChanged(bool gpgsSignedIn);
//ids changed
void adMobInterstitialIdChanged();
void adMobBannerIdChanged();
void startAdIdChanged();
void gAnalyticsIdChanged();
//visibility changed
void adMobBannerVisibleChanged();
void adMobIinterstitialVisibleChanged();
void startAdBannerVisibleChanged();
//enabled changed
void adMobBannerEnabledChanged();
void adMobIinterstitialEnabledChanged();
void startAdBannerEnabledChanged();
void gAnalyticsEnabledChanged();
//Google Play Games
//This is used when a score is returned for a leaderboad.(qstring,uint64,int)
void scoreGPG(QVariant leaderboardID,QVariant score,QVariant gpgStatus);
//test devices changed
void testDevicesChanged();
public slots:
//init library with ids and bool flags
void init();
//Timer for control, update and emit properties changes for banners (for first run)
void adctlTimerSlot();
bool initialized() const;
//AdMob banner enabled
void setAdMobBannerEnabled(const bool AdMobBannerEnabled);
bool AdMobBannerEnabled() const;
bool AdMobBannerIsLoaded() const;
//AdMob interstitial enabled
bool AdMobIinterstitialEnabled() const;
void setAdMobIinterstitialEnabled(bool AdMobIinterstitialEnabled);
bool AdMobIinterstitialIsLoaded() const;
//StartAd banner enabled
void setStartAdBannerEnabled(const bool StartAdBannerEnabled);
bool StartAdBannerEnabled() const;
//GAnalytics banner enabled
void setGAnalyticsEnabled(const bool GAnalyticsEnabled);
bool GAnalyticsEnabled() const;
//AdMob width and height
int AdMobBannerHeight() const;
int AdMobBannerWidth() const;
//StartAd width and height
int StartAdBannerHeight() const;
int StartAdBannerWidth() const;
//AdMob set position
void setAdMobBannerPosition(const QPoint AdMobBannerPosition);
QPoint AdMobBannerPosition() const;
//StartAd set position
void setStartAdBannerPosition(const QPoint StartAdBannerPosition);
QPoint StartAdBannerPosition() const;
//StartAd set size
void setStartAdBannerSize(const QSize StartAdBannerSize);
QSize StartAdBannerSize() const;
//Get Real Positions
int adMobBannerRealX();
int adMobBannerRealY();
int startAdBannerRealX();
int startAdBannerRealY();
//ids
void setAdMobBannerId(const QString &BannerAdMobId);
void setAdMobInterstitialId(const QString &InterstitialAdMobId);
void setStartAdId(const QString &StartAdId);
void setGAnalyticsId(const QString &GAnalyticsId);
QString getInterstitialAdMobId()const;
QString getBannerAdMobId()const;
QString getStartAdId()const;
QString getGAnaliticsId()const;
void setAdMobBannerVisible(const bool visible);
void setAdMobIinterstitialVisible(const bool visible);
void setStartAdBannerVisible(const bool visible);
bool AdMobBannerVisible()const;
bool AdMobIinterstitialVisible()const;
bool StartAdBannerVisible()const;
//test devices
QStringList getTestDevices()const;
void setTestDevices(const QStringList &testDevices);
//ctl methods
void showAdMobBanner();
void hideAdMobBanner();
void showAdMobInterstitial();
void showStartAdBanner();
void hideStartAdBanner();
//Google Analytics
void sendGaAppView(const QString &screenName = QString());
void sendGaEvent(const QString &category = QString(),
const QString &action = QString(),
const QString &label = QString(),
const QVariant &value = QVariant());
void endGaSession();
//Google Play Game Services
bool isGPGSSignedIn();
void setGPGSSignedIn(bool gpgsSignedIn);
void signInGPGS();
/**
* @brief This will request the score of a leaderboard.
* @note Thie result will be delivered with the @scoreGPG signal.
*/
void getLeaderBoardScoreAsync(QString leaderboard);
void submitScoreGPGS(QString leaderBoardId, int score);
void unlockAchievementGPGS(QString achievementId);
void showLeaderboardGPGS();
void showLeaderboard(QString leaderboardId);
void showAchievementsGPGS();
//Util/tool/maybenotneededbutheretheyare
void share(QString url);
//dp, pt and mm
float dp();
float mm();
float pt();
static AdCtl* getInstance();
protected:
static AdCtl* m_instance;
//Timer for control, update and emit properties changes for banners
QTimer *adctlTimer;
//Pointers
IQtAdMobBanner *m_AdMobBanner;
IQtAdMobInterstitial *m_AdMobInterstitial;
GAnalytics *gAnalytics;
//Enabled control vars
bool m_AdMobBannerEnabled = false;
bool m_AdMobInterstitialEnabled = false;
bool m_StartAdBannerEnabled = false;
bool m_GAnalyticsEnabled = false;
bool m_AdMobBannerVisible = false;
bool m_AdMobInterstitialVisible = false;
bool m_StartAdBannerVisible = false;
//ids
QString m_BannerAdMobId;
QString m_InterstitialAdMobId;
QString m_StartAdId;
QString m_GAnalyticsId;
//test devices
QStringList m_testDevices;
//initialized
bool m_AdInitialized = false;
//plarform-specific layer
AdCtl_platform_interface *m_platform;
//cache
int cacheAdMobBannerHeight;
int cacheAdMobBannerWidth;
int cacheStartAdBannerHeight;
int cacheStartAdBannerWidth;
//positions and sizes
QPoint m_AdMobBannerPosition;
QPoint m_StartAdBannerPosition;
QSize m_StartAdBannerSize;
//is banners showed
bool m_isAdMobBannerShowed = false;
bool m_isStartAdBannerShowed = false;
bool m_AdMobBannerShowHideTrigger = false;
bool m_StartAdBannerShowHideTrigger = false;
//banners alredy visible bools
bool m_AdMobWidthAlredyGreatThanZero = false;
bool m_StartAdWidthAlredyGreatThanZero = false;
//Google Play Game Services
bool m_gpgsSignedIn;
QTimer *gpgsTimer;
//density (simple Fix Qt android density bug)
float m_dp;
float m_pt;
float m_mm;
};
#endif // ADMOBBANNERCTL_H