Skip to content

Instantly share code, notes, and snippets.

@pjlaird
Last active October 14, 2015 01:58
Show Gist options
  • Select an option

  • Save pjlaird/4290335 to your computer and use it in GitHub Desktop.

Select an option

Save pjlaird/4290335 to your computer and use it in GitHub Desktop.
Integrate Tap for Tap into MoPub on Android
package com.tapfortap.mopub.example;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import com.mopub.mobileads.MoPubView;
import com.tapfortap.AdView;
import com.tapfortap.AdView.AdViewListener;
import com.tapfortap.TapForTap;
public class MyActivity extends Activity implements com.tapfortap.AdView.AdViewListener {
private AdView tapForTapAdView;
private MoPubView moPubView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mob_pub);
TapForTap.initialize(this, "YOUT API KEY");
moPubView = new MoPubView(this);
moPubView.setAdUnitId("AD UNIT ID");
moPubView.loadAd();
}
public void tapForTapCustomEvent(MoPubView view) {
if(tapForTapAdView == null ) {
tapForTapAdView = new AdView(this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(view.getAdWidth(), view.getAdHeight());
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
tapForTapAdView.setLayoutParams(layoutParams);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.activity_mo_pub);
layout.addView(tapForTapAdView);
tapForTapAdView.autoRollover = false;
tapForTapAdView.setListener(this);
}
tapForTapAdView.loadAds();
}
@Override
public void onReceiveAd() {
moPubView.customEventDidLoadAd();
}
@Override
public void onFailToReceiveAd(String reason) {
moPubView.customEventDidFailToLoadAd();
}
@Override
public void onTapAd() {
moPubView.customEventActionWillBegin();
}
@Override
public void onDestroy() {
if (tapForTapAdView != null) {
tapForTapAdView.setListener(null);
tapForTapAdView = null;
}
moPubView.destroy();
super.onDestroy();
}
}
@jwyseu

jwyseu commented Apr 23, 2013

Copy link
Copy Markdown

This uses the old method way of extending mopub. There is a new class based way to do this. I transformed your example to this at https://gist.github.com/jwyseu/5434805

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment