-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBannerAutoRefreshActivity.java
87 lines (64 loc) · 2.85 KB
/
BannerAutoRefreshActivity.java
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
package ubermedia.com.headerbiddingdemo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.mopub.mobileads.MoPubErrorCode;
import com.mopub.mobileads.MoPubView;
import ubermedia.com.ubermedia.ClearBid;
public class BannerAutoRefreshActivity extends AppCompatActivity implements MoPubView.BannerAdListener {
private final String CLASS_TAG = "ClearBid";
/* Insert your own ClearBid and MoPub ad units here */
private final String adUnit = "";
private final String moPubAdUnit = "";
private MoPubView mBannerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_banner_auto_refresh);
// You only need to call this method once in the app, usually from the MainActivity
ClearBid.initializeClearBidSDK(this, "insert api key", "insert secret key");
ClearBid.requestLocationPermission(this);
ClearBid.preCacheAdPlacement(getApplicationContext(), adUnit, new int[]{320, 50});
//ClearBid.DisableLogging();
String targetKeywords = ClearBid.getTargetParamsAsString(adUnit);
Log.d(CLASS_TAG, targetKeywords);
mBannerView = (MoPubView) findViewById(R.id.bannerAutoRefreshView);
mBannerView.setAdUnitId(moPubAdUnit);
mBannerView.setKeywords(targetKeywords);
mBannerView.setBannerAdListener(BannerAutoRefreshActivity.this);
mBannerView.setAutorefreshEnabled(true);
mBannerView.loadAd();
}
@Override
public void onBannerLoaded(MoPubView banner) {
Log.d(CLASS_TAG, "onBannerLoaded");
// Cache a new ad
ClearBid.preCacheAdPlacement(getApplicationContext(), adUnit, new int[]{320, 50});
String targetKeywords = ClearBid.getTargetParamsAsString(adUnit);
mBannerView.setKeywords(targetKeywords);
Log.d(CLASS_TAG, targetKeywords);
}
@Override
public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode) {
Log.d(CLASS_TAG, "onBannerFailed: " + errorCode.toString());
// Cache a new ad
ClearBid.preCacheAdPlacement(getApplicationContext(), adUnit, new int[]{320, 50});
String targetKeywords = ClearBid.getTargetParamsAsString(adUnit);
mBannerView.setKeywords(targetKeywords);
Log.d(CLASS_TAG, targetKeywords);
Log.d(CLASS_TAG, "No ad was received. Call your app waterfall here.");
// Call your app waterfall here
}
@Override
public void onBannerClicked(MoPubView banner) {
Log.d(CLASS_TAG, "onBannerClicked");
}
@Override
public void onBannerExpanded(MoPubView banner) {
Log.d(CLASS_TAG, "onBannerExpanded");
}
@Override
public void onBannerCollapsed(MoPubView banner) {
Log.d(CLASS_TAG, "onBannerCollapsed");
}
}