Java 类com.google.android.gms.ads.AdLoader 实例源码

项目:mopub-nativead-adapters    文件:AdMobNativeAd.java   
@Override
public void fetchAd() {
    new AdLoader.Builder(this.getContext(), this.adUnitId)
        .forAppInstallAd(AdMobNativeAd.this)
        .forContentAd(AdMobNativeAd.this)
        .withNativeAdOptions(this.getNativeAdOptionsBuilder().build())
        .withAdListener(new AdListener() {
            @Override
            public void onAdOpened() {
                AdMobNativeAd.this.notifyAdClicked();
            }

            @Override
            public void onAdFailedToLoad(final int errorCode) {
                AdMobNativeAd.this.onAdFailedToLoad(errorCode);
            }
        })
        .build()
        .loadAd(this.getAdRequestBuilder().build());
}
项目:pubnative-android-sdk    文件:AdMobNetworkAdapter.java   
@Override
protected void request(Context context, Map<String, String> networkData) {
    if (context == null || networkData == null) {
        invokeLoadFail(PNException.ADAPTER_ILLEGAL_ARGUMENTS);
    } else {
        String unitId = networkData.get(AdMob.KEY_UNIT_ID);
        if (TextUtils.isEmpty(unitId)) {
            invokeLoadFail(PNException.ADAPTER_MISSING_DATA);
        } else {

            mAdView = null;
            mWrapper = new AdMobNativeAppInstallAdModel(context, this);
            AdLoader adLoader = new AdLoader.Builder(context, unitId)
                    .forAppInstallAd(mWrapper)
                    .withAdListener(mWrapper.getAdListener())
                    .withNativeAdOptions(AdMob.getNativeAdOptions())
                    .build();
            adLoader.loadAd(AdMob.getAdRequest(context));
        }
    }
}
项目:pubnative-android-sdk    文件:AdMobNetworkAdapter.java   
@Override
protected void request(Context context, Map<String, String> networkData) {
    if (context == null || networkData == null) {
        invokeLoadFail(PNException.ADAPTER_ILLEGAL_ARGUMENTS);
    } else {
        String unitId = networkData.get(AdMob.KEY_UNIT_ID);
        if (TextUtils.isEmpty(unitId)) {
            invokeLoadFail(PNException.ADAPTER_MISSING_DATA);
        } else {

            mAdView = null;
            mWrapper = new AdMobNativeAppInstallAdModel(context, this);
            AdLoader adLoader = new AdLoader.Builder(context, unitId).forAppInstallAd(mWrapper)
                                                                     .withAdListener(mWrapper.getAdListener())
                                                                     .withNativeAdOptions(AdMob.getNativeAdOptions())
                                                                     .build();
            adLoader.loadAd(AdMob.getAdRequest(context));
        }
    }
}
项目:pubnative-android-sdk    文件:AdMobNetworkAdapter.java   
@Override
protected void request(Context context, Map<String, String> networkData) {
    if (context == null || networkData == null) {
        invokeLoadFail(PNException.ADAPTER_ILLEGAL_ARGUMENTS);
    } else {
        String unitId = networkData.get(AdMob.KEY_UNIT_ID);
        if (TextUtils.isEmpty(unitId)) {
            invokeLoadFail(PNException.ADAPTER_MISSING_DATA);
        } else {

            mAdView = null;
            mWrapper = new AdMobNativeAppInstallAdModel(context, this);
            AdLoader adLoader = new AdLoader.Builder(context, unitId).forAppInstallAd(mWrapper)
                                                                     .withAdListener(mWrapper.getAdListener())
                                                                     .withNativeAdOptions(AdMob.getNativeAdOptions())
                                                                     .build();
            adLoader.loadAd(AdMob.getAdRequest(context));
        }
    }
}
项目:mobile-sdk-android    文件:AdMobNativeAd.java   
/**
 * AppNexus SDk calls this method to request a native ad from AdMob
 *
 * @param context The context from which this class is instantiated.
 * @param uid     AdMob ad unit id, app developer needs to set up account with AdMob.
 * @param mBC     The controller that passes callbacks to AppNexus SDK
 * @param tp      Targeting parameters that were set in AppNexus API.
 */
@Override
public void requestNativeAd(Context context, String uid, MediatedNativeAdController mBC, TargetingParameters tp) {
    if (mBC != null) {
        if (AdMobNativeSettings.enableAppInstallAd || AdMobNativeSettings.enableContentAd) {
            AdMobNativeListener adMobNativeListener = new AdMobNativeListener(mBC);
            AdLoader.Builder builder = new AdLoader.Builder(context, uid).withAdListener(adMobNativeListener)
                    .withNativeAdOptions(new NativeAdOptions.Builder().setReturnUrlsForImageAssets(true).build());
            if (AdMobNativeSettings.enableAppInstallAd) {
                builder.forAppInstallAd(adMobNativeListener);
            }
            if (AdMobNativeSettings.enableContentAd) {
                builder.forContentAd(adMobNativeListener);
            }
            builder.build().loadAd(GooglePlayServicesBanner.buildRequest(tp));
        } else {
            Clog.w(Clog.mediationLogTag, "Unable to get AdMob Native ad since both AdMobNativeSettings.setEnableContentAd() and AdMobNativeSettings.setEnableAppInstallAd() were not called.");
            mBC.onAdFailed(ResultCode.MEDIATED_SDK_UNAVAILABLE);
        }
    }


}
项目:pubnative-android-sdk    文件:AdMobNetworkAdapter.java   
protected void createRequest(Context context, String unitId) {
    mWrapper = new AdMobNativeAppInstallAdModel(context, this);
    AdLoader adLoader = new AdLoader.Builder(context, unitId).forAppInstallAd(mWrapper)
                                                             .withAdListener(mWrapper.getAdListener())
                                                             .withNativeAdOptions(AdMob.getNativeAdOptions())
                                                             .build();
    adLoader.loadAd(AdMob.getAdRequest(context));
}
项目:admobadapter    文件:AdmobFetcher.java   
/**
 * Subscribing to the native ads events
 */
protected synchronized void setupAds() {
    String unitId = getReleaseUnitId() != null ? getReleaseUnitId() : getDefaultUnitId();
    AdLoader.Builder adloaderBuilder = new AdLoader.Builder(mContext.get(), unitId)
            .withAdListener(new AdListener() {
                @Override
                public void onAdFailedToLoad(int errorCode) {
                    // Handle the failure by logging, altering the UI, etc.
                    Log.i(TAG, "onAdFailedToLoad " + errorCode);
                    lockFetch.set(false);
                    mFetchFailCount++;
                    mFetchingAdsCnt--;
                    ensurePrefetchAmount();
                    onAdFailed( mPrefetchedAdList.size(), errorCode, null);
                }
            })
            .withNativeAdOptions(new NativeAdOptions.Builder()
                    // Methods in the NativeAdOptions.Builder class can be
                    // used here to specify individual options settings.
                    .build());
    if(getAdTypeToFetch().contains(EAdType.ADVANCED_INSTALLAPP))
        adloaderBuilder.forAppInstallAd(new NativeAppInstallAd.OnAppInstallAdLoadedListener() {
                @Override
                public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) {
                    onAdFetched(appInstallAd);
                }
            });
    if(getAdTypeToFetch().contains(EAdType.ADVANCED_CONTENT))
        adloaderBuilder.forContentAd(new NativeContentAd.OnContentAdLoadedListener() {
                @Override
                public void onContentAdLoaded(NativeContentAd contentAd) {
                    onAdFetched(contentAd);
                }
            });

    adLoader = adloaderBuilder.build();
}
项目:android-ads    文件:ContentAdFetcher.java   
/**
 * Loads a {@link NativeContentAd} and calls {@link ContentAdViewHolder} methods to
 * display its assets or handle failure by hiding the view.
 */
public void loadAd(Context context, ContentAdViewHolder viewHolder) {
    synchronized (mSyncObject) {
        mViewHolder = viewHolder;

        if ((mAdLoader != null) && mAdLoader.isLoading()) {
            Log.d(MainActivity.LOG_TAG, "ContentAdFetcher is already loading an ad.");
            return;
        }

        // If an ad previously loaded, reuse it instead of requesting a new one.
        if (mContentAd != null) {
            mViewHolder.populateView(mContentAd);
            return;
        }

        NativeContentAd.OnContentAdLoadedListener contentAdListener =
                new NativeContentAd.OnContentAdLoadedListener() {
                    public void onContentAdLoaded(NativeContentAd ad) {
                        mContentAd = ad;
                        mViewHolder.populateView(mContentAd);
                    }
                };

        if (mAdLoader == null) {
            mAdLoader = new AdLoader.Builder(context, mAdUnitId)
                    .forContentAd(contentAdListener)
                    .withAdListener(new AdListener() {
                        @Override
                        public void onAdFailedToLoad(int errorCode) {
                            mViewHolder.hideView();
                            Log.e(MainActivity.LOG_TAG,
                                    "Content Ad Failed to load: " + errorCode);
                        }
                    }).build();
        }

        mAdLoader.loadAd(new PublisherAdRequest.Builder().build());
    }
}
项目:android-ads    文件:AppInstallAdFetcher.java   
/**
 * Loads a {@link NativeAppInstallAd} and calls {@link AppInstallAdViewHolder} methods to
 * display its assets or handle failure by hiding the view.
 */
public void loadAd(Context context,
                   AppInstallAdViewHolder viewHolder) {
    synchronized (mSyncObject) {
        mViewHolder = viewHolder;

        if ((mAdLoader != null) && mAdLoader.isLoading()) {
            Log.d(MainActivity.LOG_TAG, "AppInstallAdFetcher is already loading an ad.");
            return;
        }

        // If an ad previously loaded, reuse it instead of requesting a new one.
        if (mAppInstallAd != null) {
            mViewHolder.populateView(mAppInstallAd);
            return;
        }

        NativeAppInstallAd.OnAppInstallAdLoadedListener appInstallAdListener =
                new NativeAppInstallAd.OnAppInstallAdLoadedListener() {
                    public void onAppInstallAdLoaded(NativeAppInstallAd ad) {
                        mAppInstallAd = ad;
                        mViewHolder.populateView(mAppInstallAd);
                    }
                };

        if (mAdLoader == null) {
            mAdLoader = new AdLoader.Builder(context, mAdUnitId)
                    .forAppInstallAd(appInstallAdListener)
                    .withAdListener(new AdListener() {
                        @Override
                        public void onAdFailedToLoad(int errorCode) {
                            mViewHolder.hideView();
                            Log.e(MainActivity.LOG_TAG,
                                    "App Install Ad Failed to load: " + errorCode);
                        }
                    }).build();
        }

        mAdLoader.loadAd(new PublisherAdRequest.Builder().build());
    }
}