com.google.android.gms.ads.doubleclick.PublisherAdView Java Examples

The following examples show how to use com.google.android.gms.ads.doubleclick.PublisherAdView. 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: AdsManager.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create {@link PublisherAdView} and add to container
 *
 * @param context   - android context
 * @param container - parent view for add ad view
 * @return true if ads has been added
 */
public static boolean addBannerAds(Context context, @Nullable ViewGroup container) {
    if (isPremiumUser(context)) {
        if (container != null) {
            container.setVisibility(View.GONE);
        }
        return false;
    } else {
        if (container == null) return false;
        container.setVisibility(View.VISIBLE);
        PublisherAdView publisherAdView = new PublisherAdView(context);
        publisherAdView.setAdSizes(AdSize.SMART_BANNER, AdSize.FLUID);
        publisherAdView.setAdUnitId(AdConstants.AdUnitId.AD_UNIT_ID_NATIVE_MAIN_320_50);

        PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
        if (BuildConfig.DEBUG) builder.addTestDevice(TEST_DEVICE_ID);

        publisherAdView.loadAd(builder.build());
        container.removeAllViews();
        container.addView(publisherAdView);
    }
    return false;
}
 
Example #2
Source File: AdsManager.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
public static PublisherAdView addBannerAds(Context context, @Nullable ViewGroup container, AdSize... adSizes) {
    if (isPremiumUser(context)) {
        if (container != null) {
            container.setVisibility(View.GONE);
        }
        return null;
    } else {
        if (container == null) return null;
        container.setVisibility(View.VISIBLE);
        PublisherAdView publisherAdView = new PublisherAdView(context);
        publisherAdView.setAdSizes(adSizes);
        publisherAdView.setAdUnitId(AdConstants.AdUnitId.AD_UNIT_ID_NATIVE_MAIN_320_50);

        PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
        if (BuildConfig.DEBUG) builder.addTestDevice(TEST_DEVICE_ID);

        publisherAdView.loadAd(builder.build());
        container.removeAllViews();
        container.addView(publisherAdView);
        return publisherAdView;
    }
}
 
Example #3
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 #4
Source File: AdMobPlugin.java    From cordova-admob-pro with MIT License 5 votes vote down vote up
protected AdSize getAdViewSize(View view) {
  if(view instanceof PublisherAdView) {
    PublisherAdView dfpView = (PublisherAdView) view;
    return dfpView.getAdSize();
  } else if(view instanceof AdView) {
    AdView admobView = (AdView) view;
    return admobView.getAdSize();
  } else {
    return new AdSize(0,0);
  }
}
 
Example #5
Source File: AdMobPlugin.java    From cordova-admob-pro with MIT License 5 votes vote down vote up
@Override
protected void __pauseAdView(View view) {
  if(view == null) return;
  
  if(view instanceof PublisherAdView) {
    PublisherAdView dfpView = (PublisherAdView)view;
    dfpView.pause();
  } else {
    AdView admobView = (AdView)view;
    admobView.pause();
  }
}
 
Example #6
Source File: AdMobPlugin.java    From cordova-admob-pro with MIT License 5 votes vote down vote up
@Override
protected void __resumeAdView(View view) {
  if(view == null) return;

  if(view instanceof PublisherAdView) {
    PublisherAdView dfpView = (PublisherAdView)view;
    dfpView.resume();
  } else {
    AdView admobView = (AdView)view;
    admobView.resume();
  }
}
 
Example #7
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 #8
Source File: MyActivity.java    From googleads-mobile-android-examples with Apache License 2.0 5 votes vote down vote up
private void loadBanner(AdSize adSize) {
  // Create an ad request.
  adView = new PublisherAdView(this);
  adView.setAdUnitId(BACKFILL_IU);
  adView.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_light));
  adContainerView.removeAllViews();
  adContainerView.addView(adView);
  adView.setAdSizes(adSize);

  PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build();

  // Start loading the ad in the background.
  adView.loadAd(adRequest);
}
 
Example #9
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++;
        }
    });
}
 
Example #10
Source File: DemoActivity.java    From prebid-mobile-android with Apache License 2.0 4 votes vote down vote up
private void setupAMBanner(int width, int height, String adUnitId) {
    amBanner = new PublisherAdView(this);
    amBanner.setAdUnitId(adUnitId);
    amBanner.setAdSizes(new AdSize(width, height));
}
 
Example #11
Source File: RNPublisherBannerViewManager.java    From react-native-admob with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void createAdView() {
    if (this.adView != null) this.adView.destroy();

    final Context context = getContext();
    this.adView = new PublisherAdView(context);
    this.adView.setAppEventListener(this);
    this.adView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            int width = adView.getAdSize().getWidthInPixels(context);
            int height = adView.getAdSize().getHeightInPixels(context);
            int left = adView.getLeft();
            int top = adView.getTop();
            adView.measure(width, height);
            adView.layout(left, top, left + width, top + height);
            sendOnSizeChangeEvent();
            sendEvent(RNPublisherBannerViewManager.EVENT_AD_LOADED, null);
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            String errorMessage = "Unknown error";
            switch (errorCode) {
                case PublisherAdRequest.ERROR_CODE_INTERNAL_ERROR:
                    errorMessage = "Internal error, an invalid response was received from the ad server.";
                    break;
                case PublisherAdRequest.ERROR_CODE_INVALID_REQUEST:
                    errorMessage = "Invalid ad request, possibly an incorrect ad unit ID was given.";
                    break;
                case PublisherAdRequest.ERROR_CODE_NETWORK_ERROR:
                    errorMessage = "The ad request was unsuccessful due to network connectivity.";
                    break;
                case PublisherAdRequest.ERROR_CODE_NO_FILL:
                    errorMessage = "The ad request was successful, but no ad was returned due to lack of ad inventory.";
                    break;
            }
            WritableMap event = Arguments.createMap();
            WritableMap error = Arguments.createMap();
            error.putString("message", errorMessage);
            event.putMap("error", error);
            sendEvent(RNPublisherBannerViewManager.EVENT_AD_FAILED_TO_LOAD, event);
        }

        @Override
        public void onAdOpened() {
            sendEvent(RNPublisherBannerViewManager.EVENT_AD_OPENED, null);
        }

        @Override
        public void onAdClosed() {
            sendEvent(RNPublisherBannerViewManager.EVENT_AD_CLOSED, null);
        }

        @Override
        public void onAdLeftApplication() {
            sendEvent(RNPublisherBannerViewManager.EVENT_AD_LEFT_APPLICATION, null);
        }
    });
    this.addView(this.adView);
}