Skip to content

Instantly share code, notes, and snippets.

@pjlaird
Last active December 22, 2015 16:58
Show Gist options
  • Save pjlaird/6502734 to your computer and use it in GitHub Desktop.
Save pjlaird/6502734 to your computer and use it in GitHub Desktop.
Android MoPub custom events for TapForTap SDK v3
package com.tapfortap.mopub;
import android.content.Context;
import com.mopub.mobileads.CustomEventBanner;
import com.mopub.mobileads.MoPubErrorCode;
import com.tapfortap.Banner;
import com.tapfortap.TapForTap;
import java.util.Map;
public class MoPubCustomBanner extends CustomEventBanner implements Banner.BannerListener {
private Banner banner;
private CustomEventBannerListener customEventBannerListener;
@Override
public void loadBanner(Context context, CustomEventBannerListener customEventBannerListener, Map<String, Object> localExtras, Map<String, String> serverExtras) {
this.customEventBannerListener = customEventBannerListener;
if (banner == null) {
// String apiKey = serverExtras.get("tft_api_key");
String apiKey = "YOUR_API_KEY";
// if (apiKey != null) {
TapForTap.initialize(context, apiKey);
// }
banner = Banner.create(context, this);
banner.enableForceLoad();
banner.disableAutoRollover();
}
banner.startShowingAds();
}
@Override
public void onInvalidate() {
if (banner != null) {
banner.setListener(null);
banner = null;
}
}
@Override
public void bannerOnReceive(Banner banner) {
if (customEventBannerListener != null) {
customEventBannerListener.onBannerLoaded(banner);
}
}
@Override
public void bannerOnFail(Banner banner, String s, Throwable throwable) {
if (customEventBannerListener != null) {
customEventBannerListener.onBannerFailed(MoPubErrorCode.UNSPECIFIED);
}
}
@Override
public void bannerOnTap(Banner banner) {
if (customEventBannerListener != null) {
customEventBannerListener.onBannerClicked();
}
}
}
package com.tapfortap.mopub;
import android.content.Context;
import android.util.Log;
import com.mopub.mobileads.CustomEventInterstitial;
import com.mopub.mobileads.MoPubErrorCode;
import com.tapfortap.Interstitial;
import com.tapfortap.Interstitial.InterstitialListener;
import com.tapfortap.TapForTap;
import java.util.Map;
public class MoPubCustomInterstitial extends CustomEventInterstitial implements InterstitialListener {
private Interstitial interstitial;
private CustomEventInterstitialListener customEventInterstitialListener;
@Override
public void loadInterstitial(Context context, CustomEventInterstitialListener customEventInterstitialListener, Map<String, Object> localExtras, Map<String, String> serverExtras) {
this.customEventInterstitialListener= customEventInterstitialListener;
if (interstitial == null) {
// String apiKey = serverExtras.get("tft_api_key");
String apiKey = "YOUR_API_KEY";
// if (apiKey != null) {
TapForTap.initialize(context, apiKey);
// }
interstitial = Interstitial.create(context, this);
}
}
@Override
public void showInterstitial() {
interstitial.show();
}
@Override
public void onInvalidate() {
interstitial = null;
}
@Override
public void interstitialOnReceive(Interstitial interstitial) {
customEventInterstitialListener.onInterstitialLoaded();
}
@Override
public void interstitialOnFail(Interstitial interstitial, String message, Throwable throwable) {
Log.e("TapForTap", "Failed load : " + message);
customEventInterstitialListener.onInterstitialFailed(MoPubErrorCode.UNSPECIFIED);
}
@Override
public void interstitialOnTap(Interstitial interstitial) {
customEventInterstitialListener.onInterstitialClicked();
}
@Override
public void interstitialOnShow(Interstitial interstitial) {
customEventInterstitialListener.onInterstitialShown();
}
@Override
public void interstitialOnDismiss(Interstitial interstitial) {
customEventInterstitialListener.onInterstitialDismissed();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment