本文整理汇总了Java中com.google.android.gms.ads.formats.NativeContentAdView类的典型用法代码示例。如果您正苦于以下问题:Java NativeContentAdView类的具体用法?Java NativeContentAdView怎么用?Java NativeContentAdView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NativeContentAdView类属于com.google.android.gms.ads.formats包,在下文中一共展示了NativeContentAdView类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onBindViewHolder
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的package包/类
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
if (viewHolder==null)
return;
int itemViewType = viewHolder.getItemViewType();
if(itemViewType == getViewTypeAdInstall()) {
NativeAppInstallAdView lvi1 = (NativeAppInstallAdView) viewHolder.itemView;
NativeAppInstallAd ad1 = (NativeAppInstallAd) getItem(position);
getInstallAdsLayoutContext().bind(lvi1, ad1);
}
else if(itemViewType == getViewTypeAdContent()) {
NativeContentAdView lvi2 = (NativeContentAdView) viewHolder.itemView;
NativeContentAd ad2 = (NativeContentAd) getItem(position);
getContentAdsLayoutContext().bind(lvi2, ad2);
}
else{
int origPos = AdapterCalculator.getOriginalContentPosition(position,
adFetcher.getFetchedAdsCount(), mAdapter.getItemCount());
mAdapter.onBindViewHolder(viewHolder, origPos);
}
}
开发者ID:clockbyte,项目名称:admobadapter,代码行数:22,代码来源:AdmobRecyclerAdapterWrapper.java
示例2: getContentAdViewHolder
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的package包/类
public ContentAdViewHolder getContentAdViewHolder() {
// There is no instance in which this will be called before getView(), so there is
// no reason getTag() should ever return a null value.
AdViewHolder holder = (AdViewHolder) mFrame.getTag();
if (holder instanceof ContentAdViewHolder) {
return (ContentAdViewHolder) holder;
} else {
mFrame.removeAllViews();
LayoutInflater inflater = (LayoutInflater) mFrame.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
NativeContentAdView adView = (NativeContentAdView) inflater
.inflate(R.layout.item_content_ad, mFrame, false);
mFrame.addView(adView);
ContentAdViewHolder contentAdViewHolder = new ContentAdViewHolder(adView);
mFrame.setTag(contentAdViewHolder);
return contentAdViewHolder;
}
}
开发者ID:googlesamples,项目名称:android-ads,代码行数:23,代码来源:MultiFormatAdPlacement.java
示例3: NativeContentAdViewHolder
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的package包/类
NativeContentAdViewHolder(View view) {
super(view);
NativeContentAdView adView = (NativeContentAdView) view;
// Register the view used for each individual asset.
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));
}
开发者ID:googlecodelabs,项目名称:admob-native-advanced-feed,代码行数:13,代码来源:NativeContentAdViewHolder.java
示例4: onBindViewHolder
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的package包/类
/**
* Replaces the content in the views that make up the menu item view and the
* Native Express ad view. This method is invoked by the layout manager.
*/
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
int viewType = getItemViewType(position);
switch (viewType) {
case NATIVE_APP_INSTALL_AD_VIEW_TYPE:
NativeAppInstallAd appInstallAd = (NativeAppInstallAd) mRecyclerViewItems.get(position);
populateAppInstallAdView(appInstallAd, (NativeAppInstallAdView) holder.itemView);
break;
case NATIVE_CONTENT_AD_VIEW_TYPE:
NativeContentAd contentAd = (NativeContentAd) mRecyclerViewItems.get(position);
populateContentAdView(contentAd, (NativeContentAdView) holder.itemView);
break;
case MENU_ITEM_VIEW_TYPE:
// fall through
default:
MenuItemViewHolder menuItemHolder = (MenuItemViewHolder) holder;
MenuItem menuItem = (MenuItem) mRecyclerViewItems.get(position);
// Get the menu item image resource ID.
String imageName = menuItem.getImageName();
int imageResID = mContext.getResources().getIdentifier(imageName, "drawable",
mContext.getPackageName());
// Add the menu item details to the menu item view.
menuItemHolder.menuItemImage.setImageResource(imageResID);
menuItemHolder.menuItemName.setText(menuItem.getName());
menuItemHolder.menuItemPrice.setText(menuItem.getPrice());
menuItemHolder.menuItemCategory.setText(menuItem.getCategory());
menuItemHolder.menuItemDescription.setText(menuItem.getDescription());
}
}
开发者ID:googlecodelabs,项目名称:admob-native-advanced-feed,代码行数:36,代码来源:RecyclerViewAdapter.java
示例5: populateContentAdView
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的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: prepare
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的package包/类
@Override
protected void prepare(@NonNull final NativeContentAdView adView, @NonNull final NativeContentAd nativeAd) {
final TextView adTitle = (TextView)adView.findViewById(R.id.ad_title);
final TextView adBody = (TextView)adView.findViewById(R.id.ad_body);
final ImageView adImage = (ImageView)adView.findViewById(R.id.ad_image);
final TextView adCallToAction = (TextView)adView.findViewById(R.id.ad_call_to_action);
adView.setHeadlineView(adTitle);
adView.setBodyView(adBody);
adView.setImageView(adImage);
adView.setCallToActionView(adCallToAction);
}
开发者ID:ayltai,项目名称:mopub-nativead-adapters,代码行数:13,代码来源:SampleAdMobNativeAd.java
示例7: populateContentAdView
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的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
示例8: ContentAdViewHolder
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的package包/类
/**
* Stores the View for a {@link NativeContentAd} and locates specific {@link View}s used
* to display its assets.
*
* @param adView the {@link View} used to display assets for a native content ad.
*/
public ContentAdViewHolder(NativeContentAdView adView) {
mAdView = adView;
mAdView.setHeadlineView(mAdView.findViewById(R.id.contentad_headline));
mAdView.setImageView(mAdView.findViewById(R.id.contentad_image));
mAdView.setBodyView(mAdView.findViewById(R.id.contentad_body));
mAdView.setCallToActionView(mAdView.findViewById(R.id.contentad_call_to_action));
mAdView.setLogoView(mAdView.findViewById(R.id.contentad_logo));
mAdView.setAdvertiserView(mAdView.findViewById(R.id.contentad_advertiser));
}
开发者ID:googlesamples,项目名称:android-ads,代码行数:17,代码来源:ContentAdViewHolder.java
示例9: getView
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的package包/类
/**
* Creates or reuses a {@link FrameLayout} for this ad placement, filling it asynchronously
* with the assets for its {@link com.google.android.gms.ads.formats.NativeContentAd}.
*
* @param convertView a {@link View} to reuse if possible
* @param parent The {@link ViewGroup} into which the {@link View} will be placed
* @return a {@link FrameLayout} that contains or will contain the ad assets for this placement
*/
@Override
public View getView(View convertView, ViewGroup parent) {
// For each native ad, a FrameLayout is created and returned to the ListView as
// the item's root view. This allows the fetcher to asynchronously request an ad, which
// will be converted into a set of Views and placed into the FrameLayout by the
// ViewHolder object.
FrameLayout frameLayout = (FrameLayout) convertView;
ContentAdViewHolder holder
= (frameLayout == null) ? null : (ContentAdViewHolder) frameLayout.getTag();
// If the holder is null, either this is the first time the item has been displayed, or
// convertView held a different type of item before. In either case, a new FrameLayout
// and ViewHolder should be created and used.
if (holder == null) {
frameLayout = new FrameLayout(parent.getContext());
LayoutInflater inflater = (LayoutInflater) parent.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
NativeContentAdView adView = (NativeContentAdView) inflater
.inflate(R.layout.item_content_ad, frameLayout, false);
frameLayout.addView(adView);
holder = new ContentAdViewHolder(adView);
frameLayout.setTag(holder);
}
// This statement kicks off the ad loading process. The ViewHolder has some interface
// methods that will be invoked when the ad is ready to be displayed or fails to load.
mFetcher.loadAd(frameLayout.getContext(), holder);
// The FrameLayout is returned to the ListView so it will have something to show for the
// item right now. The FrameLayout will be filled with native ad assets later, once the
// ad has finished loading.
return frameLayout;
}
开发者ID:googlesamples,项目名称:android-ads,代码行数:45,代码来源:ContentAdPlacement.java
示例10: populateContentAdView
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的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
示例11: trackView
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的package包/类
@Override
public void trackView(final View view) {
view.post(new Runnable() {
@Override
public void run() {
if (view instanceof NativeContentAdView) {
NativeContentAdView nativeContentAdView = (NativeContentAdView) view;
final ArrayList<View> assetViews = new ArrayList<>();
if (nativeContentAdView.getHeadlineView() != null) {
assetViews.add(nativeContentAdView.getHeadlineView());
}
if (nativeContentAdView.getBodyView() != null) {
assetViews.add(nativeContentAdView.getBodyView());
}
if (nativeContentAdView.getCallToActionView() != null) {
assetViews.add(nativeContentAdView.getCallToActionView());
}
if (nativeContentAdView.getAdvertiserView() != null) {
assetViews.add(nativeContentAdView.getAdvertiserView());
}
if (nativeContentAdView.getImageView() != null) {
assetViews.add(nativeContentAdView.getImageView());
}
if (nativeContentAdView.getLogoView() != null) {
assetViews.add(nativeContentAdView.getLogoView());
}
if (nativeContentAdView.getMediaView() != null) {
assetViews.add(mediaAdView);
}
nativeAd.registerView(view, assetViews);
} else {
Log.w(TAG, "Failed to register view for interaction.");
}
}
});
}
开发者ID:googleads,项目名称:googleads-mobile-android-mediation,代码行数:46,代码来源:MyTargetNativeAdapter.java
示例12: bind
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的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
示例13: populateContentAdView
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的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
示例14: prepare
import com.google.android.gms.ads.formats.NativeContentAdView; //导入依赖的package包/类
/**
* To render ad view properly, implementation is expected to call {@link NativeContentAdView#setHeadlineView(View)}, {@link NativeContentAdView#setBodyView(View)}, {@link NativeContentAdView#setCallToActionView(View)}, and/or {@link NativeContentAdView#setImageView(View)} methods,
* and render the ad view text/images using {@link NativeContentAd#getHeadline()}, {@link NativeContentAd#getBody()}, {@link NativeContentAd#getCallToAction()}, and/or {@link NativeContentAd#getImages()} methods.
* @param adView The native ad view to render the ad.
* @param nativeAd The native ad instance used to render the ad view.
*/
protected abstract void prepare(@NonNull NativeContentAdView adView, @NonNull NativeContentAd nativeAd);
开发者ID:ayltai,项目名称:mopub-nativead-adapters,代码行数:8,代码来源:AdMobNativeAd.java
注:本文中的com.google.android.gms.ads.formats.NativeContentAdView类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论