Skip to content

Commit 6733007

Browse files
author
Emre Demir
committed
Bundle id added for game data. Last tunnl implementation is handled. Two new event added: onAPIReady and onAPINotReady
1 parent 02f4d05 commit 6733007

File tree

5 files changed

+76
-79
lines changed

5 files changed

+76
-79
lines changed

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDGameData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class GDGameData {
88

9-
public static String gameMd5, title;
9+
public static String gameMd5, title, bundleId;
1010
public static boolean enableAds, preRoll;
1111
public static int timeAds;
1212
}

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDad.java

Lines changed: 54 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,10 @@
1616
import com.google.android.gms.ads.doubleclick.PublisherAdView;
1717
import com.google.android.gms.ads.doubleclick.PublisherInterstitialAd;
1818
import com.google.gson.Gson;
19-
2019
import org.json.JSONArray;
2120
import org.json.JSONException;
2221
import org.json.JSONObject;
23-
24-
import java.security.KeyManagementException;
25-
import java.security.NoSuchAlgorithmException;
26-
import java.security.cert.CertificateException;
27-
import java.security.cert.X509Certificate;
2822
import java.util.ArrayList;
29-
import java.util.List;
30-
31-
import javax.net.ssl.HostnameVerifier;
32-
import javax.net.ssl.HttpsURLConnection;
33-
import javax.net.ssl.SSLContext;
34-
import javax.net.ssl.SSLSession;
35-
import javax.net.ssl.TrustManager;
36-
import javax.net.ssl.X509TrustManager;
3723

3824

3925
/**
@@ -51,33 +37,32 @@ public class GDad {
5137
private RelativeLayout relativeLayoutContainer;
5238
private boolean bannerActive = false;
5339
ArrayList<GDTunnlData> tunnlData;
54-
int currentRequestInd = -1;
55-
GDRequestAdHandler gdRequestAdHandler;
40+
private int currentRequestInd = -1;
41+
private GDRequestAdHandler gdRequestAdHandler;
5642

5743
public void init(Activity mContext) {
5844
setmContext(mContext);
5945
setRootview((FrameLayout) mContext.findViewById(android.R.id.content));
6046
initBannerObject();
6147

48+
if (devListener != null) devListener.onAPIReady();
49+
6250
if(GDGameData.preRoll){
6351
showBanner("{isInterstitial:" + true + "}");
6452
}
65-
66-
disableSSLCertificateChecking();
67-
6853
}
6954

7055
public void init(Activity mContext, boolean isCordovaPlugin) {
7156
if (isCordovaPlugin) {
7257
setmContext(mContext);
7358
// in cordova plugin, there will be no banner ads.
7459

60+
if (devListener != null) devListener.onAPIReady();
61+
7562
if(GDGameData.preRoll){
7663
showBanner("{isInterstitial:" + true + "}");
7764
}
7865

79-
disableSSLCertificateChecking();
80-
8166
} else {
8267
init(mContext);
8368
}
@@ -94,7 +79,6 @@ private void initBannerObject() {
9479
setRelativeLayoutContainer(rl);
9580

9681
publisherAdView = new PublisherAdView(getmContext());
97-
publisherAdView.setAdUnitId(getmUnitId());
9882
publisherAdView.setLayoutParams(new RelativeLayout.LayoutParams(
9983
RelativeLayout.LayoutParams.WRAP_CONTENT,
10084
RelativeLayout.LayoutParams.WRAP_CONTENT
@@ -113,6 +97,19 @@ private void requestBanner(String size, String alignment, String position, Bundl
11397

11498
if(getRelativeLayoutContainer() != null){
11599

100+
if(publisherAdView != null){
101+
102+
getRelativeLayoutContainer().removeView(publisherAdView);
103+
publisherAdView = new PublisherAdView(getmContext());
104+
publisherAdView.setLayoutParams(new RelativeLayout.LayoutParams(
105+
RelativeLayout.LayoutParams.WRAP_CONTENT,
106+
RelativeLayout.LayoutParams.WRAP_CONTENT
107+
));
108+
setPublisherAdView(publisherAdView);
109+
// add adcontainer into rootview
110+
getRelativeLayoutContainer().addView(publisherAdView);
111+
}
112+
116113
PublisherAdRequest adRequest;
117114
PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
118115
builder.addNetworkExtrasBundle(AdMobAdapter.class, customParams);
@@ -122,7 +119,6 @@ private void requestBanner(String size, String alignment, String position, Bundl
122119

123120
publisherAdView.setAdUnitId(unitId);
124121

125-
126122
publisherAdView.loadAd(adRequest);
127123
publisherAdView.setAdListener(new AdListener() {
128124

@@ -152,13 +148,15 @@ public void onAdFailedToLoad(int errorCode) {
152148
error += "No fill.\nThe ad request was successful, but no ad was returned due to lack of ad inventory.\nConstant Value: " + errorCode;
153149
break;
154150
}
151+
155152
GDutils.log("Ad failed to load: " + error);
156153
GDutils.log("For more details: https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest");
157154

158-
if (devListener != null)
155+
if (devListener != null && GDstatic.testAds){
159156
devListener.onBannerFailed(error);
160-
161-
gdRequestAdHandler.Error(error);
157+
}
158+
else if(devListener != null && gdRequestAdHandler != null)
159+
gdRequestAdHandler.Error(error);
162160

163161
}
164162

@@ -186,7 +184,8 @@ public void onAdLoaded() {
186184
if (devListener != null)
187185
devListener.onBannerRecieved(gdEvent);
188186

189-
gdRequestAdHandler.Succes();
187+
if(!GDstatic.testAds)
188+
gdRequestAdHandler.Succes();
190189

191190
}
192191
});
@@ -199,7 +198,6 @@ private void requestInterstitial(Bundle customParams, String unitId) {
199198

200199
PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
201200
builder.addNetworkExtrasBundle(AdMobAdapter.class, customParams);
202-
203201
adRequest = builder.build();
204202

205203
mInterstitialAd.setAdUnitId(unitId);
@@ -233,11 +231,11 @@ public void onAdFailedToLoad(int errorCode) {
233231
GDutils.log("Ad failed to load: " + error);
234232
GDutils.log("For more details: https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest");
235233

236-
if (devListener != null)
234+
if (devListener != null && GDstatic.testAds){
237235
devListener.onBannerFailed(error);
238-
239-
gdRequestAdHandler.Error(error);
240-
236+
}
237+
else if(devListener != null && gdRequestAdHandler != null)
238+
gdRequestAdHandler.Error(error);
241239

242240
}
243241

@@ -266,7 +264,8 @@ public void onAdLoaded() {
266264
if (devListener != null)
267265
devListener.onBannerRecieved(gdEvent);
268266

269-
gdRequestAdHandler.Succes();
267+
if(!GDstatic.testAds)
268+
gdRequestAdHandler.Succes();
270269
}
271270
});
272271
mInterstitialAd.loadAd(adRequest);
@@ -333,17 +332,22 @@ public void showBanner(String args) {
333332
gDshowObj = gson.fromJson(args, GDshowObj.class);
334333

335334
if(GDstatic.testAds){
336-
if(gDshowObj.isInterstitial)
335+
if(gDshowObj.isInterstitial){
337336
this.setmUnitId(GDstatic.testInterUnitId);
338-
else
337+
requestInterstitial(null, GDstatic.testInterUnitId);
338+
}
339+
else{
339340
this.setmUnitId(GDstatic.testBannerUnitId);
341+
requestBanner(gDshowObj.size, gDshowObj.alignment, gDshowObj.position ,null, GDstatic.testBannerUnitId);
342+
}
340343
}
341344
else{
342345

343-
String bundleId = "bundle.test.1";
344-
String dimension = "640x480";
345-
if(!gDshowObj.isInterstitial) dimension = gDshowObj.size;
346-
String url = "http://pub.tunnl.com/oppm?bundleid="+bundleId+"&dnumber="+dimension;
346+
currentRequestInd = -1;
347+
String bundleId = GDGameData.bundleId;
348+
String msize = "interstitial";
349+
if(!gDshowObj.isInterstitial) msize = gDshowObj.size;
350+
String url = "http://pub.tunnl.com/oppm?bundleid="+bundleId+"&msize="+msize;
347351

348352
// getting unit id from tunnl for ad request
349353
GDHttpRequest.sendHttpRequest(GDlogger.mContext, url, Request.Method.GET, null, new GDHttpCallback() {
@@ -371,11 +375,16 @@ public void onSuccess(JSONObject data) {
371375
tunnlData.add(gdTunnlData);
372376
}
373377

374-
requestHandler(gDshowObj);
378+
if(items.length() > 0)
379+
requestHandler(gDshowObj);
380+
else{
381+
if (devListener != null)
382+
devListener.onBannerFailed("Something went wrong fetching advertisement settings. Please contact with support team.");
383+
}
375384

376385
} catch (JSONException e) {
377386
e.printStackTrace();
378-
GDutils.log("Something went wrong parsing json game data.\nData:\n"+data.toString());
387+
GDutils.log("Something went wrong parsing json tunnl data.\nData:\n"+data.toString());
379388
}
380389
}
381390
@Override
@@ -440,42 +449,16 @@ public void onError(VolleyError error) {
440449
else{
441450
currentRequestInd = -1;
442451
tunnlData = null;
443-
}
444452

445-
}
446-
};
447-
448-
449-
}
450-
451-
private static void disableSSLCertificateChecking() {
452-
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
453-
public X509Certificate[] getAcceptedIssuers() {
454-
return null;
455-
}
453+
if (devListener != null)
454+
devListener.onBannerFailed(err);
456455

457-
@Override
458-
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
459-
// Not implemented
460-
}
456+
}
461457

462-
@Override
463-
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
464-
// Not implemented
465458
}
466-
} };
467-
468-
try {
469-
SSLContext sc = SSLContext.getInstance("TLS");
459+
};
470460

471-
sc.init(null, trustAllCerts, new java.security.SecureRandom());
472461

473-
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
474-
} catch (KeyManagementException e) {
475-
e.printStackTrace();
476-
} catch (NoSuchAlgorithmException e) {
477-
e.printStackTrace();
478-
}
479462
}
480463

481464
public void destroyBanner() {

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDadListener.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
public abstract class GDadListener {
8+
89
public void onBannerClosed() {
910
}
1011
public void onBannerStarted() {
@@ -13,5 +14,9 @@ public void onBannerRecieved(GDEvent data) {
1314
}
1415
public void onBannerFailed(String msg) {
1516
}
17+
public void onAPIReady(){
18+
}
19+
public void onAPINotReady(String error){
20+
}
1621

1722
}

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDbanner.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class GDbanner {
1414
protected static void init() {
1515

1616
if(GDstatic.enable) {
17-
String url = GDstatic.GAME_API_URL + '/' + GDstatic.gameId + "?domain=test.api";
17+
String url = GDstatic.GAME_API_URL + '/' + GDstatic.gameId;
1818
GDHttpRequest.sendHttpRequest(GDlogger.mContext, url, Request.Method.GET, null, new GDHttpCallback() {
1919
@Override
2020
public void onSuccess(JSONObject data) {
@@ -30,19 +30,23 @@ public void onSuccess(JSONObject data) {
3030
GDGameData.preRoll = game.getBoolean("preRoll");
3131
GDGameData.timeAds = game.getInt("timeAds");
3232
GDGameData.title = game.getString("title");
33+
GDGameData.bundleId = game.getString("androidBundleId");
3334

3435
GDutils.log(data.toString());
35-
3636
GDlogger.gDad.init(GDlogger.mContext,GDlogger.isCordovaPlugin);
37+
}
38+
else{
39+
String error = "Something went wrong fetching game data.";
40+
GDutils.log(error);
3741

38-
42+
if(GDlogger.gDad.devListener != null)
43+
GDlogger.gDad.devListener.onAPINotReady(error);
3944
}
4045

4146
} catch (JSONException e) {
4247
e.printStackTrace();
4348
GDutils.log("Something went wrong parsing json game data.\nData:\n"+data.toString());
4449
}
45-
4650
}
4751

4852
@Override
@@ -75,12 +79,17 @@ protected static void ShowBanner(String args) {
7579

7680
if (gDshowObj.isInterstitial) {
7781
if (GDstatic.reqInterstitialEnabled) {
82+
7883
GDlogger.gDad.showBanner(args);
7984
adInterstitialTimer = null;
85+
8086
if(!GDstatic.testAds){
8187
setAdTimer(true); // inter timer
8288
GDstatic.reqInterstitialEnabled = false;
8389
}
90+
else{
91+
GDstatic.reqInterstitialEnabled = true;
92+
}
8493

8594
} else {
8695
GDutils.log("You can not invoke 'ShowBanner()' within " + GDGameData.timeAds + " min(s).");
@@ -91,7 +100,7 @@ protected static void ShowBanner(String args) {
91100
GDlogger.gDad.showBanner(args);
92101
adBannerTimer = null;
93102
if(!GDstatic.testAds){
94-
setAdTimer(true); // banner timer
103+
setAdTimer(false); // banner timer
95104
GDstatic.reqBannerEnabled = false;
96105
}
97106

@@ -100,6 +109,7 @@ protected static void ShowBanner(String args) {
100109
}
101110
}
102111
} else {
112+
103113
if (GDlogger.gDad.devListener != null) {
104114
GDlogger.gDad.devListener.onBannerFailed("Banner request failed: 'Midroll is disabled.'");
105115
}
@@ -124,7 +134,6 @@ public void run() {
124134
adTimerHandler(isInterstitial);
125135
}
126136
} catch (InterruptedException e) {
127-
// TODO Auto-generated catch block
128137
e.printStackTrace();
129138
}
130139
}
@@ -141,7 +150,6 @@ public void run() {
141150
adTimerHandler(isInterstitial);
142151
}
143152
} catch (InterruptedException e) {
144-
// TODO Auto-generated catch block
145153
e.printStackTrace();
146154
}
147155
}

Source/GDApi/gdapi/src/main/java/com/gd/analytics/GDstatic.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class GDstatic {
44

5+
protected static final String TEST_GAME_API_URL = "http://test.game.api.gamedistribution.com/game/get";
56
protected static final String GAME_API_URL = "https://game.api.gamedistribution.com/game/get";
67
protected static final String TUNNL_TAG_URL = "https://ana.tunnl.com"; // /at?id={{game-id}}&pageurl={{bundle-name}}
78
protected static final String version = "v1.0";

0 commit comments

Comments
 (0)