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

The following are top voted examples for showing how to use com.google.android.gms.ads.doubleclick.PublisherAdView. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: prebid-mobile-android   File: DFPBannerFragment.java   View source code 7 votes vote down vote up
private void setupBannerWithWait(final int waitTime) {

        FrameLayout adFrame = (FrameLayout) root.findViewById(R.id.adFrame2);
        adFrame.removeAllViews();
        adView2 = new PublisherAdView(getActivity());
        adView2.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_300x250);
        adView2.setAdSizes(new AdSize(300, 250));
        adView2.setAdListener(adListener);
        adFrame.addView(adView2);
        //region PriceCheckForDFP API usage
        PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
        PublisherAdRequest request = builder.build();
        Prebid.attachBidsWhenReady(request, Constants.BANNER_300x250, this, waitTime, this.getActivity());
        //endregion

    }
 
Example 2
Project: text_converter   File: AdsManager.java   View source code 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 3
Project: text_converter   File: AdsManager.java   View source code 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 4
Project: mobile-sdk-android   File: GooglePlayDFPBanner.java   View source code 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.loadAd(buildRequest(ssparm, targetingParameters));

    return adView;
}
 
Example 5
Project: prebid-mobile-android   File: DFPBannerFragment.java   View source code 5 votes vote down vote up
private void setupBannerWithoutWait() {
    FrameLayout adFrame = (FrameLayout) root.findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    adView1 = new PublisherAdView(getActivity());
    adView1.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_320x50);
    adView1.setAdSizes(new AdSize(320, 50));
    adView1.setAdListener(adListener);
    adFrame.addView(adView1);
    //region PriceCheckForDFP API usage
    PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
    PublisherAdRequest request = builder.build();
    Prebid.attachBids(request, Constants.BANNER_320x50, this.getActivity());
    //endregion
    adView1.loadAd(request);
}
 
Example 6
Project: hotmob-android-sdk   File: MediationBannerFragment.java   View source code 5 votes vote down vote up
private void getBanner(String iu){
    final PublisherAdView adView = new PublisherAdView(getContext());
    adView.setAdUnitId(iu);
    adView.setAdSizes(AdSize.SMART_BANNER);
    AdListener mAdListener = new AdListener() {
        @Override
        public void onAdClosed() {
            super.onAdClosed();
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            super.onAdFailedToLoad(errorCode);
        }

        @Override
        public void onAdLeftApplication() {
            super.onAdLeftApplication();
        }

        @Override
        public void onAdOpened() {
            super.onAdOpened();
        }

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            bannerContainer.addView(adView);
        }
    };
    adView.setAdListener(mAdListener);
    PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build();
    adView.loadAd(adRequest);
}
 
Example 7
Project: hotmob-android-sdk   File: MediationListAdapter.java   View source code 4 votes vote down vote up
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    // Get the data item for this position
    String item = getItem(position);
    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.listitem_mediation_banner, parent, false);
    }
    // Lookup view for data population
    TextView adCode = convertView.findViewById(R.id.adcode);
    final ViewGroup bannerContainer = convertView.findViewById(R.id.banner_view);
    // Populate the data into the template view using the data object
    adCode.setText(item);
    if (bannerContainer.getChildCount() == 0) {
        final PublisherAdView adView = new PublisherAdView(getContext());
        adView.setAdUnitId(item);
        adView.setAdSizes(AdSize.SMART_BANNER);
        AdListener mAdListener = new AdListener() {
            @Override
            public void onAdClosed() {
                super.onAdClosed();
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                super.onAdFailedToLoad(errorCode);
            }

            @Override
            public void onAdLeftApplication() {
                super.onAdLeftApplication();
            }

            @Override
            public void onAdOpened() {
                super.onAdOpened();
            }

            @Override
            public void onAdLoaded() {
                super.onAdLoaded();
                bannerContainer.addView(adView);
            }
        };
        adView.setAdListener(mAdListener);
        PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build();
        adView.loadAd(adRequest);
    }
    // Return the completed view to render on screen
    return convertView;
}
 
Example 8
Project: react-native-admob   File: RNPublisherBannerViewManager.java   View source code 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);
}