129 lines
3.7 KiB
Java
129 lines
3.7 KiB
Java
package com.keyboardskinning.theme.tools;
|
|
|
|
import android.app.Activity;
|
|
import android.util.Log;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import com.applovin.mediation.MaxAd;
|
|
import com.applovin.mediation.MaxAdListener;
|
|
import com.applovin.mediation.MaxError;
|
|
import com.applovin.mediation.ads.MaxInterstitialAd;
|
|
import com.keyboardskinning.theme.mylistener.AdCallback;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
public class Admanager {
|
|
|
|
public static final String unit1 = "aa5f1b6007e164bb";
|
|
public static final String unit2 = "2508a453b5762c26";
|
|
public static final String unit3 = "15208b32ede43744";
|
|
|
|
public static MaxInterstitialAd show(List<MaxInterstitialAd> ads) {
|
|
Collections.shuffle(ads);
|
|
for (int g = 0; g < ads.size(); g++) {
|
|
MaxInterstitialAd maxInterstitialAd = ads.get(g);
|
|
if (maxInterstitialAd.isReady()) {
|
|
return maxInterstitialAd;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static void setAdShowCall(MaxInterstitialAd ad, AdCallback adListener) {
|
|
ad.setListener(new MaxAdListener() {
|
|
@Override
|
|
public void onAdLoaded(@NonNull MaxAd maxAd) {
|
|
if (adListener != null) {
|
|
adListener.onLoadSuccess(maxAd);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onAdDisplayed(@NonNull MaxAd maxAd) {
|
|
|
|
if (adListener != null) {
|
|
adListener.onShowSuccess(maxAd);
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onAdHidden(@NonNull MaxAd maxAd) {
|
|
if (adListener != null) {
|
|
adListener.onHidden();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onAdClicked(@NonNull MaxAd maxAd) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onAdLoadFailed(@NonNull String s, @NonNull MaxError maxError) {
|
|
if (adListener != null) {
|
|
adListener.onLoadFail(s, maxError);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onAdDisplayFailed(@NonNull MaxAd maxAd, @NonNull MaxError maxError) {
|
|
if (adListener != null) {
|
|
adListener.onShowFail(maxAd);
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
public static List<MaxInterstitialAd> initMyAd(Activity mActivity) {
|
|
MaxInterstitialAd ad1 = new MaxInterstitialAd(unit1, mActivity);
|
|
ad1.setListener(new MaxAdListener() {
|
|
@Override
|
|
public void onAdLoaded(@NonNull MaxAd maxAd) {
|
|
Log.d("-------","--------onAdLoaded ad1"+ad1.getAdUnitId());
|
|
}
|
|
|
|
@Override
|
|
public void onAdDisplayed(@NonNull MaxAd maxAd) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onAdHidden(@NonNull MaxAd maxAd) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onAdClicked(@NonNull MaxAd maxAd) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onAdLoadFailed(@NonNull String s, @NonNull MaxError maxError) {
|
|
Log.d("-------","--------onAdLoadFailed ad1"+ad1.getAdUnitId());
|
|
}
|
|
|
|
@Override
|
|
public void onAdDisplayFailed(@NonNull MaxAd maxAd, @NonNull MaxError maxError) {
|
|
|
|
}
|
|
});
|
|
ad1.loadAd();
|
|
MaxInterstitialAd ad2 = new MaxInterstitialAd(unit2, mActivity);
|
|
ad2.loadAd();
|
|
MaxInterstitialAd ad3 = new MaxInterstitialAd(unit3, mActivity);
|
|
ad3.loadAd();
|
|
ArrayList<MaxInterstitialAd> ads = new ArrayList<>();
|
|
ads.add(ad1);
|
|
ads.add(ad2);
|
|
ads.add(ad3);
|
|
return ads;
|
|
}
|
|
|
|
|
|
}
|