Skip to content

Instantly share code, notes, and snippets.

@jwyseu
Last active December 16, 2015 12:28
Show Gist options
  • Select an option

  • Save jwyseu/5434805 to your computer and use it in GitHub Desktop.

Select an option

Save jwyseu/5434805 to your computer and use it in GitHub Desktop.
Implementation of class-based integration of tapfortap in mopub as described at https://github.com/mopub/mopub-client/wiki/CustomEventsAndroid
package com.mopub.mobileads;
import java.util.Map;
import android.content.Context;
import com.tapfortap.TapForTap;
public class TapForTapCustomEventBanner extends CustomEventBanner implements com.tapfortap.AdView.AdViewListener {
private com.tapfortap.AdView tapForTapAdView;
private CustomEventBannerListener customEventBannerListener;
@Override
public void loadBanner(Context context, CustomEventBannerListener customEventBannerListener, Map<String, Object> localExtras,
Map<String, String> serverExtras) {
this.customEventBannerListener = customEventBannerListener;
if (tapForTapAdView == null) {
TapForTap.initialize(context, "<your id>");
tapForTapAdView = new com.tapfortap.AdView(context);
tapForTapAdView.autoRollover = false;
tapForTapAdView.setListener(this);
}
tapForTapAdView.loadAds();
}
@Override
public void onInvalidate() {
if (tapForTapAdView != null) {
tapForTapAdView.setListener(null);
tapForTapAdView = null;
}
}
@Override
public void onFailToReceiveAd(String arg0) {
if (customEventBannerListener != null) {
customEventBannerListener.onBannerFailed(MoPubErrorCode.UNSPECIFIED);
}
}
@Override
public void onReceiveAd() {
if (customEventBannerListener != null) {
customEventBannerListener.onBannerLoaded(tapForTapAdView);
}
}
@Override
public void onTapAd() {
if (customEventBannerListener != null) {
customEventBannerListener.onBannerClicked();
}
}
}
package com.mopub.mobileads;
import java.util.Map;
import android.content.Context;
import android.util.Log;
import com.tapfortap.Interstitial;
import com.tapfortap.Interstitial.InterstitialListener;
public class TapForTapCustomEventInterstitial extends CustomEventInterstitial implements InterstitialListener {
private Context context;
private CustomEventInterstitialListener customEventInterstitialListener;
@Override
public void loadInterstitial(Context context, CustomEventInterstitialListener customEventInterstitialListener, Map<String, Object> localExtras,
Map<String, String> serverExtras) {
Interstitial.prepare(context);
Interstitial.setListener(this);
this.context = context;
this.customEventInterstitialListener= customEventInterstitialListener;
}
@Override
public void showInterstitial() {
Interstitial.show(context);
}
@Override
public void onInvalidate() {
}
@Override
public void onDismiss() {
customEventInterstitialListener.onInterstitialDismissed();
}
@Override
public void onReceiveAd() {
customEventInterstitialListener.onInterstitialLoaded();
}
@Override
public void onFail(String message) {
Log.e("TapForTap", "Failed load : " + message);
customEventInterstitialListener.onInterstitialFailed(MoPubErrorCode.UNSPECIFIED);
}
@Override
public void onShow() {
customEventInterstitialListener.onInterstitialShown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment