Java 类com.google.android.gms.ads.mediation.customevent.CustomEventInterstitialListener 实例源码

项目:googleads-mobile-android-mediation    文件:SampleCustomEvent.java   
@Override
public void requestInterstitialAd(Context context,
                                  CustomEventInterstitialListener listener,
                                  String serverParameter,
                                  MediationAdRequest mediationAdRequest,
                                  Bundle customEventExtras) {
    /*
     * In this method, you should:
     *
     * 1. Create your interstitial ad.
     * 2. Set your ad network's listener.
     * 3. Make an ad request.
     *
     * When setting your ad network's listener, don't forget to send the following callbacks:
     *
     * listener.onAdLoaded(this);
     * listener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_*);
     * listener.onAdOpened(this);
     * listener.onAdLeftApplication(this);
     * listener.onAdClosed(this);
     */

    mSampleInterstitial = new SampleInterstitial(context);

    // Here we're assuming the serverParameter is the ad unit for the Sample Ad Network.
    mSampleInterstitial.setAdUnit(serverParameter);

    // Implement a SampleAdListener and forward callbacks to mediation.
    mSampleInterstitial.setAdListener(new SampleCustomInterstitialEventForwarder(listener));

    // Make an ad request.
    mSampleInterstitial.fetchAd(createSampleRequest(mediationAdRequest));
}
项目:mytarget-android    文件:MyTargetAdmobCustomEventInterstitial.java   
@Override
public void requestInterstitialAd(Context context,
                                  CustomEventInterstitialListener
                                          customEventInterstitialListener,
                                  String serverParameter,
                                  MediationAdRequest mediationAdRequest,
                                  Bundle bundle)
{
    this.interstitialListener = customEventInterstitialListener;

    int slotId;
    try
    {
        JSONObject json = new JSONObject(serverParameter);
        slotId = json.getInt(SLOT_ID_KEY);
    } catch (JSONException e)
    {
        Log.i(TAG, "Unable to get slotId from parameter json. Probably Admob mediation " +
                "misconfiguration.");
        if (interstitialListener != null)
        {
            interstitialListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INTERNAL_ERROR);
        }
        return;
    }

    interstitial = new InterstitialAd(slotId, context);
    interstitial.getCustomParams().setCustomParam("mediation", "1");
    if (mediationAdRequest != null)
    {
        interstitial.getCustomParams().setGender(mediationAdRequest.getGender());
        Date date = mediationAdRequest.getBirthday();
        if (date != null && date.getTime() != -1)
        {
            GregorianCalendar calendar = new GregorianCalendar();
            GregorianCalendar calendarNow = new GregorianCalendar();

            calendar.setTimeInMillis(date.getTime());
            int a = calendarNow.get(GregorianCalendar.YEAR) -
                    calendar.get(GregorianCalendar.YEAR);
            if (a >= 0)
            {
                interstitial.getCustomParams().setAge(a);
            }
        }
    }
    interstitial.setListener(interstitialAdListener);
    interstitial.load();
}
项目:SDK-Network-Adaptors    文件:AppLovinCustomEventInterstitial.java   
@Override
public void requestInterstitialAd(final Context context, final CustomEventInterstitialListener listener, final String serverParameter, final MediationAdRequest mediationAdRequest, final Bundle customEventExtras)
{
    log( DEBUG, "Requesting AppLovin interstitial..." );

    // SDK versions BELOW 7.2.0 require a instance of an Activity to be passed in as the context
    if ( AppLovinSdk.VERSION_CODE < 720 && !( context instanceof Activity ) )
    {
        log( ERROR, "Unable to request AppLovin interstitial. Invalid context provided." );
        listener.onAdFailedToLoad( AdRequest.ERROR_CODE_INVALID_REQUEST );

        return;
    }

    // Store parent objects
    this.listener = listener;
    this.context = context;

    final AppLovinSdk sdk = AppLovinSdk.getInstance( context );
    sdk.setPluginVersion( "AdMob-2.0" );

    // Zones support is available on AppLovin SDK 7.5.0 and higher
    if ( AppLovinSdk.VERSION_CODE >= 750 && customEventExtras != null && customEventExtras.containsKey( "zone_id" ) )
    {
        zoneId = customEventExtras.getString( "zone_id" );
    }
    else
    {
        zoneId = DEFAULT_ZONE;
    }

    // Check if we already have a preloaded ad for the given zone
    final AppLovinAd preloadedAd = dequeueAd( zoneId );
    if ( preloadedAd != null )
    {
        log( DEBUG, "Found preloaded ad for zone: {" + zoneId + "}" );
        adReceived( preloadedAd );
    }
    else
    {
        // If this is a default Zone, load the interstitial ad normally
        if ( DEFAULT_ZONE.equals( zoneId ) )
        {
            sdk.getAdService().loadNextAd( AppLovinAdSize.INTERSTITIAL, this );
        }
        // Otherwise, use the Zones API
        else
        {
            // Dynamically load an ad for a given zone without breaking backwards compatibility for publishers on older SDKs
            try
            {
                final Method method = sdk.getAdService().getClass().getMethod( "loadNextAdForZoneId", String.class, AppLovinAdLoadListener.class );
                method.invoke( sdk.getAdService(), zoneId, this );
            }
            catch ( Throwable th )
            {
                log( ERROR, "Unable to load ad for zone: " + zoneId + "..." );
                listener.onAdFailedToLoad( AdRequest.ERROR_CODE_INVALID_REQUEST );
            }
        }
    }
}
项目:googleads-mobile-android-mediation    文件:SampleCustomInterstitialEventForwarder.java   
/**
 * Creates a new {@code SampleInterstitialEventForwarder}.
 * @param listener An AdMob Mediation {@link CustomEventInterstitialListener} that should
 *                 receive forwarded events.
 */
public SampleCustomInterstitialEventForwarder(CustomEventInterstitialListener listener) {
    this.mInterstitialListener = listener;
}