• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NativeContentAd类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.android.gms.ads.formats.NativeContentAd的典型用法代码示例。如果您正苦于以下问题:Java NativeContentAd类的具体用法?Java NativeContentAd怎么用?Java NativeContentAd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NativeContentAd类属于com.google.android.gms.ads.formats包,在下文中一共展示了NativeContentAd类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onBindViewHolder

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的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: populateView

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的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: getItemViewType

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的package包/类
/**
 * Determines the view type for the given position.
 */
@Override
public int getItemViewType(int position) {

    Object recyclerViewItem = mRecyclerViewItems.get(position);
    if (recyclerViewItem instanceof NativeAppInstallAd) {
        return NATIVE_APP_INSTALL_AD_VIEW_TYPE;
    } else if (recyclerViewItem instanceof NativeContentAd) {
        return NATIVE_CONTENT_AD_VIEW_TYPE;
    }
    return MENU_ITEM_VIEW_TYPE;
}
 
开发者ID:googlecodelabs,项目名称:admob-native-advanced-feed,代码行数:15,代码来源:RecyclerViewAdapter.java


示例4: onBindViewHolder

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的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.NativeContentAd; //导入依赖的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.NativeContentAd; //导入依赖的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: onContentAdLoaded

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的package包/类
@Override
public void onContentAdLoaded(final NativeContentAd nativeAd) {
    this.nativeContentAd = nativeAd;

    this.render(this.nativeContentAd);

    this.setImpressionMinTimeViewed(BaseStaticNativeAd.IMPRESSION_MIN_TIME);
}
 
开发者ID:ayltai,项目名称:mopub-nativead-adapters,代码行数:9,代码来源:AdMobNativeAd.java


示例8: setupAds

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的package包/类
/**
 * Subscribing to the native ads events
 */
protected synchronized void setupAds() {
    String unitId = getReleaseUnitId() != null ? getReleaseUnitId() : getDefaultUnitId();
    AdLoader.Builder adloaderBuilder = new AdLoader.Builder(mContext.get(), unitId)
            .withAdListener(new AdListener() {
                @Override
                public void onAdFailedToLoad(int errorCode) {
                    // Handle the failure by logging, altering the UI, etc.
                    Log.i(TAG, "onAdFailedToLoad " + errorCode);
                    lockFetch.set(false);
                    mFetchFailCount++;
                    mFetchingAdsCnt--;
                    ensurePrefetchAmount();
                    onAdFailed( mPrefetchedAdList.size(), errorCode, null);
                }
            })
            .withNativeAdOptions(new NativeAdOptions.Builder()
                    // Methods in the NativeAdOptions.Builder class can be
                    // used here to specify individual options settings.
                    .build());
    if(getAdTypeToFetch().contains(EAdType.ADVANCED_INSTALLAPP))
        adloaderBuilder.forAppInstallAd(new NativeAppInstallAd.OnAppInstallAdLoadedListener() {
                @Override
                public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) {
                    onAdFetched(appInstallAd);
                }
            });
    if(getAdTypeToFetch().contains(EAdType.ADVANCED_CONTENT))
        adloaderBuilder.forContentAd(new NativeContentAd.OnContentAdLoadedListener() {
                @Override
                public void onContentAdLoaded(NativeContentAd contentAd) {
                    onAdFetched(contentAd);
                }
            });

    adLoader = adloaderBuilder.build();
}
 
开发者ID:clockbyte,项目名称:admobadapter,代码行数:40,代码来源:AdmobFetcher.java


示例9: populateContentAdView

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的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


示例10: loadAd

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的package包/类
/**
 * Loads a {@link NativeContentAd} and calls {@link ContentAdViewHolder} methods to
 * display its assets or handle failure by hiding the view.
 */
public void loadAd(Context context, ContentAdViewHolder viewHolder) {
    synchronized (mSyncObject) {
        mViewHolder = viewHolder;

        if ((mAdLoader != null) && mAdLoader.isLoading()) {
            Log.d(MainActivity.LOG_TAG, "ContentAdFetcher is already loading an ad.");
            return;
        }

        // If an ad previously loaded, reuse it instead of requesting a new one.
        if (mContentAd != null) {
            mViewHolder.populateView(mContentAd);
            return;
        }

        NativeContentAd.OnContentAdLoadedListener contentAdListener =
                new NativeContentAd.OnContentAdLoadedListener() {
                    public void onContentAdLoaded(NativeContentAd ad) {
                        mContentAd = ad;
                        mViewHolder.populateView(mContentAd);
                    }
                };

        if (mAdLoader == null) {
            mAdLoader = new AdLoader.Builder(context, mAdUnitId)
                    .forContentAd(contentAdListener)
                    .withAdListener(new AdListener() {
                        @Override
                        public void onAdFailedToLoad(int errorCode) {
                            mViewHolder.hideView();
                            Log.e(MainActivity.LOG_TAG,
                                    "Content Ad Failed to load: " + errorCode);
                        }
                    }).build();
        }

        mAdLoader.loadAd(new PublisherAdRequest.Builder().build());
    }
}
 
开发者ID:googlesamples,项目名称:android-ads,代码行数:44,代码来源:ContentAdFetcher.java


示例11: AdMobNativeAdResponse

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的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


示例12: onBindViewHolder

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的package包/类
@Override
public void onBindViewHolder(final NativeAdViewHolder holder, final int position) {
    final NativeAd nativeAd = this.nativeAds.get(position);

    if (nativeAd != null) {
        holder.itemView.addOnAttachStateChangeListener(this);

        // Not sure what the previous ad type is, so just clear all of them
        NativeAdAdapter.clear(nativeAd, holder, NativeAdAdapter.ID_ADMOB_APP_INSTALL_AD_VIEW);
        NativeAdAdapter.clear(nativeAd, holder, NativeAdAdapter.ID_ADMOB_CONTENT_AD_VIEW);
        NativeAdAdapter.clear(nativeAd, holder, NativeAdAdapter.ID_ADMOB_NORMAL_AD_VIEW);

        final StaticNativeAd staticNativeAd = (StaticNativeAd)nativeAd.getBaseNativeAd();

        int viewId = 0;

        // AdMob native ads need special handling
        if (staticNativeAd instanceof AdMobNativeAd) {
            final com.google.android.gms.ads.formats.NativeAd ad = ((AdMobNativeAd)staticNativeAd).getNativeAd();

            if (ad instanceof NativeAppInstallAd) {
                holder.setAdType(NativeAdViewHolder.AD_TYPE_ADMOB_APP_INSTALL);

                viewId = NativeAdAdapter.ID_ADMOB_APP_INSTALL_AD_VIEW;
            } else if (ad instanceof NativeContentAd) {
                holder.setAdType(NativeAdViewHolder.AD_TYPE_ADMOB_CONTENT);

                viewId = NativeAdAdapter.ID_ADMOB_CONTENT_AD_VIEW;
            } else {
                Log.w(this.getClass().getSimpleName(), String.format("Unexpected AdMob native ad type: %s", ad.getClass()));
            }
        } else {
            holder.setAdType(NativeAdViewHolder.AD_TYPE_NORMAL);

            viewId = NativeAdAdapter.ID_ADMOB_NORMAL_AD_VIEW;
        }

        if (viewId > 0) {
            nativeAd.renderAdView(holder.adContainer.findViewById(viewId));
            nativeAd.prepare(holder.adContainer.findViewById(viewId));
        }

        NativeAdAdapter.resizeAdImage(holder, R.id.ad_image);
    }
}
 
开发者ID:ayltai,项目名称:mopub-nativead-adapters,代码行数:46,代码来源:NativeAdAdapter.java


示例13: setHeadline

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的package包/类
private void setHeadline(@NonNull final NativeContentAd nativeAd) {
    if (!TextUtils.isEmpty(nativeAd.getHeadline())) this.setTitle(nativeAd.getHeadline().toString());
}
 
开发者ID:ayltai,项目名称:mopub-nativead-adapters,代码行数:4,代码来源:AdMobNativeAd.java


示例14: setBody

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的package包/类
private void setBody(@NonNull final NativeContentAd nativeAd) {
    if (!TextUtils.isEmpty(nativeAd.getBody())) this.setText(nativeAd.getBody().toString());
}
 
开发者ID:ayltai,项目名称:mopub-nativead-adapters,代码行数:4,代码来源:AdMobNativeAd.java


示例15: setCallToAction

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的package包/类
private void setCallToAction(@NonNull final NativeContentAd nativeAd) {
    if (!TextUtils.isEmpty(nativeAd.getCallToAction())) this.setCallToAction(nativeAd.getCallToAction().toString());
}
 
开发者ID:ayltai,项目名称:mopub-nativead-adapters,代码行数:4,代码来源:AdMobNativeAd.java


示例16: populateContentAdView

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的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


示例17: bind

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的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.NativeContentAd; //导入依赖的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: onContentAdLoaded

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的package包/类
@Override
public void onContentAdLoaded(NativeContentAd nativeContentAd) {
    if (mBC != null) {
        mBC.onAdLoaded(new AdMobNativeAdResponse(nativeContentAd, AdMobNativeSettings.AdMobNativeType.CONTENT_AD));
    }
}
 
开发者ID:appnexus,项目名称:mobile-sdk-android,代码行数:7,代码来源:AdMobNativeListener.java


示例20: prepare

import com.google.android.gms.ads.formats.NativeContentAd; //导入依赖的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.NativeContentAd类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BlobId类代码示例发布时间:2022-05-23
下一篇:
Java RecordConsumer类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap