Skip to content

Instantly share code, notes, and snippets.

@hendrawd
Last active June 24, 2016 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hendrawd/51d1eb6e4b593244347bc7171b47052a to your computer and use it in GitHub Desktop.
Save hendrawd/51d1eb6e4b593244347bc7171b47052a to your computer and use it in GitHub Desktop.
An helper class to load interstitial and overwall DU AD
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