Menu

Splash Ad

1. Implementation of abstract methods for open-screen ads and callbacks for advertising events

1.1 Abstract methods that require additional implementation for open-screen ads

MethodParametersReturn valueDescriptionWhether it must be implemented
showActivity activity: Activity ViewGroup container: Container of advoidShow splash adYes

The CustomiSplashAdapter provides a member variable for the ad loading timeout time, which is the fetchAdTimeout variable passed in by developers through the ATSplashAd construction method. This variable can be used to set the timeout time for the advertising platform.

1.2 Open screen advertising event callback

Use the CustomSplashEventListener member variable of CustomSplashAdapter to implement Advertising event callback

Callback methodParameter descriptionDescription
onSplashAdClicked-Callback to the developer when the ad is clicked
onSplashAdShow-Callback to the developer when the ad is displayed
onSplashAdDismiss-Callback to the developer executed when the ad is closed

Note: When using the member variable CustomSplashEventListener, you need to perform null processing because there are The Listener object may be recycled.

1.3 Sample Code

public class PangleSplashAdapter extends CustomSplashAdapter implements TTSplashAd.AdInteractionListener {
    private final String TAG = getClass().getSimpleName();

    String appId = "";
    String slotId = "";
    String personalizedTemplate = "";

    TTSplashAd splashAd;

    @Override
    public void loadCustomNetworkAd(final Context context, Map<String, Object> serverExtra, final Map<String, Object> localExtra) {
        if (serverExtra.containsKey("app_id") && serverExtra.containsKey("slot_id")) {
            appId = (String) serverExtra.get("app_id");
            slotId = (String) serverExtra.get("slot_id");

        } else {
            if (mLoadListener != null) {
                mLoadListener.onAdLoadError("", "app_id or slot_id is empty!");
            }
            return;
        }

        personalizedTemplate = "0";
        if (serverExtra.containsKey("personalized_template")) {
            personalizedTemplate = (String) serverExtra.get("personalized_template");
        }

        PangleInitManager.getInstance().initSDK(context, serverExtra, true, new PangleInitManager.InitCallback() {
            @Override
            public void onFinish() {
                startLoad(context, localExtra);
            }
        });
    }

    private void startLoad(Context context, Map<String, Object> localExtra) {
        TTAdManager ttAdManager = TTAdSdk.getAdManager();

        final TTAdNative mTTAdNative = ttAdManager.createAdNative(context);//baseContext is recommended for activity
        final AdSlot.Builder adSlotBuilder = new AdSlot.Builder().setCodeId(slotId);

        int width = 0;
        int height = 0;
        try {
            if (localExtra.containsKey(ATAdConst.KEY.AD_WIDTH)) {
                width = Integer.parseInt(localExtra.get(ATAdConst.KEY.AD_WIDTH).toString());
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }

        try {
            if (localExtra.containsKey(ATAdConst.KEY.AD_HEIGHT)) {
                height = Integer.parseInt(localExtra.get(ATAdConst.KEY.AD_HEIGHT).toString());
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }

        adSlotBuilder.setImageAcceptedSize(width, height); //Must be set

        if (TextUtils.equals("1", personalizedTemplate)) {// Native Express
            adSlotBuilder.setExpressViewAcceptedSize(width, height);
        }

        postOnMainThread(new Runnable() {
            @Override
            public void run() {
                AdSlot adSlot = adSlotBuilder.build();
                mTTAdNative.loadSplashAd(adSlot, new TTAdNative.SplashAdListener() {
                    @Override
                    public void onError(int i, String s) {
                        if (mLoadListener != null) {
                            mLoadListener.onAdLoadError(i + "", s);
                        }
                    }

                    @Override
                    public void onTimeout() {
                        if (mLoadListener != null) {
                            mLoadListener.onAdLoadError("", "onTimeout");
                        }
                    }

                    @Override
                    public void onSplashAdLoad(TTSplashAd ttSplashAd) {
                        splashAd = ttSplashAd;
                        if (mLoadListener != null) {
                            mLoadListener.onAdCacheLoaded();
                        }
                    }
                }, mFetchAdTimeout);
            }
        });

    }

    @Override
    public boolean isAdReady() {
        return splashAd != null;
    }

    @Override
    public void show(Activity activity, ViewGroup container) {
        if (splashAd != null) {
            splashAd.setSplashInteractionListener(PangleSplashAdapter.this);
            View splashView = splashAd.getSplashView();
            if (splashView != null) {
                container.addView(splashView);
            }
        }
    }

    @Override
    public String getNetworkName() {
        return PangleInitManager.getInstance().getNetworkName();
    }

    @Override
    public void destory() {

    }

    @Override
    public String getNetworkPlacementId() {
        return slotId;
    }

    @Override
    public String getNetworkSDKVersion() {
        return PangleInitManager.getInstance().getNetworkVersion();
    }

    @Override
    public void onAdClicked(View view, int i) {
        if (mImpressionListener != null) {
            mImpressionListener.onSplashAdClicked();
        }

    }

    @Override
    public void onAdShow(View view, int i) {
        if (mImpressionListener != null) {
            mImpressionListener.onSplashAdShow();
        }

    }

    @Override
    public void onAdSkip() {
        if (mImpressionListener != null) {
            mImpressionListener.onSplashAdDismiss();
        }
    }

    @Override
    public void onAdTimeOver() {
        if (mImpressionListener != null) {
            mImpressionListener.onSplashAdDismiss();
        }
    }

}


Previous
Native Ad
Next
Custom Client Bidding Network
Last modified: 2025-05-30Powered by