com.google.android.gms.ads.formats.MediaView Java Examples

The following examples show how to use com.google.android.gms.ads.formats.MediaView. 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: TemplateView.java    From googleads-mobile-android-native-templates with Apache License 2.0 6 votes vote down vote up
@Override
public void onFinishInflate() {
  super.onFinishInflate();
  nativeAdView = (UnifiedNativeAdView) findViewById(R.id.native_ad_view);
  primaryView = (TextView) findViewById(R.id.primary);
  secondaryView = (TextView) findViewById(R.id.secondary);
  tertiaryView = (TextView) findViewById(R.id.body);

  ratingBar = (RatingBar) findViewById(R.id.rating_bar);
  ratingBar.setEnabled(false);

  callToActionView = (Button) findViewById(R.id.cta);
  iconView = (ImageView) findViewById(R.id.icon);
  mediaView = (MediaView) findViewById(R.id.media_view);
  background = (ConstraintLayout) findViewById(R.id.background);
}
 
Example #2
Source File: UnifiedNativeAdViewHolder.java    From admob-native-advanced-feed with Apache License 2.0 6 votes vote down vote up
UnifiedNativeAdViewHolder(View view) {
    super(view);
    adView = (UnifiedNativeAdView) view.findViewById(R.id.ad_view);

    // The MediaView will display a video asset if one is present in the ad, and the
    // first image asset otherwise.
    adView.setMediaView((MediaView) adView.findViewById(R.id.ad_media));

    // Register the view used for each individual asset.
    adView.setHeadlineView(adView.findViewById(R.id.ad_headline));
    adView.setBodyView(adView.findViewById(R.id.ad_body));
    adView.setCallToActionView(adView.findViewById(R.id.ad_call_to_action));
    adView.setIconView(adView.findViewById(R.id.ad_icon));
    adView.setPriceView(adView.findViewById(R.id.ad_price));
    adView.setStarRatingView(adView.findViewById(R.id.ad_stars));
    adView.setStoreView(adView.findViewById(R.id.ad_store));
    adView.setAdvertiserView(adView.findViewById(R.id.ad_advertiser));
}
 
Example #3
Source File: MyTargetNativeAdapter.java    From googleads-mobile-android-mediation with Apache License 2.0 6 votes vote down vote up
private static int findMediaAdViewPosition(@NonNull List<View> clickableViews,
    @NonNull MediaAdView mediaAdView) {
  for (int i = 0; i < clickableViews.size(); i++) {
    View view = clickableViews.get(i);
    if (view instanceof MediaView) {
      MediaView mediaView = (MediaView) view;
      int childCount = mediaView.getChildCount();
      for (int j = 0; j < childCount; j++) {
        View innerView = mediaView.getChildAt(j);
        if (innerView == mediaAdView) {
          return i;
        }
      }
      break;
    }
  }
  return -1;
}
 
Example #4
Source File: MainActivity.java    From googleads-mobile-android-mediation with Apache License 2.0 4 votes vote down vote up
/**
 * Populates a {@link UnifiedNativeAdView} object with data from a given {@link UnifiedNativeAd}.
 *
 * @param nativeAd the object containing the ad's assets
 * @param adView the view to be populated
 */
private void populateUnifiedNativeAdView(UnifiedNativeAd nativeAd, UnifiedNativeAdView adView) {
  // Set the media view. Media content will be automatically populated in the media view once
  // adView.setNativeAd() is called.
  MediaView mediaView = adView.findViewById(R.id.ad_media);
  adView.setMediaView(mediaView);

  // Set other ad assets.
  adView.setHeadlineView(adView.findViewById(R.id.ad_headline));
  adView.setBodyView(adView.findViewById(R.id.ad_body));
  adView.setCallToActionView(adView.findViewById(R.id.ad_call_to_action));
  adView.setIconView(adView.findViewById(R.id.ad_app_icon));
  adView.setPriceView(adView.findViewById(R.id.ad_price));
  adView.setStarRatingView(adView.findViewById(R.id.ad_stars));
  adView.setStoreView(adView.findViewById(R.id.ad_store));
  adView.setAdvertiserView(adView.findViewById(R.id.ad_advertiser));

  // The headline is guaranteed to be in every UnifiedNativeAd.
  ((TextView) adView.getHeadlineView()).setText(nativeAd.getHeadline());

  // These assets aren't guaranteed to be in every UnifiedNativeAd, so it's important to
  // check before trying to display them.
  if (nativeAd.getBody() == null) {
    adView.getBodyView().setVisibility(View.INVISIBLE);
  } else {
    adView.getBodyView().setVisibility(View.VISIBLE);
    ((TextView) adView.getBodyView()).setText(nativeAd.getBody());
  }

  if (nativeAd.getCallToAction() == null) {
    adView.getCallToActionView().setVisibility(View.INVISIBLE);
  } else {
    adView.getCallToActionView().setVisibility(View.VISIBLE);
    ((Button) adView.getCallToActionView()).setText(nativeAd.getCallToAction());
  }

  if (nativeAd.getIcon() == null) {
    adView.getIconView().setVisibility(View.GONE);
  } else {
    ((ImageView) adView.getIconView()).setImageDrawable(
        nativeAd.getIcon().getDrawable());
    adView.getIconView().setVisibility(View.VISIBLE);
  }

  if (nativeAd.getPrice() == null) {
    adView.getPriceView().setVisibility(View.INVISIBLE);
  } else {
    adView.getPriceView().setVisibility(View.VISIBLE);
    ((TextView) adView.getPriceView()).setText(nativeAd.getPrice());
  }

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

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

  if (nativeAd.getAdvertiser() == null) {
    adView.getAdvertiserView().setVisibility(View.INVISIBLE);
  } else {
    ((TextView) adView.getAdvertiserView()).setText(nativeAd.getAdvertiser());
    adView.getAdvertiserView().setVisibility(View.VISIBLE);
  }

  // This method tells the Google Mobile Ads SDK that you have finished populating your
  // native ad view with this native ad. The SDK will populate the adView's MediaView
  // with the media content from this native ad.
  adView.setNativeAd(nativeAd);
}
 
Example #5
Source File: DFPCustomControlsFragment.java    From android-ads with Apache License 2.0 4 votes vote down vote up
/**
 * 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) {
    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());

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

    MediaView mediaView = adView.findViewById(R.id.appinstall_media);
    ImageView mainImageView = adView.findViewById(R.id.appinstall_image);

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

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

    // These assets aren't guaranteed to be in every NativeAppInstallAd, so it's important to
    // check before trying to display them.
    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);
    }


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

    customControlsView.setVideoController(videoController);

    refresh.setEnabled(true);
}
 
Example #6
Source File: DFPCustomControlsFragment.java    From android-ads with Apache License 2.0 4 votes vote down vote up
/**
 * 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 videoController = 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 (videoController.hasVideoContent()) {
        mainImageView.setVisibility(View.GONE);
        adView.setMediaView(mediaView);
    } 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());
    }

    // 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);
    customControlsView.setVideoController(videoController);

    refresh.setEnabled(true);
}
 
Example #7
Source File: AdMobCustomMuteThisAdFragment.java    From android-ads with Apache License 2.0 4 votes vote down vote up
/**
 * Populates a {@link UnifiedNativeAdView} object with data from a given
 * {@link UnifiedNativeAd}.
 *
 * @param nativeAd the object containing the ad's assets
 * @param adView the view to be populated
 */
private void populateUnifiedNativeAdView(UnifiedNativeAd nativeAd, UnifiedNativeAdView adView) {
    MediaView mediaView = adView.findViewById(R.id.ad_media);
    adView.setMediaView(mediaView);

    adView.setHeadlineView(adView.findViewById(R.id.ad_headline));
    adView.setBodyView(adView.findViewById(R.id.ad_body));
    adView.setCallToActionView(adView.findViewById(R.id.ad_call_to_action));
    adView.setIconView(adView.findViewById(R.id.ad_app_icon));
    adView.setPriceView(adView.findViewById(R.id.ad_price));
    adView.setStarRatingView(adView.findViewById(R.id.ad_stars));
    adView.setStoreView(adView.findViewById(R.id.ad_store));
    adView.setAdvertiserView(adView.findViewById(R.id.ad_advertiser));

    ((TextView) adView.getHeadlineView()).setText(nativeAd.getHeadline());

    if (nativeAd.getBody() == null) {
        adView.getBodyView().setVisibility(View.INVISIBLE);
    } else {
        ((TextView) adView.getBodyView()).setText(nativeAd.getBody());
        adView.getBodyView().setVisibility(View.VISIBLE);
    }

    if (nativeAd.getCallToAction() == null) {
        adView.getCallToActionView().setVisibility(View.INVISIBLE);
    } else {
        ((Button) adView.getCallToActionView()).setText(nativeAd.getCallToAction());
        adView.getCallToActionView().setVisibility(View.VISIBLE);
    }

    if (nativeAd.getIcon() == null) {
        adView.getIconView().setVisibility(View.GONE);
    } else {
        ((ImageView) adView.getIconView()).setImageDrawable(
            nativeAd.getIcon().getDrawable());
        adView.getIconView().setVisibility(View.VISIBLE);
    }

    if (nativeAd.getPrice() == null) {
        adView.getPriceView().setVisibility(View.INVISIBLE);
    } else {
        ((TextView) adView.getPriceView()).setText(nativeAd.getPrice());
        adView.getPriceView().setVisibility(View.VISIBLE);
    }

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

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

    if (nativeAd.getAdvertiser() == null) {
        adView.getAdvertiserView().setVisibility(View.INVISIBLE);
    } else {
        ((TextView) adView.getAdvertiserView()).setText(nativeAd.getAdvertiser());
        adView.getAdvertiserView().setVisibility(View.VISIBLE);
    }

    adView.setNativeAd(nativeAd);

    VideoController vc = nativeAd.getVideoController();

    if (vc.hasVideoContent()) {
        vc.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
            @Override
            public void onVideoEnd() {
                refresh.setEnabled(true);
                super.onVideoEnd();
            }
        });
    } else {
        refresh.setEnabled(true);
    }
}
 
Example #8
Source File: DFPCustomControlsFragment.java    From googleads-mobile-android-examples with Apache License 2.0 4 votes vote down vote up
/**
 * 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) {
    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());

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

    MediaView mediaView = adView.findViewById(R.id.appinstall_media);
    ImageView mainImageView = adView.findViewById(R.id.appinstall_image);

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

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

    // These assets aren't guaranteed to be in every NativeAppInstallAd, so it's important to
    // check before trying to display them.
    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);
    }


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

    customControlsView.setVideoController(videoController);

    refresh.setEnabled(true);
}
 
Example #9
Source File: DFPCustomControlsFragment.java    From googleads-mobile-android-examples with Apache License 2.0 4 votes vote down vote up
/**
 * 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 videoController = 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 (videoController.hasVideoContent()) {
        mainImageView.setVisibility(View.GONE);
        adView.setMediaView(mediaView);
    } 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());
    }

    // 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);
    customControlsView.setVideoController(videoController);

    refresh.setEnabled(true);
}
 
Example #10
Source File: AdMobCustomMuteThisAdFragment.java    From googleads-mobile-android-examples with Apache License 2.0 4 votes vote down vote up
/**
 * Populates a {@link UnifiedNativeAdView} object with data from a given
 * {@link UnifiedNativeAd}.
 *
 * @param nativeAd the object containing the ad's assets
 * @param adView the view to be populated
 */
private void populateUnifiedNativeAdView(UnifiedNativeAd nativeAd, UnifiedNativeAdView adView) {
    adView.setMediaView((MediaView) adView.findViewById(R.id.ad_media));

    adView.setHeadlineView(adView.findViewById(R.id.ad_headline));
    adView.setBodyView(adView.findViewById(R.id.ad_body));
    adView.setCallToActionView(adView.findViewById(R.id.ad_call_to_action));
    adView.setIconView(adView.findViewById(R.id.ad_app_icon));
    adView.setPriceView(adView.findViewById(R.id.ad_price));
    adView.setStarRatingView(adView.findViewById(R.id.ad_stars));
    adView.setStoreView(adView.findViewById(R.id.ad_store));
    adView.setAdvertiserView(adView.findViewById(R.id.ad_advertiser));

    ((TextView) adView.getHeadlineView()).setText(nativeAd.getHeadline());
    adView.getMediaView().setMediaContent(nativeAd.getMediaContent());

    if (nativeAd.getBody() == null) {
        adView.getBodyView().setVisibility(View.INVISIBLE);
    } else {
        ((TextView) adView.getBodyView()).setText(nativeAd.getBody());
        adView.getBodyView().setVisibility(View.VISIBLE);
    }

    if (nativeAd.getCallToAction() == null) {
        adView.getCallToActionView().setVisibility(View.INVISIBLE);
    } else {
        ((Button) adView.getCallToActionView()).setText(nativeAd.getCallToAction());
        adView.getCallToActionView().setVisibility(View.VISIBLE);
    }

    if (nativeAd.getIcon() == null) {
        adView.getIconView().setVisibility(View.GONE);
    } else {
        ((ImageView) adView.getIconView()).setImageDrawable(
            nativeAd.getIcon().getDrawable());
        adView.getIconView().setVisibility(View.VISIBLE);
    }

    if (nativeAd.getPrice() == null) {
        adView.getPriceView().setVisibility(View.INVISIBLE);
    } else {
        ((TextView) adView.getPriceView()).setText(nativeAd.getPrice());
        adView.getPriceView().setVisibility(View.VISIBLE);
    }

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

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

    if (nativeAd.getAdvertiser() == null) {
        adView.getAdvertiserView().setVisibility(View.INVISIBLE);
    } else {
        ((TextView) adView.getAdvertiserView()).setText(nativeAd.getAdvertiser());
        adView.getAdvertiserView().setVisibility(View.VISIBLE);
    }

    adView.setNativeAd(nativeAd);

    VideoController vc = nativeAd.getVideoController();

    if (vc.hasVideoContent()) {
        vc.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() {
            @Override
            public void onVideoEnd() {
                refresh.setEnabled(true);
                super.onVideoEnd();
            }
        });
    } else {
        refresh.setEnabled(true);
    }
}