本文整理汇总了Java中com.google.android.gms.ads.formats.NativeAd类的典型用法代码示例。如果您正苦于以下问题:Java NativeAd类的具体用法?Java NativeAd怎么用?Java NativeAd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NativeAd类属于com.google.android.gms.ads.formats包,在下文中一共展示了NativeAd类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SampleNativeContentAdMapper
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
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());
}
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:27,代码来源:SampleNativeContentAdMapper.java
示例2: populateView
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
/**
* 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);
}
示例3: populateView
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
/**
* 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);
}
示例4: insertAdsInMenuItems
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
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;
}
}
示例5: populateContentAdView
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
/**
* 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);
}
示例6: SampleNativeContentAdMapper
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
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());
}
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:37,代码来源:SampleNativeContentAdMapper.java
示例7: SampleNativeAppInstallAdMapper
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
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());
}
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:40,代码来源:SampleNativeAppInstallAdMapper.java
示例8: SampleNativeAppInstallAdMapper
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
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());
}
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:30,代码来源:SampleNativeAppInstallAdMapper.java
示例9: onAdFetched
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
/**
* 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);
}
示例10: getItemViewType
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
@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);
}
}
示例11: populateContentAdView
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
/**
* 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);
}
示例12: AdMobNativeAdResponse
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
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();
}
示例13: getNativeAd
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
public NativeAd getNativeAd() {
return this.nativeAppInstallAd == null ? this.nativeContentAd : this.nativeAppInstallAd;
}
示例14: populateAppInstallAdView
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
/**
* 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));
}
}
示例15: populateContentAdView
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
/**
* 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));
}
}