本文整理汇总了Java中com.google.android.gms.ads.formats.NativeAd类的典型用法代码示例。如果您正苦于以下问题:Java NativeAd类的具体用法?Java NativeAd怎么用?Java NativeAd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NativeAd类属于com.google.android.gms.ads.formats包,在下文中一共展示了NativeAd类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:googlesamples,项目名称:android-ads,代码行数:32,代码来源:ContentAdViewHolder.java
示例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);
}
开发者ID:googlesamples,项目名称:android-ads,代码行数:29,代码来源:AppInstallAdViewHolder.java
示例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;
}
}
开发者ID:googlecodelabs,项目名称:admob-native-advanced-feed,代码行数:13,代码来源:MainActivity.java
示例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);
}
开发者ID:googlecodelabs,项目名称:admob-native-advanced-feed,代码行数:35,代码来源:RecyclerViewAdapter.java
示例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);
}
开发者ID:clockbyte,项目名称:admobadapter,代码行数:17,代码来源:AdmobFetcher.java
示例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);
}
}
开发者ID:clockbyte,项目名称:admobadapter,代码行数:13,代码来源:AdmobRecyclerAdapterWrapper.java
示例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);
}
开发者ID:googlesamples,项目名称:android-ads,代码行数:45,代码来源:MainActivity.java
示例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();
}
开发者ID:appnexus,项目名称:mobile-sdk-android,代码行数:38,代码来源:AdMobNativeAdResponse.java
示例13: getNativeAd
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
public NativeAd getNativeAd() {
return this.nativeAppInstallAd == null ? this.nativeContentAd : this.nativeAppInstallAd;
}
开发者ID:ayltai,项目名称:mopub-nativead-adapters,代码行数:4,代码来源:AdMobNativeAd.java
示例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));
}
}
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:80,代码来源:MainActivity.java
示例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));
}
}
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:53,代码来源:MainActivity.java
示例16: bind
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
@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);
}
开发者ID:clockbyte,项目名称:admobadapter,代码行数:48,代码来源:InstallAppAdLayoutContext.java
示例17: bind
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
@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);
}
开发者ID:clockbyte,项目名称:admobadapter,代码行数:44,代码来源:ContentAdLayoutContext.java
示例18: 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) {
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);
}
开发者ID:googlesamples,项目名称:android-ads,代码行数:77,代码来源:MainActivity.java
示例19: bind
import com.google.android.gms.ads.formats.NativeAd; //导入依赖的package包/类
public abstract void bind(NativeAdView nativeAdView, NativeAd nativeAd);
开发者ID:clockbyte,项目名称:admobadapter,代码行数:2,代码来源:NativeAdLayoutContext.java
注:本文中的com.google.android.gms.ads.formats.NativeAd类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论