当前位置: 首页>>代码示例>>Java>>正文


Java NativeContentAdView.setCallToActionView方法代码示例

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


在下文中一共展示了NativeContentAdView.setCallToActionView方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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


注:本文中的com.google.android.gms.ads.formats.NativeContentAdView.setCallToActionView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。