Last active
October 14, 2015 01:58
-
-
Save pjlaird/4290335 to your computer and use it in GitHub Desktop.
Integrate Tap for Tap into MoPub on Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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