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

项目:googleads-mobile-android-mediation    文件:SampleNativeContentAdMapper.java   
public SampleNativeContentAdMapper(SampleNativeContentAd ad, NativeAdOptions adOptions) {
    mSampleAd = ad;
    mNativeAdOptions = adOptions;

    setAdvertiser(mSampleAd.getAdvertiser());
    setHeadline(mSampleAd.getHeadline());
    setBody(mSampleAd.getBody());
    setCallToAction(mSampleAd.getCallToAction());

    setLogo(new SampleNativeMappedImage(ad.getLogo(), ad.getLogoUri(),
            SampleCustomEvent.SAMPLE_SDK_IMAGE_SCALE));

    List<NativeAd.Image> imagesList = new ArrayList<NativeAd.Image>();
    imagesList.add(new SampleNativeMappedImage(ad.getImage(), ad.getImageUri(),
            SampleCustomEvent.SAMPLE_SDK_IMAGE_SCALE));
    setImages(imagesList);

    Bundle extras = new Bundle();
    extras.putString(SampleCustomEvent.DEGREE_OF_AWESOMENESS, ad.getDegreeOfAwesomeness());
    this.setExtras(extras);

    setOverrideClickHandling(false);
    setOverrideImpressionRecording(false);

    setAdChoicesContent(mSampleAd.getInformationIcon());
}
项目:googleads-mobile-android-mediation    文件:FacebookAdapter.java   
@Override
public void onAdLoaded(Ad ad) {
    if (ad != mNativeAd) {
        Log.w(TAG, "Ad loaded is not a native ad.");
        FacebookAdapter.this.mNativeListener.onAdFailedToLoad(
                FacebookAdapter.this, AdRequest.ERROR_CODE_INTERNAL_ERROR);
        return;
    }

    NativeAdOptions options = mMediationAdRequest.getNativeAdOptions();
    // We always convert the ad into an app install ad.
    final AppInstallMapper mapper = new AppInstallMapper(mNativeAd, options);
    mapper.mapNativeAd(new NativeAdMapperListener() {
        @Override
        public void onMappingSuccess() {
            mNativeListener.onAdLoaded(FacebookAdapter.this, mapper);
        }

        @Override
        public void onMappingFailed() {
            mNativeListener.onAdFailedToLoad(FacebookAdapter.this,
                    AdRequest.ERROR_CODE_NO_FILL);
        }
    });
}
项目: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);
        }
    }


}
项目:googleads-mobile-android-mediation    文件:SampleNativeContentAdMapper.java   
public SampleNativeContentAdMapper(SampleNativeContentAd ad, NativeAdOptions adOptions) {
    mSampleAd = ad;
    mNativeAdOptions = adOptions;

    setAdvertiser(mSampleAd.getAdvertiser());
    setHeadline(mSampleAd.getHeadline());
    setBody(mSampleAd.getBody());
    setCallToAction(mSampleAd.getCallToAction());

    setLogo(new SampleNativeMappedImage(ad.getLogo(), ad.getLogoUri(),
            SampleAdapter.SAMPLE_SDK_IMAGE_SCALE));

    List<NativeAd.Image> imagesList = new ArrayList<NativeAd.Image>();
    imagesList.add(new SampleNativeMappedImage(ad.getImage(), ad.getImageUri(),
            SampleAdapter.SAMPLE_SDK_IMAGE_SCALE));
    setImages(imagesList);

    Bundle extras = new Bundle();
    extras.putString(SampleAdapter.DEGREE_OF_AWESOMENESS, ad.getDegreeOfAwesomeness());
    this.setExtras(extras);

    SampleMediaView mediaView = mSampleAd.getMediaView();

    // Some ads from Sample SDK has video assets and some do not.
    if(mediaView != null) {
        setMediaView(mediaView);
        setHasVideoContent(true);
    } else {
        setHasVideoContent(false);
    }

    setOverrideClickHandling(false);
    setOverrideImpressionRecording(false);

    setAdChoicesContent(mSampleAd.getInformationIcon());
}
项目:googleads-mobile-android-mediation    文件:SampleNativeAppInstallAdMapper.java   
public SampleNativeAppInstallAdMapper(SampleNativeAppInstallAd ad, NativeAdOptions adOptions) {
    mSampleAd = ad;
    mNativeAdOptions = adOptions;
    setHeadline(mSampleAd.getHeadline());
    setBody(mSampleAd.getBody());
    setCallToAction(mSampleAd.getCallToAction());
    setStarRating(mSampleAd.getStarRating());
    setStore(mSampleAd.getStoreName());
    setIcon(new SampleNativeMappedImage(ad.getAppIcon(), ad.getAppIconUri(),
            SampleAdapter.SAMPLE_SDK_IMAGE_SCALE));

    List<NativeAd.Image> imagesList = new ArrayList<NativeAd.Image>();
    imagesList.add(new SampleNativeMappedImage(ad.getImage(), ad.getImageUri(),
            SampleAdapter.SAMPLE_SDK_IMAGE_SCALE));
    setImages(imagesList);

    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    String priceString = formatter.format(mSampleAd.getPrice());
    setPrice(priceString);

    Bundle extras = new Bundle();
    extras.putString(SampleAdapter.DEGREE_OF_AWESOMENESS, ad.getDegreeOfAwesomeness());
    this.setExtras(extras);

    SampleMediaView mediaView = mSampleAd.getMediaView();

    // Some ads from Sample SDK has video assets and some do not.
    if (mediaView != null) {
        setMediaView(mediaView);
        setHasVideoContent(true);
    } else {
        setHasVideoContent(false);
    }

    setOverrideClickHandling(false);
    setOverrideImpressionRecording(false);

    setAdChoicesContent(mSampleAd.getInformationIcon());
}
项目:googleads-mobile-android-mediation    文件:SampleNativeAppInstallAdMapper.java   
public SampleNativeAppInstallAdMapper(SampleNativeAppInstallAd ad, NativeAdOptions adOptions) {
    mSampleAd = ad;
    mNativeAdOptions = adOptions;
    setHeadline(mSampleAd.getHeadline());
    setBody(mSampleAd.getBody());
    setCallToAction(mSampleAd.getCallToAction());
    setStarRating(mSampleAd.getStarRating());
    setStore(mSampleAd.getStoreName());
    setIcon(new SampleNativeMappedImage(ad.getAppIcon(), ad.getAppIconUri(),
            SampleCustomEvent.SAMPLE_SDK_IMAGE_SCALE));

    List<NativeAd.Image> imagesList = new ArrayList<NativeAd.Image>();
    imagesList.add(new SampleNativeMappedImage(ad.getImage(), ad.getImageUri(),
            SampleCustomEvent.SAMPLE_SDK_IMAGE_SCALE));
    setImages(imagesList);

    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    String priceString = formatter.format(mSampleAd.getPrice());
    setPrice(priceString);

    Bundle extras = new Bundle();
    extras.putString(SampleCustomEvent.DEGREE_OF_AWESOMENESS, ad.getDegreeOfAwesomeness());
    this.setExtras(extras);

    setOverrideClickHandling(false);
    setOverrideImpressionRecording(false);

    setAdChoicesContent(mSampleAd.getInformationIcon());
}
项目: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();
}
项目:pubnative-android-sdk    文件:AdMob.java   
public static NativeAdOptions getNativeAdOptions() {

        return new NativeAdOptions.Builder().setReturnUrlsForImageAssets(true)
                                            .build();
    }
项目:mytarget-android    文件:MyTargetAdmobCustomEventNative.java   
@Override
public void requestNativeAd(@Nullable Context context,
                            @Nullable CustomEventNativeListener customEventNativeListener,
                            @Nullable String serverParameter,
                            @Nullable NativeMediationAdRequest nativeMediationAdRequest,
                            @Nullable
                                    Bundle customEventExtras)
{
    if (context == null)
    {
        Log.d(TAG, "unable to request native ad, context is null");
        if (customEventNativeListener != null)
        {
            customEventNativeListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INTERNAL_ERROR);
        }
        return;
    }

    this.resources = context.getResources();

    this.customEventNativeListener = customEventNativeListener;

    NativeAdOptions options = null;
    int gender = 0;
    Date birthday = null;
    if (nativeMediationAdRequest != null)
    {
        options = nativeMediationAdRequest.getNativeAdOptions();
        isAppInstallAdRequested = nativeMediationAdRequest.isAppInstallAdRequested();
        isContentAdRequested = nativeMediationAdRequest.isContentAdRequested();
        gender = nativeMediationAdRequest.getGender();
        birthday = nativeMediationAdRequest.getBirthday();
    }

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

    NativeAd nativeAd = new NativeAd(slotId, context.getApplicationContext());

    if (options != null)
    {
        nativeAd.setAutoLoadImages(!options.shouldReturnUrlsForImageAssets());
    }

    nativeAd.getCustomParams().setGender(gender);

    if (birthday != null && birthday.getTime() != -1)
    {
        GregorianCalendar calendar = new GregorianCalendar();
        GregorianCalendar calendarNow = new GregorianCalendar();

        calendar.setTimeInMillis(birthday.getTime());
        int a = calendarNow.get(GregorianCalendar.YEAR) - calendar.get(GregorianCalendar.YEAR);
        if (a >= 0)
        {
            nativeAd.getCustomParams().setAge(a);
        }
    }

    nativeAd.getCustomParams().setCustomParam("mediation", "1");
    nativeAd.setListener(nativeAdListener);
    nativeAd.load();
}
项目:googleads-mobile-android-mediation    文件:SampleAdapter.java   
protected NativeAdOptions getNativeAdOptions() {
    return mNativeAdOptions;
}
项目:googleads-mobile-android-mediation    文件:SampleCustomEvent.java   
@Override
public void requestNativeAd(Context context,
                            CustomEventNativeListener customEventNativeListener,
                            String serverParameter,
                            NativeMediationAdRequest nativeMediationAdRequest,
                            Bundle extras) {
    // Create one of the Sample SDK's ad loaders from which to request ads.
    SampleNativeAdLoader loader = new SampleNativeAdLoader(context);
    loader.setAdUnit(serverParameter);

    // Create a native request to give to the SampleNativeAdLoader.
    SampleNativeAdRequest request = new SampleNativeAdRequest();

    // The Google Mobile Ads SDK requires the image assets to be downloaded automatically unless
    // the publisher specifies otherwise by using the NativeAdOptions object's
    // shouldReturnUrlsForImageAssets method. If your network doesn't have an option like this
    // and instead only ever returns URLs for images (rather than the images themselves), your
    // adapter should download image assets on behalf of the publisher. See the
    // SampleNativeMediationEventForwarder for information on how to do so.
    request.setShouldDownloadImages(true);

    request.setShouldDownloadMultipleImages(false);
    request.setPreferredImageOrientation(SampleNativeAdRequest.IMAGE_ORIENTATION_ANY);

    NativeAdOptions options = nativeMediationAdRequest.getNativeAdOptions();

    if (options != null) {
        // If the NativeAdOptions' shouldReturnUrlsForImageAssets is true, the adapter should
        // send just the URLs for the images.
        request.setShouldDownloadImages(!options.shouldReturnUrlsForImageAssets());

        // If your network does not support any of the following options, please make sure
        // that it is documented in your adapter's documentation.
        request.setShouldDownloadMultipleImages(options.shouldRequestMultipleImages());
        switch (options.getImageOrientation()) {
            case NativeAdOptions.ORIENTATION_LANDSCAPE:
                request.setPreferredImageOrientation(
                        SampleNativeAdRequest.IMAGE_ORIENTATION_LANDSCAPE);
                break;
            case NativeAdOptions.ORIENTATION_PORTRAIT:
                request.setPreferredImageOrientation(
                        SampleNativeAdRequest.IMAGE_ORIENTATION_PORTRAIT);
                break;
            case NativeAdOptions.ORIENTATION_ANY:
            default:
                request.setPreferredImageOrientation(
                        SampleNativeAdRequest.IMAGE_ORIENTATION_ANY);
        }
    }

    // Set App Install and Content Ad requests.
    //
    // NOTE: Care needs to be taken to make sure the custom event respects the publisher's
    // wishes in regard to native ad formats. For example, if the mediated ad network only
    // provides app install ads, and the publisher requests content ads alone, the custom event
    // must report an error by calling the listener's onAdFailedToLoad method with an error code
    // of AdRequest.ERROR_CODE_INVALID_REQUEST. It should *not* request an app install ad
    // anyway, and then attempt to map it to the content ad format.
    if (!nativeMediationAdRequest.isAppInstallAdRequested()
            && !nativeMediationAdRequest.isContentAdRequested()) {
        customEventNativeListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INVALID_REQUEST);
        return;
    }
    request.setAppInstallAdsRequested(nativeMediationAdRequest.isAppInstallAdRequested());
    request.setContentAdsRequested(nativeMediationAdRequest.isContentAdRequested());

    loader.setNativeAdListener(
            new SampleCustomNativeEventForwarder(customEventNativeListener, options));

    // Begin a request.
    loader.fetchAd(request);
}
项目:googleads-mobile-android-mediation    文件:MoPubNativeAppInstallAdMapper.java   
public void trackView(View view) {

        mMopubNativeAdData.prepare(view);

        if (!(view instanceof ViewGroup)) {
            return;
        }

        ViewGroup adView = (ViewGroup) view;

        View overlayView = adView.getChildAt(adView.getChildCount() - 1);
        if (overlayView instanceof FrameLayout) {

            final Context context = view.getContext();
            if (context == null) {
                return;
            }

            privacyInformationIconImageView = new ImageView(context);
            String privacyInformationImageUrl =
                    mMopubNativeAdData.getPrivacyInformationIconImageUrl();
            final String privacyInformationClickthroughUrl = mMopubNativeAdData
                    .getPrivacyInformationIconClickThroughUrl();

            if (privacyInformationImageUrl == null) {
                privacyInformationIconImageView.setImageDrawable(
                        Drawables.NATIVE_PRIVACY_INFORMATION_ICON.createDrawable(context));
            } else {
                NativeImageHelper.loadImageView(privacyInformationImageUrl,
                        privacyInformationIconImageView);
            }

            privacyInformationIconImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View v) {
                    new UrlHandler.Builder()
                            .withSupportedUrlActions(
                                    UrlAction.IGNORE_ABOUT_SCHEME,
                                    UrlAction.OPEN_NATIVE_BROWSER,
                                    UrlAction.OPEN_IN_APP_BROWSER,
                                    UrlAction.HANDLE_SHARE_TWEET,
                                    UrlAction.FOLLOW_DEEP_LINK_WITH_FALLBACK,
                                    UrlAction.FOLLOW_DEEP_LINK)
                            .build().handleUrl(context, privacyInformationClickthroughUrl);
                }
            });
            privacyInformationIconImageView.setVisibility(View.VISIBLE);
            ((ViewGroup) overlayView).addView(privacyInformationIconImageView);

            float scale = context.getResources().getDisplayMetrics().density;
            int icon_size_px = (int) (mPrivacyIconSize * scale + 0.5);
            FrameLayout.LayoutParams params =
                    new FrameLayout.LayoutParams(icon_size_px, icon_size_px);

            switch (privacyIconPlacement) {
                case NativeAdOptions.ADCHOICES_TOP_LEFT:
                    params.gravity = Gravity.TOP | Gravity.LEFT;
                    break;
                case NativeAdOptions.ADCHOICES_BOTTOM_RIGHT:
                    params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
                    break;
                case NativeAdOptions.ADCHOICES_BOTTOM_LEFT:
                    params.gravity = Gravity.BOTTOM | Gravity.LEFT;
                    break;
                case NativeAdOptions.ADCHOICES_TOP_RIGHT:
                    params.gravity = Gravity.TOP | Gravity.RIGHT;
                    break;
                default:
                    params.gravity = Gravity.TOP | Gravity.RIGHT;
            }
            privacyInformationIconImageView.setLayoutParams(params);
            adView.requestLayout();
        } else {
            Log.d(MoPubAdapter.TAG, "Failed to show AdChoices icon.");
        }


    }
项目:googleads-mobile-android-mediation    文件:MyTargetNativeAdapter.java   
@Override
public void requestNativeAd(Context context,
                            MediationNativeListener customEventNativeListener,
                            Bundle serverParameter,
                            NativeMediationAdRequest nativeMediationAdRequest,
                            Bundle customEventExtras) {
    this.customEventNativeListener = customEventNativeListener;
    int slotId = MyTargetTools.checkAndGetSlotId(context, serverParameter);
    Log.d(TAG, "Requesting myTarget mediation, slotId: " + slotId);

    if (slotId < 0) {
        if (customEventNativeListener != null) {
            customEventNativeListener.onAdFailedToLoad(
                    MyTargetNativeAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST);
        }
        return;
    }
    NativeAdOptions options = null;
    int gender = 0;
    Date birthday = null;
    boolean contentRequested = false;
    boolean installRequested = false;
    if (nativeMediationAdRequest != null) {
        options = nativeMediationAdRequest.getNativeAdOptions();
        gender = nativeMediationAdRequest.getGender();
        birthday = nativeMediationAdRequest.getBirthday();
        contentRequested = nativeMediationAdRequest.isContentAdRequested();
        installRequested = nativeMediationAdRequest.isAppInstallAdRequested();
    }

    NativeAd nativeAd = new NativeAd(slotId, context);

    boolean autoLoadImages = true;
    if (options != null) {
        autoLoadImages = !options.shouldReturnUrlsForImageAssets();
        Log.d(TAG, "Set autoload images to " + autoLoadImages);
    }
    nativeAd.setAutoLoadImages(autoLoadImages);

    CustomParams params = nativeAd.getCustomParams();
    Log.d(TAG, "Set gender to " + gender);
    params.setGender(gender);

    if (birthday != null && birthday.getTime() != -1) {
        GregorianCalendar calendar = new GregorianCalendar();
        GregorianCalendar calendarNow = new GregorianCalendar();

        calendar.setTimeInMillis(birthday.getTime());
        int age = calendarNow.get(GregorianCalendar.YEAR)
                - calendar.get(GregorianCalendar.YEAR);
        if (age >= 0) {
            params.setAge(age);
        }
    }
    Log.d(TAG, "Content requested: " + contentRequested
            + ", install requested: " + installRequested);
    if (!contentRequested || !installRequested) {
        if (!contentRequested) {
            params.setCustomParam(PARAM_NATIVE_TYPE_REQUEST, PARAM_INSTALL_ONLY);
        } else {
            params.setCustomParam(PARAM_NATIVE_TYPE_REQUEST, PARAM_CONTENT_ONLY);
        }
    }

    MyTargetNativeAdListener nativeAdListener =
            new MyTargetNativeAdListener(nativeAd, nativeMediationAdRequest, context);

    params.setCustomParam(
            MyTargetTools.PARAM_MEDIATION_KEY, MyTargetTools.PARAM_MEDIATION_VALUE);
    nativeAd.setListener(nativeAdListener);
    nativeAd.load();
}
项目:mopub-nativead-adapters    文件:AdMobNativeAd.java   
/**
 * Returns a {@link com.google.android.gms.ads.formats.NativeAdOptions.Builder} instance to let you customize ad requests.
 * <p>For details on how to customize it, please refer to <a href="https://firebase.google.com/docs/admob/android/native-advanced">this guide</a>.</p>
 * @return A {@link com.google.android.gms.ads.formats.NativeAdOptions.Builder} instance to let you customize ad requests.
 */
@NonNull
public NativeAdOptions.Builder getNativeAdOptionsBuilder() {
    return this.nativeAdOptionsBuilder;
}
项目:googleads-mobile-android-mediation    文件:SampleCustomNativeEventForwarder.java   
/**
 * Creates a new {@code SampleNativeEventForwarder}.
 *
 * @param listener An AdMob Mediation {@link CustomEventNativeListener} that should receive
 *                 forwarded events.
 */
public SampleCustomNativeEventForwarder(CustomEventNativeListener listener,
                                        NativeAdOptions adOptions) {
    this.mNativeListener = listener;
    this.mNativeAdOptions = adOptions;
}
项目:googleads-mobile-android-mediation    文件:FacebookAdapter.java   
/**
 * Default constructor for {@link AppInstallMapper}.
 *
 * @param nativeAd  The Facebook native ad to be mapped.
 * @param adOptions {@link NativeAdOptions} containing the preferences to be used when
 *                  mapping the native ad.
 */
public AppInstallMapper(NativeAd nativeAd, NativeAdOptions adOptions) {
    AppInstallMapper.this.mNativeAd = nativeAd;
    AppInstallMapper.this.mNativeAdOptions = adOptions;
}