本文整理匯總了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);
}
示例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);
}
示例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();
}
示例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.");
}
}