Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
buildbox 3.x custom appodeal sdk integration
package com.buildbox.adapter.custom;
import android.app.Activity;
import android.util.Log;
import com.appodeal.ads.Appodeal;
import com.appodeal.ads.BannerCallbacks;
import com.appodeal.ads.InterstitialCallbacks;
import com.appodeal.ads.RewardedVideoCallbacks;
import com.appodeal.ads.api.App;
import com.buildbox.AdIntegratorManager;
import com.buildbox.CustomIntegrator;
import com.buildbox.adapter.AdIntegratorInterface;
import com.explorestack.consent.Consent;
import java.lang.ref.WeakReference;
import java.util.HashMap;
public class AdIntegrator implements AdIntegratorInterface, CustomIntegrator {
private static String customNetworkName = "Appodeal";
private static String adNetworkId = "custom";
private static String TAG = "Appodeal Custom Adapter";
private static Activity activity;
//Modify these.
private String appodealKey = " ";
private boolean hasConsent = false;
private int adTypes = Appodeal.INTERSTITIAL | Appodeal.REWARDED_VIDEO | Appodeal.BANNER;
private int bannerPosition = Appodeal.BANNER_BOTTOM;
private boolean isBannerVisible = false;
/**
* Use this method to initialize the Ad network only. Do not start loading ads here. If you are supporting banners,
* then make sure to set the bannerView to View.GONE to start
* @param initValues - Ignore this for custom integration
* @param act - Use activity if you need a reference to activity or context
*/
@Override
public void initAds(HashMap<String, String> initValues, WeakReference<Activity> act) {
activity = act.get();
//Use this method to initialize the Ad network only. Do not start loading ads here. If you are supporting banners,
//then make sure to set them to a GONE/hidden state to start
Appodeal.setInterstitialCallbacks(new InterstitialCallbacks() {
@Override
public void onInterstitialLoaded(boolean b) {
Log.d(TAG, "interstitial loaded");
AdIntegratorManager.interstitialLoaded(adNetworkId);
}
@Override
public void onInterstitialFailedToLoad() {
Log.d(TAG, "interstitial loaded");
AdIntegratorManager.interstitialFailed(adNetworkId);
}
@Override
public void onInterstitialShown() {
}
@Override
public void onInterstitialShowFailed() {
}
@Override
public void onInterstitialClicked() {
}
@Override
public void onInterstitialClosed() {
AdIntegratorManager.interstitialClosed(adNetworkId);
}
@Override
public void onInterstitialExpired() {
}
});
Appodeal.setBannerCallbacks(new BannerCallbacks() {
@Override
public void onBannerLoaded(int i, boolean b) {
AdIntegratorManager.bannerLoaded(adNetworkId);
}
@Override
public void onBannerFailedToLoad() {
AdIntegratorManager.bannerFailed(adNetworkId);
}
@Override
public void onBannerShown() {
isBannerVisible = false;
}
@Override
public void onBannerShowFailed() {
}
@Override
public void onBannerClicked() {
}
@Override
public void onBannerExpired() {
}
});
Appodeal.setRewardedVideoCallbacks(new RewardedVideoCallbacks() {
@Override
public void onRewardedVideoLoaded(boolean b) {
AdIntegratorManager.rewardedVideoLoaded(adNetworkId);
}
@Override
public void onRewardedVideoFailedToLoad() {
AdIntegratorManager.rewardedVideoFailed(adNetworkId);
}
@Override
public void onRewardedVideoShown() {
}
@Override
public void onRewardedVideoShowFailed() {
}
@Override
public void onRewardedVideoFinished(double v, String s) {
AdIntegratorManager.rewardedVideoDidEnd(adNetworkId, true);
}
@Override
public void onRewardedVideoClosed(boolean b) {
}
@Override
public void onRewardedVideoExpired() {
}
@Override
public void onRewardedVideoClicked() {
}
});
try {
Appodeal.initialize(activity, appodealKey, adTypes, hasConsent);
Log.i(TAG, "appodeal ad integrator init success");
networkLoaded();
} catch (Exception ex) {
Log.e(TAG, "appodeal ad integrator init failed " + ex.getMessage());
networkFailed();
}
}
@Override
public void initBanner() {
}
@Override
public void initInterstitial() {
}
@Override
public void initRewardedVideo() {
}
@Override
public void showBanner() {
Appodeal.show(activity, bannerPosition);
}
@Override
public void hideBanner() {
Appodeal.hide(activity, Appodeal.BANNER);
isBannerVisible = false;
}
@Override
public void showInterstitial() {
Appodeal.show(activity, Appodeal.INTERSTITIAL);
}
@Override
public void showRewardedVideo() {
Appodeal.show(activity, Appodeal.REWARDED_VIDEO);
}
@Override
public boolean isBannerVisible() {
return isBannerVisible;
}
@Override
public boolean isRewardedVideoAvailable() {
//return true if a rewarded video is loaded and ready to show
return Appodeal.isLoaded(Appodeal.REWARDED_VIDEO);
}
@Override
public void setUserConsent(boolean consentGiven) {
hasConsent = consentGiven;
}
/**
* Call this method when a user closes an interstitial
*/
@Override
public void interstitialClosed() {
}
/**
* Call this method passing true if a rewarded video reward is successfully received.
* Call this method passing false if a rewarded video
* @param value - was a reward received
*/
@Override
public void rewardedVideoDidReward(boolean value) {
}
/**
* Call this method passing true if a rewarded video completes without failure
* Call this method passing false if a rewarded video fails to show
* @param value - did the video complete without failure
*/
@Override
public void rewardedVideoDidEnd(boolean value) {
}
/**
* Call this method when the network is initialized
*/
@Override
public void networkLoaded() {
Log.d(TAG, "Network loaded");
AdIntegratorManager.sdkLoaded(adNetworkId);
}
/**
* Call this method when a banner is successfully loaded
*/
@Override
public void bannerLoaded() {
}
/**
* Call this method when an interstitial is successfully loaded
*/
@Override
public void interstitialLoaded() {
}
/**
* Call this method when a rewarded video is successfully loaded
*/
@Override
public void rewardedVideoLoaded() {
}
/**
* Call this method when if a network fails
*/
@Override
public void networkFailed() {
Log.d(TAG, "network failed");
AdIntegratorManager.sdkFailed(adNetworkId);
}
/**
* Call this method when a banner fails for any reason
*/
@Override
public void bannerFailed() {
Log.d(TAG, "banner failed");
AdIntegratorManager.bannerFailed(adNetworkId);
}
/**
* Call this method when an interstitial fails for any reason
*/
@Override
public void interstitialFailed() {
Log.d(TAG, "interstitial failed");
AdIntegratorManager.interstitialFailed(adNetworkId);
}
/**
* Call this method when a rewarded video fails for any reason
*/
@Override
public void rewardedVideoFailed() {
Log.d(TAG, "rewarded video failed");
AdIntegratorManager.rewardedVideoFailed(adNetworkId);
}
@Override
public void onActivityCreated(Activity activity) {
//Use this method for handling activity lifecycle if the network requires it
}
@Override
public void onActivityStarted(Activity activity) {
//Use this method for handling activity lifecycle if the network requires it
}
@Override
public void onActivityResumed(Activity activity) {
//Use this method for handling activity lifecycle if the network requires it
}
@Override
public void onActivityPaused(Activity activity) {
//Use this method for handling activity lifecycle if the network requires it
}
@Override
public void onActivityStopped(Activity activity) {
//Use this method for handling activity lifecycle if the network requires it
}
@Override
public void onActivityDestroyed(Activity activity) {
//Use this method for handling activity lifecycle if the network requires it
}
@Override
public void loadingDidComplete() {
// This is a legacy call for plugging this custom SDK into the game lifecycle. If unsure, leave this be
}
@Override
public void screenOnEnter(String screenName) {
// This is a legacy call for plugging this custom SDK into the game lifecycle. If unsure, leave this be
}
@Override
public void screenOnExit(String screenName) {
// This is a legacy call for plugging this custom SDK into the game lifecycle. If unsure, leave this be
}
@Override
public void sceneOnEnter(String sceneName) {
// This is a legacy call for plugging this custom SDK into the game lifecycle. If unsure, leave this be
}
@Override
public void sceneOnExit(String sceneName) {
// This is a legacy call for plugging this custom SDK into the game lifecycle. If unsure, leave this be
}
@Override
public void buttonActivated(String buttonName) {
// This is a legacy call for plugging this custom SDK into the game lifecycle. If unsure, leave this be
}
@Override
public boolean buttonVisible(String buttonName) {
// This is a legacy call for plugging this custom SDK into the game lifecycle. If unsure, leave this be
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment