Java Code Examples for com.google.android.gms.ads.doubleclick.PublisherAdView#setAdListener()

The following examples show how to use com.google.android.gms.ads.doubleclick.PublisherAdView#setAdListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GooglePlayDFPBanner.java    From mobile-sdk-android with Apache License 2.0 6 votes vote down vote up
/**
 * Interface called by the AN SDK to request an ad from the mediating SDK.
 *
 * @param mBC                 the object which will be called with events from the 3rd party SDK
 * @param activity            the activity from which this is launched
 * @param parameter           String parameter received from the server for instantiation of this object
 * @param adUnitID            The 3rd party placement, in DFP this is the adUnitID
 * @param width               Width of the ad
 * @param height              Height of the ad
 * @param targetingParameters targetingParameters
 */
@Override
public View requestAd(MediatedBannerAdViewController mBC, Activity activity, String parameter, String adUnitID,
                      int width, int height, TargetingParameters targetingParameters) {

    adListener = new GooglePlayAdListener(mBC, super.getClass().getSimpleName());
    adListener.printToClog(String.format(" - requesting an ad: [%s, %s, %dx%d]",
            parameter, adUnitID, width, height));

    DFBBannerSSParameters ssparm = new DFBBannerSSParameters(parameter);
    AdSize adSize = ssparm.isSmartBanner ? AdSize.SMART_BANNER : new AdSize(width, height);

    adView = new PublisherAdView(activity);
    adView.setAdUnitId(adUnitID);
    adView.setAdSizes(adSize);
    adView.setAdListener(adListener);
    adView.setAppEventListener(adListener);

    adView.loadAd(buildRequest(ssparm, targetingParameters));

    return adView;
}
 
Example 2
Source File: AdMobPlugin.java    From cordova-admob-pro with MIT License 5 votes vote down vote up
@Override
protected void __destroyAdView(View view) {
  if(view == null) return;

  if(view instanceof PublisherAdView) {
    PublisherAdView dfpView = (PublisherAdView)view;
    dfpView.setAdListener(null);
    dfpView.destroy();
  } else {
    AdView admobView = (AdView)view;
    admobView.setAdListener(null);
    admobView.destroy();
  }
}
 
Example 3
Source File: DemoActivity.java    From prebid-mobile-android with Apache License 2.0 4 votes vote down vote up
void createDFPNative() {
    FrameLayout adFrame = (FrameLayout) findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    final PublisherAdView nativeAdView = new PublisherAdView(this);
    nativeAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            LogUtil.d("ad loaded");
        }
    });
    nativeAdView.setAdUnitId(Constants.DFP_IN_BANNER_NATIVE_ADUNIT_ID_APPNEXUS);
    nativeAdView.setAdSizes(AdSize.FLUID);
    adFrame.addView(nativeAdView);
    final PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
    request = builder.build();
    NativeAdUnit nativeAdUnit = (NativeAdUnit) adUnit;
    nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC);
    nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED);
    nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL);
    ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>();
    methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE);

    try {
        NativeEventTracker tracker = new NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods);
        nativeAdUnit.addEventTracker(tracker);
    } catch (Exception e) {
        e.printStackTrace();

    }
    NativeTitleAsset title = new NativeTitleAsset();
    title.setLength(90);
    title.setRequired(true);
    nativeAdUnit.addAsset(title);
    NativeImageAsset icon = new NativeImageAsset();
    icon.setImageType(NativeImageAsset.IMAGE_TYPE.ICON);
    icon.setWMin(20);
    icon.setHMin(20);
    icon.setRequired(true);
    nativeAdUnit.addAsset(icon);
    NativeImageAsset image = new NativeImageAsset();
    image.setImageType(NativeImageAsset.IMAGE_TYPE.MAIN);
    image.setHMin(200);
    image.setWMin(200);
    image.setRequired(true);
    nativeAdUnit.addAsset(image);
    NativeDataAsset data = new NativeDataAsset();
    data.setLen(90);
    data.setDataType(NativeDataAsset.DATA_TYPE.SPONSORED);
    data.setRequired(true);
    nativeAdUnit.addAsset(data);
    NativeDataAsset body = new NativeDataAsset();
    body.setRequired(true);
    body.setDataType(NativeDataAsset.DATA_TYPE.DESC);
    nativeAdUnit.addAsset(body);
    NativeDataAsset cta = new NativeDataAsset();
    cta.setRequired(true);
    cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT);
    nativeAdUnit.addAsset(cta);
    int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
    nativeAdUnit.setAutoRefreshPeriodMillis(millis);
    nativeAdUnit.fetchDemand(request, new OnCompleteListener() {
        @Override
        public void onComplete(ResultCode resultCode) {
            DemoActivity.this.resultCode = resultCode;
            nativeAdView.loadAd(request);
            DemoActivity.this.request = request;
            refreshCount++;
        }
    });
}