Skip to content

Commit 8a12213

Browse files
author
Emre Demir
committed
Enabling test ads feautre and some cleaning.
1 parent 511f14f commit 8a12213

File tree

75 files changed

+50
-13520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+50
-13520
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.gd.analytics;
22

33
import android.content.Context;
4+
45
import com.android.volley.Request;
56
import com.android.volley.RequestQueue;
67
import com.android.volley.toolbox.Volley;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.gd.analytics;
22

33
import com.android.volley.VolleyError;
4-
import com.google.gson.JsonObject;
54

65
import org.json.JSONObject;
76

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.gd.analytics;
22

33
import android.content.Context;
4+
45
import com.android.volley.Response;
56
import com.android.volley.VolleyError;
67
import com.android.volley.toolbox.JsonObjectRequest;

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.app.Activity;
44
import android.os.Bundle;
5-
import android.provider.Settings;
65
import android.view.Gravity;
76
import android.widget.FrameLayout;
87
import android.widget.RelativeLayout;
@@ -15,9 +14,6 @@
1514
import com.google.android.gms.ads.doubleclick.PublisherInterstitialAd;
1615
import com.google.gson.Gson;
1716

18-
import java.security.MessageDigest;
19-
import java.security.NoSuchAlgorithmException;
20-
2117

2218
/**
2319
* Created by Emre Demir on 20.09.2016.
@@ -30,24 +26,43 @@ public class GDad {
3026
private PublisherInterstitialAd mInterstitialAd;
3127
private Activity mContext;
3228
private String mUnitId;
33-
private String cordovaAdxUnitId = "ca-mb-app-pub-5192618204358860/8119020012";
3429
private PublisherAdView publisherAdView;
3530
private FrameLayout rootview;
3631
private RelativeLayout relativeLayoutContainer;
3732
private boolean bannerActive = false;
38-
private boolean isCordovaPlugin = false;
3933

4034
public void init(Activity mContext) {
4135
setmContext(mContext);
4236
setRootview((FrameLayout) mContext.findViewById(android.R.id.content));
4337
initBannerObject();
38+
if(GDstatic.testAds){
39+
this.setmUnitId(GDstatic.testAdxUnitId);
40+
}
41+
else{
42+
this.setmUnitId(GDstatic.adUnit);
43+
}
44+
45+
if(GDGameData.preRoll){
46+
requestInterstitial();
47+
}
4448
}
4549

4650
public void init(Activity mContext, boolean isCordovaPlugin) {
4751
if (isCordovaPlugin) {
48-
this.isCordovaPlugin = true;
52+
if(GDstatic.testAds){
53+
this.setmUnitId(GDstatic.testAdxUnitId);
54+
}
55+
else{
56+
this.setmUnitId(GDstatic.cordovaAdxUnitId);
57+
}
58+
4959
setmContext(mContext);
5060
// in cordova plugin, there will be no banner ads.
61+
62+
if(GDGameData.preRoll){
63+
requestInterstitial();
64+
}
65+
5166
} else {
5267
init(mContext);
5368
}
@@ -80,10 +95,10 @@ private void initBannerObject() {
8095
}
8196

8297
private void requestBanner(String size, String alignment, String position) {
98+
8399
Bundle cust_params = new Bundle();
84100
cust_params.putString("apptype", "android");
85101
cust_params.putString("appid", GDstatic.gameId);
86-
cust_params.putString("a", GDstatic.affiliateId);
87102

88103
PublisherAdRequest adRequest;
89104
PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
@@ -175,11 +190,8 @@ private void requestInterstitial() {
175190

176191
adRequest = builder.build();
177192

178-
if (this.isCordovaPlugin) {
179-
mInterstitialAd.setAdUnitId(cordovaAdxUnitId);
180-
} else {
181-
mInterstitialAd.setAdUnitId(getmUnitId());
182-
}
193+
mInterstitialAd.setAdUnitId(getmUnitId());
194+
183195
mInterstitialAd.setAdListener(new AdListener() {
184196
@Override
185197
public void onAdClosed() {

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@
44
import com.android.volley.VolleyError;
55
import com.google.gson.Gson;
66

7-
import org.apache.http.Header;
87
import org.json.JSONException;
98
import org.json.JSONObject;
10-
import org.xmlpull.v1.XmlPullParser;
11-
import org.xmlpull.v1.XmlPullParserException;
12-
import org.xmlpull.v1.XmlPullParserFactory;
13-
14-
import java.io.IOException;
15-
import java.io.StringReader;
169

1710
class GDbanner {
1811

@@ -21,7 +14,8 @@ class GDbanner {
2114
protected static void init() {
2215

2316
if(GDstatic.enable) {
24-
GDHttpRequest.sendHttpRequest(GDlogger.mContext, GDstatic.GAME_API_URL, Request.Method.GET, null, new GDHttpCallback() {
17+
String url = GDstatic.GAME_API_URL + '/' + GDstatic.gameId + "?domain=test.api";
18+
GDHttpRequest.sendHttpRequest(GDlogger.mContext, url, Request.Method.GET, null, new GDHttpCallback() {
2519
@Override
2620
public void onSuccess(JSONObject data) {
2721

@@ -36,6 +30,12 @@ public void onSuccess(JSONObject data) {
3630
GDGameData.preRoll = game.getBoolean("preRoll");
3731
GDGameData.timeAds = game.getInt("timeAds");
3832
GDGameData.title = game.getString("title");
33+
34+
GDutils.log(data.toString());
35+
36+
GDlogger.gDad.init(GDlogger.mContext,GDlogger.isCordovaPlugin);
37+
38+
3939
}
4040

4141
} catch (JSONException e) {
@@ -63,7 +63,6 @@ protected static void ShowBanner(String args) {
6363
if (GDGameData.enableAds && gDshowObj._key != null && gDshowObj._key.equals("preroll") && GDlogger.gDad != null) {
6464

6565
if (GDGameData.preRoll) {
66-
GDlogger.gDad.setmUnitId(GDstatic.adUnit);
6766
GDlogger.gDad.showBanner(args);
6867
} else {
6968
if (GDlogger.gDad.devListener != null) {
@@ -76,7 +75,6 @@ protected static void ShowBanner(String args) {
7675

7776
if (gDshowObj.isInterstitial) {
7877
if (GDstatic.reqInterstitialEnabled) {
79-
GDlogger.gDad.setmUnitId(GDstatic.adUnit);
8078
GDlogger.gDad.showBanner(args);
8179
adInterstitialTimer = null;
8280
setAdTimer(true); // inter timer
@@ -86,7 +84,6 @@ protected static void ShowBanner(String args) {
8684
}
8785
} else {
8886
if (GDstatic.reqBannerEnabled) {
89-
GDlogger.gDad.setmUnitId(GDstatic.adUnit);
9087
GDlogger.gDad.showBanner(args);
9188
adBannerTimer = null;
9289
setAdTimer(false); // banner timer

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

Lines changed: 0 additions & 93 deletions
This file was deleted.

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

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.gd.analytics;
22

33
import android.app.Activity;
4-
import android.content.SharedPreferences;
5-
import android.preference.PreferenceManager;
6-
import android.support.annotation.Nullable;
74
import android.util.Log;
85

96
import com.google.android.gms.common.ConnectionResult;
@@ -13,8 +10,9 @@
1310
public class GDlogger {
1411

1512
static Activity mContext;
16-
static SharedPreferences appSharedPrefs;
1713
static GDad gDad;
14+
static boolean isCordovaPlugin = false;
15+
1816

1917
/**
2018
* Initialize Game Distribution Java API
@@ -37,9 +35,6 @@ public static void init(String gameId, String regId, Activity _mContext) {
3735
} else {
3836
mContext = _mContext;
3937
gDad = new GDad();
40-
gDad.init(GDlogger.mContext);
41-
42-
appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext.getApplicationContext());
4338

4439
String[] gameserver = regId.toLowerCase().split("-");
4540
GDstatic.serverId = gameserver[5];
@@ -54,36 +49,11 @@ public static void init(String gameId, String regId, Activity _mContext) {
5449
}
5550

5651
public static void init(String gameId, String regId, Activity _mContext, boolean isCordovaPlugin) {
57-
5852
if (isCordovaPlugin) {
59-
mContext = _mContext;
60-
61-
if (!checkPlayServices(_mContext)) {
62-
GDutils.log("Google play services out of date. Update it in order to use GDApi properly.");
63-
}
64-
65-
if (GDstatic.enable) {
66-
GDutils.log("API is already Initilized.");
67-
} else {
68-
mContext = _mContext;
69-
gDad = new GDad();
70-
gDad.init(GDlogger.mContext, true);
71-
72-
appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext.getApplicationContext());
73-
74-
String[] gameserver = regId.toLowerCase().split("-");
75-
GDstatic.serverId = gameserver[5];
76-
GDstatic.regId = gameserver[0] + "-" + gameserver[1] + "-" + gameserver[2] + "-" + gameserver[3] + "-" + gameserver[4];
77-
GDstatic.gameId = gameId;
78-
GDstatic.enable = true;
79-
80-
GDbanner.init();
81-
GDutils.log("Game Distribution Android API Init");
82-
}
83-
} else {
84-
init(gameId, regId, _mContext);
53+
GDlogger.isCordovaPlugin = true;
8554
}
8655

56+
init(gameId, regId, _mContext);
8757

8858
}
8959

@@ -94,6 +64,13 @@ public static void debug(Boolean enable) {
9464
GDstatic.debug = enable;
9565
}
9666

67+
/**
68+
* GDlogger enables test ads
69+
*/
70+
public static void EnableTestAds(Boolean test) {
71+
GDstatic.testAds = test;
72+
}
73+
9774
/**
9875
* GDlogger shows banner
9976
*/

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class GDstatic {
1212
protected static String gameId;
1313
protected static boolean reqBannerEnabled = true;
1414
protected static boolean reqInterstitialEnabled = true;
15-
protected static String adUnit;
15+
protected static String adUnit = "ca-app-pub-3940256099942544/4411468910"; // currently it is test.
16+
protected static String testAdxUnitId = "ca-app-pub-3940256099942544/4411468910";
17+
protected static String cordovaAdxUnitId = "ca-mb-app-pub-5192618204358860/8119020012";
18+
protected static boolean testAds = false;
1619
protected static String affiliateId;
1720
}

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

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)