本文整理汇总了Java中com.facebook.ads.NativeAd.downloadAndDisplayImage方法的典型用法代码示例。如果您正苦于以下问题:Java NativeAd.downloadAndDisplayImage方法的具体用法?Java NativeAd.downloadAndDisplayImage怎么用?Java NativeAd.downloadAndDisplayImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.ads.NativeAd
的用法示例。
在下文中一共展示了NativeAd.downloadAndDisplayImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inflateAd
import com.facebook.ads.NativeAd; //导入方法依赖的package包/类
private void inflateAd(NativeAd nativeAd, View adView) {
// Create native UI using the ad metadata.
ImageView nativeAdIcon = (ImageView) adView.findViewById(R.id.native_ad_icon);
TextView nativeAdTitle = (TextView) adView.findViewById(R.id.native_ad_title);
TextView nativeAdBody = (TextView) adView.findViewById(R.id.native_ad_body);
MediaView nativeAdMedia = (MediaView) adView.findViewById(R.id.native_ad_media);
nativeAdMedia.setAutoplay(AdSettings.isVideoAutoplay());
TextView nativeAdSocialContext =
(TextView) adView.findViewById(R.id.native_ad_social_context);
Button nativeAdCallToAction = (Button) adView.findViewById(R.id.native_ad_call_to_action);
// Setting the Text
nativeAdSocialContext.setText(nativeAd.getAdSocialContext());
nativeAdCallToAction.setText(nativeAd.getAdCallToAction());
nativeAdCallToAction.setVisibility(View.VISIBLE);
nativeAdTitle.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();
DisplayMetrics metrics = myContext.getResources().getDisplayMetrics();
int mediaWidth = adView.getWidth() > 0 ? adView.getWidth() : metrics.widthPixels;
nativeAdMedia.setLayoutParams(new LinearLayout.LayoutParams(
mediaWidth,
Math.min(
(int) (((double) mediaWidth / (double) bannerWidth) * bannerHeight),
metrics.heightPixels / 7))); // eskiden 3
nativeAdMedia.setNativeAd(nativeAd);
// Wire up the View with the native ad, the whole nativeAdContainer will be clickable.
nativeAd.registerViewForInteraction(adView);
}
示例2: inflateAd
import com.facebook.ads.NativeAd; //导入方法依赖的package包/类
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));
}
示例3: inflateAd
import com.facebook.ads.NativeAd; //导入方法依赖的package包/类
public static 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 nativeAdBody = (TextView) adView.findViewById(R.id.nativeAdBody);
ImageView nativeAdImage = (ImageView) adView.findViewById(R.id.nativeAdImage);
TextView nativeAdSocialContext = (TextView) adView.findViewById(R.id.nativeAdSocialContext);
Button nativeAdCallToAction = (Button) adView.findViewById(R.id.nativeAdCallToAction);
RatingBar nativeAdStarRating = (RatingBar) adView.findViewById(R.id.nativeAdStarRating);
// Setting the Text
nativeAdSocialContext.setText(nativeAd.getAdSocialContext());
nativeAdCallToAction.setText(nativeAd.getAdCallToAction());
nativeAdCallToAction.setVisibility(View.VISIBLE);
nativeAdTitle.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(nativeAdContainer, Arrays.asList(nativeAdCallToAction, nativeAdImage));
}