當前位置: 首頁>>代碼示例>>Java>>正文


Java NativeCustomTemplateAd類代碼示例

本文整理匯總了Java中com.google.android.gms.ads.formats.NativeCustomTemplateAd的典型用法代碼示例。如果您正苦於以下問題:Java NativeCustomTemplateAd類的具體用法?Java NativeCustomTemplateAd怎麽用?Java NativeCustomTemplateAd使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NativeCustomTemplateAd類屬於com.google.android.gms.ads.formats包,在下文中一共展示了NativeCustomTemplateAd類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: populateView

import com.google.android.gms.ads.formats.NativeCustomTemplateAd; //導入依賴的package包/類
/**
 * Populates the asset {@link View}s with data
 * from the {@link NativeCustomTemplateAd} object. This method is invoked when an
 * {@link SimpleCustomTemplateAdFetcher} has successfully loaded a
 * {@link NativeCustomTemplateAd}.
 *
 * @param customTemplateAd the ad that is to be displayed
 */
public void populateView(final NativeCustomTemplateAd customTemplateAd) {
    mHeadline.setText(customTemplateAd.getText(HEADLINE_TEMPLATE_FIELD_NAME));
    mCaption.setText(customTemplateAd.getText(CAPTION_TEMPLATE_FIELD_NAME));

    mMainImage.setImageDrawable(
            customTemplateAd.getImage(MAINIMAGE_TEMPLATE_FIELD_NAME).getDrawable());
    mMainImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            customTemplateAd.performClick(MAINIMAGE_TEMPLATE_FIELD_NAME);
        }
    });

    mAdView.setVisibility(View.VISIBLE);
}
 
開發者ID:googlesamples,項目名稱:android-ads,代碼行數:24,代碼來源:SimpleCustomTemplateAdViewHolder.java

示例2: populateView

import com.google.android.gms.ads.formats.NativeCustomTemplateAd; //導入依賴的package包/類
/**
 * Populates the asset {@link View}s with data from the {@link NativeCustomTemplateAd} object.
 * This method is invoked when an {@link SimpleCustomTemplateAdFetcher} has successfully loaded
 * a {@link NativeCustomTemplateAd}.
 *
 * @param customTemplateAd the ad that is to be displayed
 */
public void populateView(final NativeCustomTemplateAd customTemplateAd) {
    mHeadline.setText(customTemplateAd.getText(HEADLINE_TEMPLATE_FIELD_NAME));
    mCaption.setText(customTemplateAd.getText(CAPTION_TEMPLATE_FIELD_NAME));
    mBody.setText(customTemplateAd.getText(BODY_TEMPLATE_FIELD_NAME));
    mCallToAction.setText(customTemplateAd.getText(CALLTOACTION_TEMPLATE_FIELD_NAME));
    mMainImage.setImageDrawable(
            customTemplateAd.getImage(MAINIMAGE_TEMPLATE_FIELD_NAME).getDrawable());

    mCallToAction.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            customTemplateAd.performClick(CALLTOACTION_TEMPLATE_FIELD_NAME);
        }
    });

    mAdView.setVisibility(View.VISIBLE);
}
 
開發者ID:googlesamples,項目名稱:android-ads,代碼行數:25,代碼來源:ExtendedCustomTemplateAdViewHolder.java

示例3: processClick

import com.google.android.gms.ads.formats.NativeCustomTemplateAd; //導入依賴的package包/類
/**
 * Processes the custom click events from the {@link NativeCustomTemplateAd}. In this case, a
 * {@link Toast} is displayed, but other applications might change UI elements or enable/disable
 * inputs in response to these click events.
 *
 * @param customTemplateAd the ad object that's invoking the method
 * @param assetName        the name of the asset that was clicked by the user
 */
public void processClick(NativeCustomTemplateAd customTemplateAd,
                         String assetName) {
    Context context = mAdView.getContext();
    String messageFormatString = context.getResources().getString(R.string.custom_click_toast);
    String message = String.format(messageFormatString, assetName,
            customTemplateAd.getCustomTemplateId());
    Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
 
開發者ID:googlesamples,項目名稱:android-ads,代碼行數:17,代碼來源:SimpleCustomTemplateAdViewHolder.java

示例4: populateSimpleTemplateAdView

import com.google.android.gms.ads.formats.NativeCustomTemplateAd; //導入依賴的package包/類
/**
 * Populates a {@link View} object with data from a {@link NativeCustomTemplateAd}. This method
 * handles a particular "simple" custom native ad format.
 *
 * @param nativeCustomTemplateAd the object containing the ad's assets
 * @param adView                 the view to be populated
 */
private void populateSimpleTemplateAdView(final NativeCustomTemplateAd nativeCustomTemplateAd,
                                          View adView) {
    TextView headline = adView.findViewById(R.id.simplecustom_headline);
    TextView caption = adView.findViewById(R.id.simplecustom_caption);

    headline.setText(nativeCustomTemplateAd.getText("Headline"));
    caption.setText(nativeCustomTemplateAd.getText("Caption"));

    FrameLayout mediaPlaceholder = adView.findViewById(R.id.simplecustom_media_placeholder);

    // Get the video controller for the ad. One will always be provided, even if the ad doesn't
    // have a video asset.
    VideoController vc = nativeCustomTemplateAd.getVideoController();

    // Apps can check the VideoController's hasVideoContent property to determine if the
    // NativeCustomTemplateAd has a video asset.
    if (vc.hasVideoContent()) {
        mediaPlaceholder.addView(nativeCustomTemplateAd.getVideoMediaView());
        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 {
        ImageView mainImage = new ImageView(this);
        mainImage.setAdjustViewBounds(true);
        mainImage.setImageDrawable(nativeCustomTemplateAd.getImage("MainImage").getDrawable());

        mainImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                nativeCustomTemplateAd.performClick("MainImage");
            }
        });
        mediaPlaceholder.addView(mainImage);
        mRefresh.setEnabled(true);
        mVideoStatus.setText("Video status: Ad does not contain a video asset.");
    }
}
 
開發者ID:googlesamples,項目名稱:android-ads,代碼行數:58,代碼來源:MainActivity.java


注:本文中的com.google.android.gms.ads.formats.NativeCustomTemplateAd類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。