Java Code Examples for com.facebook.ads.NativeAd#getAdIcon()

The following examples show how to use com.facebook.ads.NativeAd#getAdIcon() . 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: TimelineAdapter.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
public void inflateAd(NativeAd nativeAd, View adView, Context context) {
    // Create native UI using the ad metadata.

    ImageView nativeAdIcon = (ImageView) adView.findViewById(R.id.nativeAdIcon);
    TextView nativeAdTitle = (TextView) adView.findViewById(R.id.nativeAdTitle);
    TextView nativeAdTitleRating = (TextView) adView.findViewById(R.id.nativeAdTitleRating);
    TextView nativeAdBody = (TextView) adView.findViewById(R.id.nativeAdBody);

    ImageView nativeAdImage = (ImageView) adView.findViewById(R.id.nativeAdImage);
    TextView nativeAdSocialContext = (TextView) adView.findViewById(R.id.nativeAdSocialContext);
    FaceBookAdButton nativeAdCallToAction = (FaceBookAdButton) adView.findViewById(R.id.nativeAdCallToAction);
    RatingBar nativeAdStarRating = (RatingBar) adView.findViewById(R.id.nativeAdStarRating);

    // Setting the Text
    nativeAdSocialContext.setText(nativeAd.getAdSocialContext());
    nativeAdCallToAction.setText(nativeAd.getAdCallToAction());
    nativeAdTitle.setText(nativeAd.getAdTitle());
    nativeAdTitleRating.setText(nativeAd.getAdTitle());
    nativeAdBody.setText(nativeAd.getAdBody());

    // Downloading and setting the ad icon.
    NativeAd.Image adIcon = nativeAd.getAdIcon();
    NativeAd.downloadAndDisplayImage(adIcon, nativeAdIcon);

    // Downloading and setting the cover image.
    NativeAd.Image adCoverImage = nativeAd.getAdCoverImage();
    int bannerWidth = adCoverImage.getWidth();
    int bannerHeight = adCoverImage.getHeight();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
    int screenWidth = metrics.widthPixels;
    int screenHeight = metrics.heightPixels;
    nativeAdImage.setLayoutParams(new LinearLayout.LayoutParams(
            screenWidth,
            Math.min((int) (((double) screenWidth / (double) bannerWidth) * bannerHeight), screenHeight / 3)
    ));
    NativeAd.downloadAndDisplayImage(adCoverImage, nativeAdImage);

    NativeAd.Rating rating = nativeAd.getAdStarRating();
    if (rating != null) {
        nativeAdStarRating.setVisibility(View.VISIBLE);
        nativeAdStarRating.setNumStars((int) rating.getScale());
        nativeAdStarRating.setRating((float) rating.getValue());
    } else {
        nativeAdStarRating.setVisibility(View.GONE);
    }

    // Wire up the View with the native ad, the whole nativeAdContainer will be clickable
    //nativeAd.registerViewForInteraction(adView);


    // Or you can replace the above call with the following function to specify the clickable areas.
    nativeAd.registerViewForInteraction(adView, Arrays.asList(nativeAdCallToAction));

}
 
Example 2
Source File: FacebookAdapter.java    From googleads-mobile-android-mediation with Apache License 2.0 2 votes vote down vote up
/**
 * This method will check whether or not the given Facebook native ad contains all the necessary
 * fields for it to be mapped to Google Mobile Ads' native app install ad.
 *
 * @param nativeAd Facebook native ad.
 * @return {@code true} if the given ad contains all the necessary fields, {@link false}
 * otherwise.
 */
private boolean containsRequiredFieldsForNativeAppInstallAd(NativeAd nativeAd) {
  return ((nativeAd.getAdHeadline() != null) && (nativeAd.getAdCoverImage() != null)
      && (nativeAd.getAdBodyText() != null) && (nativeAd.getAdIcon() != null)
      && (nativeAd.getAdCallToAction() != null) && (mMediaView != null));
}
 
Example 3
Source File: FacebookAdapter.java    From googleads-mobile-android-mediation with Apache License 2.0 2 votes vote down vote up
/**
 * This method will check whether or not the given Facebook native ad contains all the necessary
 * fields for it to be mapped to Google Mobile Ads' Unified install ad.
 *
 * @param nativeAd Facebook native ad.
 * @return {@code true} if the given ad contains all the necessary fields, {@link false}
 * otherwise.
 */
private boolean containsRequiredFieldsForUnifiedNativeAd(NativeAd nativeAd) {
  return ((nativeAd.getAdHeadline() != null) && (nativeAd.getAdCoverImage() != null)
      && (nativeAd.getAdBodyText() != null) && (nativeAd.getAdIcon() != null)
      && (nativeAd.getAdCallToAction() != null) && (mMediaView != null));
}