Last active
June 24, 2016 06:41
-
-
Save hendrawd/51d1eb6e4b593244347bc7171b47052a to your computer and use it in GitHub Desktop.
An helper class to load interstitial and overwall DU AD
This file contains 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
import android.app.Activity; | |
import android.content.Intent; | |
import android.util.Log; | |
import com.duapps.ad.AbsInterstitialListener; | |
import com.duapps.ad.InterstitialAd; | |
import com.duapps.ad.offerwall.ui.OfferWallAct; | |
/** | |
* @author hendrawd on 6/24/16 | |
*/ | |
public class DuAdHelper { | |
private static final String TAG = DuAdHelper.class.getSimpleName(); | |
private static final InterstitialAd.Type AD_TYPE = InterstitialAd.Type.SCREEN; | |
private static InterstitialAd interstitialAd; | |
private static InterstitialAd getInterstitialAd(Activity activity, int pid) { | |
if (interstitialAd == null) { | |
interstitialAd = new InterstitialAd(activity, pid, AD_TYPE); | |
} | |
return interstitialAd; | |
} | |
public static void fillInterstitial(Activity activity, int pid) { | |
getInterstitialAd(activity, pid).fill(); | |
} | |
public static void showInterstitial(Activity activity, int pid) { | |
getInterstitialAd(activity, pid).setInterstitialListener(new AbsInterstitialListener() { | |
@Override | |
public void onAdFail(int errCode) { | |
Log.d(TAG, "call to onAdFail, errCode(" + errCode + ")"); | |
} | |
@Override | |
public void onAdReceive() { | |
Log.d(TAG, "call to onAdReceive()!"); | |
interstitialAd.show(); | |
} | |
}); | |
interstitialAd.load(); | |
} | |
/** | |
* Call this method from the caller Activity's onStop() | |
*/ | |
public static void closeInterstitial() { | |
if (interstitialAd != null) { | |
interstitialAd.close(); | |
} | |
} | |
/** | |
* Call this method from the caller Activity's onDestroy() | |
*/ | |
public static void destroyInterstitial() { | |
if (interstitialAd != null) { | |
interstitialAd.destory(); | |
} | |
} | |
public static void showOverwall(Activity activity, int pid) { | |
Intent intent = new Intent(activity, OfferWallAct.class); | |
intent.putExtra("pid", pid); | |
activity.startActivity(intent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment