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

项目: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());
}
项目:android-ads    文件:ContentAdViewHolder.java   
/**
 * Populates the asset {@link View}s contained it the {@link NativeContentAdView} with data
 * from the {@link NativeContentAd} object. This method is invoked when an
 * {@link ContentAdFetcher} has successfully loaded a {@link NativeContentAd}.
 *
 * @param contentAd the ad that is to be displayed
 */
public void populateView(NativeContentAd contentAd) {
    ((TextView) mAdView.getHeadlineView()).setText(contentAd.getHeadline());
    ((TextView) mAdView.getBodyView()).setText(contentAd.getBody());
    ((TextView) mAdView.getCallToActionView()).setText(contentAd.getCallToAction());
    ((TextView) mAdView.getAdvertiserView()).setText(contentAd.getAdvertiser());

    List<NativeAd.Image> images = contentAd.getImages();

    if (images != null && images.size() > 0) {
        ((ImageView) mAdView.getImageView())
                .setImageDrawable(images.get(0).getDrawable());
    }

    NativeAd.Image logoImage = contentAd.getLogo();

    if (logoImage != null) {
        ((ImageView) mAdView.getLogoView())
                .setImageDrawable(logoImage.getDrawable());
    }

    // assign native ad object to the native view and make visible
    mAdView.setNativeAd(contentAd);
    mAdView.setVisibility(View.VISIBLE);
}
项目:android-ads    文件:AppInstallAdViewHolder.java   
/**
 * Populates the asset {@link View}s contained it the {@link NativeAppInstallAdView} with data
 * from the {@link NativeAppInstallAd} object. This method is invoked when an
 * {@link AppInstallAdFetcher} has successfully loaded a {@link NativeAppInstallAd}.
 *
 * @param appInstallAd the ad that is to be displayed
 */
public void populateView(NativeAppInstallAd appInstallAd) {
    ((TextView) mAdView.getHeadlineView()).setText(appInstallAd.getHeadline());
    ((TextView) mAdView.getBodyView()).setText(appInstallAd.getBody());
    ((TextView) mAdView.getPriceView()).setText(appInstallAd.getPrice());
    ((TextView) mAdView.getStoreView()).setText(appInstallAd.getStore());
    ((Button) mAdView.getCallToActionView()).setText(appInstallAd.getCallToAction());
    ((ImageView) mAdView.getIconView()).setImageDrawable(appInstallAd.getIcon().getDrawable());
    ((RatingBar) mAdView.getStarRatingView())
            .setRating(appInstallAd.getStarRating().floatValue());

    List<NativeAd.Image> images = appInstallAd.getImages();

    if (images.size() > 0) {
        ((ImageView) mAdView.getImageView())
                .setImageDrawable(images.get(0).getDrawable());
    }

    // assign native ad object to the native view and make visible
    mAdView.setNativeAd(appInstallAd);
    mAdView.setVisibility(View.VISIBLE);
}
项目:admob-native-advanced-feed    文件:MainActivity.java   
private void insertAdsInMenuItems() {
    if (mNativeAds.size() <= 0) {
        return;
    }

    int offset = (mRecyclerViewItems.size() / mNativeAds.size()) + 1;
    int index = 0;
    for (NativeAd ad : mNativeAds) {
        mRecyclerViewItems.add(index, ad);
        index = index + offset;
    }
}
项目:admob-native-advanced-feed    文件:RecyclerViewAdapter.java   
/**
 * Populates a {@link NativeContentAdView} object with data from a given
 * {@link NativeContentAd}.
 *
 * @param nativeContentAd the object containing the ad's assets
 * @param adView          the view to be populated
 */
private void populateContentAdView(NativeContentAd nativeContentAd,
                                   NativeContentAdView adView) {
    // Some assets are guaranteed to be in every NativeContentAd.
    ((TextView) adView.getHeadlineView()).setText(nativeContentAd.getHeadline());
    ((TextView) adView.getBodyView()).setText(nativeContentAd.getBody());
    ((TextView) adView.getCallToActionView()).setText(nativeContentAd.getCallToAction());
    ((TextView) adView.getAdvertiserView()).setText(nativeContentAd.getAdvertiser());

    List<NativeAd.Image> images = nativeContentAd.getImages();

    if (images.size() > 0) {
        ((ImageView) adView.getImageView()).setImageDrawable(images.get(0).getDrawable());
    }

    // Some aren't guaranteed, however, and should be checked.
    NativeAd.Image logoImage = nativeContentAd.getLogo();

    if (logoImage == null) {
        adView.getLogoView().setVisibility(View.INVISIBLE);
    } else {
        ((ImageView) adView.getLogoView()).setImageDrawable(logoImage.getDrawable());
        adView.getLogoView().setVisibility(View.VISIBLE);
    }

    // Assign native ad object to the native view.
    adView.setNativeAd(nativeContentAd);
}
项目: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   
/**
 * A handler for received native ads
 */
private synchronized void onAdFetched(NativeAd adNative) {
    Log.i(TAG, "onAdFetched");
    int index = -1;
    if (canUseThisAd(adNative)) {
        mPrefetchedAdList.add(adNative);
        index = mPrefetchedAdList.size()-1;
        mNoOfFetchedAds++;
    }
    lockFetch.set(false);
    mFetchFailCount = 0;
    ensurePrefetchAmount();
    onAdLoaded(index);
}
项目:admobadapter    文件:AdmobRecyclerAdapterWrapper.java   
@Override
public int getItemViewType(int position) {
    if (AdapterCalculator.canShowAdAtPosition(position, adFetcher.getFetchedAdsCount())) {
        int adPos = AdapterCalculator.getAdIndex(position);
        NativeAd ad = adFetcher.getAdForIndex(adPos);
        return ad instanceof NativeAppInstallAd ? getViewTypeAdInstall() : getViewTypeAdContent();
    } else {
        int origPos = AdapterCalculator.getOriginalContentPosition(position,
                adFetcher.getFetchedAdsCount(), mAdapter.getItemCount());
        return mAdapter.getItemViewType(origPos);
    }
}
项目:android-ads    文件:MainActivity.java   
/**
 * Populates a {@link NativeContentAdView} object with data from a given
 * {@link NativeContentAd}.
 *
 * @param nativeContentAd the object containing the ad's assets
 * @param adView          the view to be populated
 */
private void populateContentAdView(NativeContentAd nativeContentAd,
                                   NativeContentAdView adView) {
    mVideoStatus.setText("Video status: Ad does not contain a video asset.");
    mRefresh.setEnabled(true);

    adView.setHeadlineView(adView.findViewById(R.id.contentad_headline));
    adView.setImageView(adView.findViewById(R.id.contentad_image));
    adView.setBodyView(adView.findViewById(R.id.contentad_body));
    adView.setCallToActionView(adView.findViewById(R.id.contentad_call_to_action));
    adView.setLogoView(adView.findViewById(R.id.contentad_logo));
    adView.setAdvertiserView(adView.findViewById(R.id.contentad_advertiser));

    // Some assets are guaranteed to be in every NativeContentAd.
    ((TextView) adView.getHeadlineView()).setText(nativeContentAd.getHeadline());
    ((TextView) adView.getBodyView()).setText(nativeContentAd.getBody());
    ((TextView) adView.getCallToActionView()).setText(nativeContentAd.getCallToAction());
    ((TextView) adView.getAdvertiserView()).setText(nativeContentAd.getAdvertiser());

    List<NativeAd.Image> images = nativeContentAd.getImages();

    if (images.size() > 0) {
        ((ImageView) adView.getImageView()).setImageDrawable(images.get(0).getDrawable());
    }

    // Some aren't guaranteed, however, and should be checked.
    NativeAd.Image logoImage = nativeContentAd.getLogo();

    if (logoImage == null) {
        adView.getLogoView().setVisibility(View.INVISIBLE);
    } else {
        ((ImageView) adView.getLogoView()).setImageDrawable(logoImage.getDrawable());
        adView.getLogoView().setVisibility(View.VISIBLE);
    }

    // Assign native ad object to the native view.
    adView.setNativeAd(nativeContentAd);
}
项目:googleads-mobile-android-examples    文件:MainActivity.java   
/**
 * Populates a {@link NativeContentAdView} object with data from a given
 * {@link NativeContentAd}.
 *
 * @param nativeContentAd the object containing the ad's assets
 * @param adView          the view to be populated
 */
private void populateContentAdView(NativeContentAd nativeContentAd,
                                   NativeContentAdView adView) {
    mVideoStatus.setText("Video status: Ad does not contain a video asset.");
    mRefresh.setEnabled(true);

    adView.setHeadlineView(adView.findViewById(R.id.contentad_headline));
    adView.setImageView(adView.findViewById(R.id.contentad_image));
    adView.setBodyView(adView.findViewById(R.id.contentad_body));
    adView.setCallToActionView(adView.findViewById(R.id.contentad_call_to_action));
    adView.setLogoView(adView.findViewById(R.id.contentad_logo));
    adView.setAdvertiserView(adView.findViewById(R.id.contentad_advertiser));

    // Some assets are guaranteed to be in every NativeContentAd.
    ((TextView) adView.getHeadlineView()).setText(nativeContentAd.getHeadline());
    ((TextView) adView.getBodyView()).setText(nativeContentAd.getBody());
    ((TextView) adView.getCallToActionView()).setText(nativeContentAd.getCallToAction());
    ((TextView) adView.getAdvertiserView()).setText(nativeContentAd.getAdvertiser());

    List<NativeAd.Image> images = nativeContentAd.getImages();

    if (images.size() > 0) {
        ((ImageView) adView.getImageView()).setImageDrawable(images.get(0).getDrawable());
    }

    // Some aren't guaranteed, however, and should be checked.
    NativeAd.Image logoImage = nativeContentAd.getLogo();

    if (logoImage == null) {
        adView.getLogoView().setVisibility(View.INVISIBLE);
    } else {
        ((ImageView) adView.getLogoView()).setImageDrawable(logoImage.getDrawable());
        adView.getLogoView().setVisibility(View.VISIBLE);
    }

    // Assign native ad object to the native view.
    adView.setNativeAd(nativeContentAd);
}
项目:mobile-sdk-android    文件:AdMobNativeAdResponse.java   
AdMobNativeAdResponse(NativeAd ad, AdMobNativeSettings.AdMobNativeType type) {
    this.nativeAd = ad;
    this.type = type;
    runnable = new Runnable() {
        @Override
        public void run() {
            if (coverImage != null) {
                coverImage.recycle();
                coverImage = null;
            }
            if (icon != null) {
                icon.recycle();
                icon = null;
            }
            listener = null;
            expired = true;
            if (AdMobNativeAdResponse.this.nativeAd != null) {
                try {
                    switch (AdMobNativeAdResponse.this.type) {
                        case APP_INSTALL:
                            NativeAppInstallAd appInstallAd = (NativeAppInstallAd) AdMobNativeAdResponse.this.nativeAd;
                            appInstallAd.destroy();
                            break;
                        case CONTENT_AD:
                            NativeContentAd contentAd = (NativeContentAd) AdMobNativeAdResponse.this.nativeAd;
                            contentAd.destroy();
                            break;
                    }
                } catch (ClassCastException e) {
                }
            }
        }
    };
    nativeExpireHandler = new Handler(Looper.getMainLooper());
    nativeExpireHandler.postDelayed(runnable, Settings.NATIVE_AD_RESPONSE_EXPIRATION_TIME);
    loadAssets();
}
项目:mopub-nativead-adapters    文件:AdMobNativeAd.java   
public NativeAd getNativeAd() {
    return this.nativeAppInstallAd == null ? this.nativeContentAd : this.nativeAppInstallAd;
}
项目:googleads-mobile-android-mediation    文件:MainActivity.java   
/**
 * Populates a {@link NativeAppInstallAdView} object with data from a given
 * {@link NativeAppInstallAd}.
 *
 * @param nativeAppInstallAd the object containing the ad's assets
 * @param adView             the view to be populated
 */
private void populateAppInstallAdView(NativeAppInstallAd nativeAppInstallAd,
                                      NativeAppInstallAdView adView) {
    VideoController videoController = nativeAppInstallAd.getVideoController();

    // Assign native ad object to the native view.
    adView.setNativeAd(nativeAppInstallAd);

    adView.setHeadlineView(adView.findViewById(R.id.appinstall_headline));
    adView.setBodyView(adView.findViewById(R.id.appinstall_body));
    adView.setCallToActionView(adView.findViewById(R.id.appinstall_call_to_action));
    adView.setIconView(adView.findViewById(R.id.appinstall_app_icon));
    adView.setPriceView(adView.findViewById(R.id.appinstall_price));
    adView.setStarRatingView(adView.findViewById(R.id.appinstall_stars));
    adView.setStoreView(adView.findViewById(R.id.appinstall_store));

    // Some assets are guaranteed to be in every NativeAppInstallAd.
    ((TextView) adView.getHeadlineView()).setText(nativeAppInstallAd.getHeadline());
    ((TextView) adView.getBodyView()).setText(nativeAppInstallAd.getBody());
    ((Button) adView.getCallToActionView()).setText(nativeAppInstallAd.getCallToAction());
    ((ImageView) adView.getIconView()).setImageDrawable(nativeAppInstallAd.getIcon()
            .getDrawable());

    MediaView sampleMediaView = adView.findViewById(R.id.appinstall_media);
    ImageView imageView = adView.findViewById(R.id.appinstall_image);

    if (videoController.hasVideoContent()) {
        imageView.setVisibility(View.GONE);
        adView.setMediaView(sampleMediaView);
    } else {
        sampleMediaView.setVisibility(View.GONE);
        adView.setImageView(imageView);

        List<NativeAd.Image> images = nativeAppInstallAd.getImages();

        if (images.size() > 0) {
            ((ImageView) adView.getImageView()).setImageDrawable(images.get(0).getDrawable());
        }
    }

    // Some aren't guaranteed, however, and should be checked.
    if (nativeAppInstallAd.getPrice() == null) {
        adView.getPriceView().setVisibility(View.INVISIBLE);
    } else {
        adView.getPriceView().setVisibility(View.VISIBLE);
        ((TextView) adView.getPriceView()).setText(nativeAppInstallAd.getPrice());
    }

    if (nativeAppInstallAd.getStore() == null) {
        adView.getStoreView().setVisibility(View.INVISIBLE);
    } else {
        adView.getStoreView().setVisibility(View.VISIBLE);
        ((TextView) adView.getStoreView()).setText(nativeAppInstallAd.getStore());
    }

    if (nativeAppInstallAd.getStarRating() == null) {
        adView.getStarRatingView().setVisibility(View.INVISIBLE);
    } else {
        ((RatingBar) adView.getStarRatingView())
                .setRating(nativeAppInstallAd.getStarRating().floatValue());
        adView.getStarRatingView().setVisibility(View.VISIBLE);
    }

    // Handle the fact that this could be a Sample SDK native ad, which includes a
    // "degree of awesomeness" field.

    Bundle extras = nativeAppInstallAd.getExtras();
    if (extras.containsKey(SampleCustomEvent.DEGREE_OF_AWESOMENESS)) {
        TextView degree = (TextView) adView.findViewById(R.id.appinstall_degreeofawesomeness);
        degree.setVisibility(View.VISIBLE);
        degree.setText(extras.getString(SampleCustomEvent.DEGREE_OF_AWESOMENESS));
    }
}
项目:googleads-mobile-android-mediation    文件:MainActivity.java   
/**
 * Populates a {@link NativeContentAdView} object with data from a given
 * {@link NativeContentAd}.
 *
 * @param nativeContentAd the object containing the ad's assets
 * @param adView          the view to be populated
 */
private void populateContentAdView(NativeContentAd nativeContentAd,
                                   NativeContentAdView adView) {
    // Assign native ad object to the native view.
    adView.setNativeAd(nativeContentAd);

    adView.setHeadlineView(adView.findViewById(R.id.contentad_headline));
    adView.setImageView(adView.findViewById(R.id.contentad_image));
    adView.setBodyView(adView.findViewById(R.id.contentad_body));
    adView.setCallToActionView(adView.findViewById(R.id.contentad_call_to_action));
    adView.setLogoView(adView.findViewById(R.id.contentad_logo));
    adView.setAdvertiserView(adView.findViewById(R.id.contentad_advertiser));

    // Some assets are guaranteed to be in every NativeContentAd.
    ((TextView) adView.getHeadlineView()).setText(nativeContentAd.getHeadline());
    ((TextView) adView.getBodyView()).setText(nativeContentAd.getBody());
    ((TextView) adView.getCallToActionView()).setText(nativeContentAd.getCallToAction());
    ((TextView) adView.getAdvertiserView()).setText(nativeContentAd.getAdvertiser());

    List<NativeAd.Image> images = nativeContentAd.getImages();

    if (images.size() > 0) {
        ((ImageView) adView.getImageView()).setImageDrawable(images.get(0).getDrawable());
    }

    // Some aren't guaranteed, however, and should be checked.
    NativeAd.Image logoImage = nativeContentAd.getLogo();

    if (logoImage == null) {
        adView.getLogoView().setVisibility(View.INVISIBLE);
    } else {
        ((ImageView) adView.getLogoView())
                .setImageDrawable(logoImage.getDrawable());
        adView.getLogoView().setVisibility(View.VISIBLE);
    }

    // Handle the fact that this could be a Sample SDK native ad, which includes a
    // "degree of awesomeness" field.

    Bundle extras = nativeContentAd.getExtras();
    if (extras.containsKey(SampleCustomEvent.DEGREE_OF_AWESOMENESS)) {
        TextView degree = (TextView) adView.findViewById(R.id.appinstall_degreeofawesomeness);
        degree.setVisibility(View.VISIBLE);
        degree.setText(extras.getString(SampleCustomEvent.DEGREE_OF_AWESOMENESS));
    }
}
项目:admobadapter    文件:InstallAppAdLayoutContext.java   
@Override
public void bind(NativeAdView nativeAdView, NativeAd nativeAd) throws ClassCastException{
    if (nativeAdView == null || nativeAd == null) return;
    if(!(nativeAd instanceof NativeAppInstallAd) || !(nativeAdView instanceof NativeAppInstallAdView))
        throw new ClassCastException();

    NativeAppInstallAd ad = (NativeAppInstallAd) nativeAd;
    NativeAppInstallAdView adView = (NativeAppInstallAdView) nativeAdView;

    // Locate the view that will hold the headline, set its text, and call the
    // NativeAppInstallAdView's setHeadlineView method to register it.
    TextView tvHeader = (TextView) adView.findViewById(R.id.tvHeader);
    tvHeader.setText(ad.getHeadline());
    adView.setHeadlineView(tvHeader);

    TextView tvDescription = (TextView) adView.findViewById(R.id.tvDescription);
    tvDescription.setText(ad.getBody());
    adView.setBodyView(tvDescription);

    ImageView ivLogo = (ImageView) adView.findViewById(R.id.ivLogo);
    if(ad.getIcon()!=null)
        ivLogo.setImageDrawable(ad.getIcon().getDrawable());
    adView.setIconView(ivLogo);

    Button btnAction = (Button) adView.findViewById(R.id.btnAction);
    btnAction.setText(ad.getCallToAction());
    adView.setCallToActionView(btnAction);

    TextView tvStore = (TextView) adView.findViewById(R.id.tvStore);
    tvStore.setText(ad.getStore());
    adView.setStoreView(tvStore);

    TextView tvPrice = (TextView) adView.findViewById(R.id.tvPrice);
    tvPrice.setText(ad.getPrice());
    adView.setPriceView(tvPrice);

    ImageView ivImage = (ImageView) adView.findViewById(R.id.ivImage);
    if (ad.getImages() != null && ad.getImages().size() > 0) {
        ivImage.setImageDrawable(ad.getImages().get(0).getDrawable());
        ivImage.setVisibility(View.VISIBLE);
    } else ivImage.setVisibility(View.GONE);
    adView.setImageView(ivImage);

    // Call the NativeAppInstallAdView's setNativeAd method to register the
    // NativeAd.
    adView.setNativeAd(ad);
}
项目:admobadapter    文件:ContentAdLayoutContext.java   
@Override
public void bind(NativeAdView nativeAdView, NativeAd nativeAd) throws ClassCastException{
    if (nativeAdView == null || nativeAd == null) return;
    if(!(nativeAd instanceof NativeContentAd) || !(nativeAdView instanceof NativeContentAdView))
        throw new ClassCastException();

    NativeContentAd ad = (NativeContentAd) nativeAd;
    NativeContentAdView adView = (NativeContentAdView) nativeAdView;

    // Locate the view that will hold the headline, set its text, and call the
    // NativeContentAdView's setHeadlineView method to register it.
    TextView tvHeader = (TextView) nativeAdView.findViewById(R.id.tvHeader);
    tvHeader.setText(ad.getHeadline());
    adView.setHeadlineView(tvHeader);

    TextView tvDescription = (TextView) nativeAdView.findViewById(R.id.tvDescription);
    tvDescription.setText(ad.getBody());
    adView.setBodyView(tvDescription);

    ImageView ivLogo = (ImageView) nativeAdView.findViewById(R.id.ivLogo);
    if(ad.getLogo()!=null)
        ivLogo.setImageDrawable(ad.getLogo().getDrawable());
    adView.setLogoView(ivLogo);

    Button btnAction = (Button) nativeAdView.findViewById(R.id.btnAction);
    btnAction.setText(ad.getCallToAction());
    adView.setCallToActionView(btnAction);

    TextView tvAdvertiser = (TextView) nativeAdView.findViewById(R.id.tvAdvertiser);
    tvAdvertiser.setText(ad.getAdvertiser());
    adView.setAdvertiserView(tvAdvertiser);

    ImageView ivImage = (ImageView) nativeAdView.findViewById(R.id.ivImage);
    if (ad.getImages() != null && ad.getImages().size() > 0) {
        ivImage.setImageDrawable(ad.getImages().get(0).getDrawable());
        ivImage.setVisibility(View.VISIBLE);
    } else ivImage.setVisibility(View.GONE);
    adView.setImageView(ivImage);

    // Call the NativeContentAdView's setNativeAd method to register the
    // NativeAdObject.
    nativeAdView.setNativeAd(nativeAd);
}
项目:android-ads    文件:MainActivity.java   
/**
 * Populates a {@link NativeContentAdView} object with data from a given
 * {@link NativeContentAd}.
 *
 * @param nativeContentAd the object containing the ad's assets
 * @param adView          the view to be populated
 */
private void populateContentAdView(NativeContentAd nativeContentAd,
                                   NativeContentAdView adView) {
    adView.setHeadlineView(adView.findViewById(R.id.contentad_headline));
    adView.setBodyView(adView.findViewById(R.id.contentad_body));
    adView.setCallToActionView(adView.findViewById(R.id.contentad_call_to_action));
    adView.setLogoView(adView.findViewById(R.id.contentad_logo));
    adView.setAdvertiserView(adView.findViewById(R.id.contentad_advertiser));

    // Some assets are guaranteed to be in every NativeContentAd.
    ((TextView) adView.getHeadlineView()).setText(nativeContentAd.getHeadline());
    ((TextView) adView.getBodyView()).setText(nativeContentAd.getBody());
    ((TextView) adView.getCallToActionView()).setText(nativeContentAd.getCallToAction());
    ((TextView) adView.getAdvertiserView()).setText(nativeContentAd.getAdvertiser());

    // Get the video controller for the ad. One will always be provided, even if the ad doesn't
    // have a video asset.
    VideoController vc = nativeContentAd.getVideoController();

    MediaView mediaView = adView.findViewById(R.id.contentad_media);
    ImageView mainImageView = adView.findViewById(R.id.contentad_image);

    // Apps can check the VideoController's hasVideoContent property to determine if the
    // NativeContentAd has a video asset.
    if (vc.hasVideoContent()) {
        mainImageView.setVisibility(View.GONE);
        adView.setMediaView(mediaView);

        mVideoStatus.setText(String.format(Locale.getDefault(),
                "Video status: Ad contains a %.2f:1 video asset.",
                vc.getAspectRatio()));

        // Create a new VideoLifecycleCallbacks object and pass it to the VideoController. The
        // VideoController will call methods on this object when events occur in the video
        // lifecycle.
        vc.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
            public void onVideoEnd() {
                // Publishers should allow native ads to complete video playback before
                // refreshing or replacing them with another ad in the same UI location.
                mRefresh.setEnabled(true);
                mVideoStatus.setText("Video status: Video playback has ended.");
                super.onVideoEnd();
            }
        });
    } else {
        mediaView.setVisibility(View.GONE);
        adView.setImageView(mainImageView);

        // At least one image is guaranteed.
        List<NativeAd.Image> images = nativeContentAd.getImages();
        mainImageView.setImageDrawable(images.get(0).getDrawable());

        mRefresh.setEnabled(true);
        mVideoStatus.setText("Video status: Ad does not contain a video asset.");
    }

    // These assets aren't guaranteed to be in every NativeContentAd, so it's important to
    // check before trying to display them.
    NativeAd.Image logoImage = nativeContentAd.getLogo();

    if (logoImage == null) {
        adView.getLogoView().setVisibility(View.INVISIBLE);
    } else {
        ((ImageView) adView.getLogoView()).setImageDrawable(logoImage.getDrawable());
        adView.getLogoView().setVisibility(View.VISIBLE);
    }

    // Assign native ad object to the native view.
    adView.setNativeAd(nativeContentAd);
}
项目:googleads-mobile-android-examples    文件:MainActivity.java   
/**
 * Populates a {@link NativeContentAdView} object with data from a given
 * {@link NativeContentAd}.
 *
 * @param nativeContentAd the object containing the ad's assets
 * @param adView          the view to be populated
 */
private void populateContentAdView(NativeContentAd nativeContentAd,
                                   NativeContentAdView adView) {
    adView.setHeadlineView(adView.findViewById(R.id.contentad_headline));
    adView.setBodyView(adView.findViewById(R.id.contentad_body));
    adView.setCallToActionView(adView.findViewById(R.id.contentad_call_to_action));
    adView.setLogoView(adView.findViewById(R.id.contentad_logo));
    adView.setAdvertiserView(adView.findViewById(R.id.contentad_advertiser));

    // Some assets are guaranteed to be in every NativeContentAd.
    ((TextView) adView.getHeadlineView()).setText(nativeContentAd.getHeadline());
    ((TextView) adView.getBodyView()).setText(nativeContentAd.getBody());
    ((TextView) adView.getCallToActionView()).setText(nativeContentAd.getCallToAction());
    ((TextView) adView.getAdvertiserView()).setText(nativeContentAd.getAdvertiser());

    // Get the video controller for the ad. One will always be provided, even if the ad doesn't
    // have a video asset.
    VideoController vc = nativeContentAd.getVideoController();

    MediaView mediaView = adView.findViewById(R.id.contentad_media);
    ImageView mainImageView = adView.findViewById(R.id.contentad_image);

    // Apps can check the VideoController's hasVideoContent property to determine if the
    // NativeContentAd has a video asset.
    if (vc.hasVideoContent()) {
        mainImageView.setVisibility(View.GONE);
        adView.setMediaView(mediaView);

        mVideoStatus.setText(String.format(Locale.getDefault(),
                "Video status: Ad contains a %.2f:1 video asset.",
                vc.getAspectRatio()));

        // Create a new VideoLifecycleCallbacks object and pass it to the VideoController. The
        // VideoController will call methods on this object when events occur in the video
        // lifecycle.
        vc.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
            public void onVideoEnd() {
                // Publishers should allow native ads to complete video playback before
                // refreshing or replacing them with another ad in the same UI location.
                mRefresh.setEnabled(true);
                mVideoStatus.setText("Video status: Video playback has ended.");
                super.onVideoEnd();
            }
        });
    } else {
        mediaView.setVisibility(View.GONE);
        adView.setImageView(mainImageView);

        // At least one image is guaranteed.
        List<NativeAd.Image> images = nativeContentAd.getImages();
        mainImageView.setImageDrawable(images.get(0).getDrawable());

        mRefresh.setEnabled(true);
        mVideoStatus.setText("Video status: Ad does not contain a video asset.");
    }

    // These assets aren't guaranteed to be in every NativeContentAd, so it's important to
    // check before trying to display them.
    NativeAd.Image logoImage = nativeContentAd.getLogo();

    if (logoImage == null) {
        adView.getLogoView().setVisibility(View.INVISIBLE);
    } else {
        ((ImageView) adView.getLogoView()).setImageDrawable(logoImage.getDrawable());
        adView.getLogoView().setVisibility(View.VISIBLE);
    }

    // Assign native ad object to the native view.
    adView.setNativeAd(nativeContentAd);
}
项目:admobadapter    文件:NativeAdLayoutContext.java   
public abstract void bind(NativeAdView nativeAdView, NativeAd nativeAd);