Draw ads are a special type of native ad rendering, generally displayed in full-screen mode, suitable for full-screen page-swipe info feed ads. Draw ads support both self-rendering and template rendering types. The general effect of Draw ads is as follows:

(1) When the app starts, use ATNative.makeAdRequest to execute ad loading. Request ads in advance so that ads can be quickly displayed when needed.
(2) It is recommended to call entryAdScenario(placementId,scenarioId) after entering a displayable ad scenario to count the cache status of the current Ad Placement. For detailed usage of statistics, see Ad Scenarios for distinguishing data across different business scenarios.
(3) Do not execute the ad loading method in the onNativeAdLoadFail callback, otherwise it will cause many unnecessary requests and may cause the app to lag.
(4) Get the ad object via ATNative.getNativeAd at the position where native ads need to be displayed to check whether it is null:
ATNative.makeAdRequest to load ads.NativeAd ad object. At this point, you can directly call ATNative.makeAdRequest again to preload the next ad (as long as you have called ATNative.getNativeAd, you can directly preload the next ad).(5) It is recommended to configure a preset strategy to improve the ad loading efficiency during the first cold start. For specific instructions and integration tutorials, see SDK Preset Strategy Instructions.
Note: For Pangle (China), and Pangle, ensure that an Activity is passed when creating the ATNativeAdView instance. For Kuaishou, the ATNativeAdView height must be match_parent.
For detailed sample code, refer to Demo: Taku SDK Demo. For Draw ad integration, refer to the NativeDrawVideoActivity.java class in the Demo.
ATNative atNative;
NativeAd mNativeAd;
int adViewWidth;
int adViewHeight;
public void loadNativeAd() {
if (atNative == null) {
// Initialize the ad loading object
atNative = new ATNative(this, nativeTakuPlacementID, new ATNativeNetworkListener() {
@Override
public void onNativeAdLoaded() {
Log.i(TAG, "onNativeAdLoaded");
}
@Override
public void onNativeAdLoadFail(AdError adError) {
// Note: Do not execute the ad loading method in this callback for retry, otherwise it will cause many unnecessary requests and may cause the app to lag.
// AdError, please refer to https://docs.takuad.com/#/zh-cn/android/android_doc/android_test?id=aderror
Log.i(TAG, "onNativeAdLoadFail:" + adError.getFullErrorInfo());
}
});
}
// Initiate ad request
atNative.makeAdRequest();
}
ATNativeAdView mATNativeAdView; // Container that must be created for rendering ads.
View mSelfRenderView; // Developer custom layout container.
public void showNativeAd(ViewGroup adContainer, int adViewWidth) {
/*
To count scenario arrival rate, related info can be found at "https://help.takuad.com/docs/1RWLAv"
Call the “enter ad scenario” method when the ad triggering conditions are met, for example:
** If the ad scenario is to display an ad after a cleanup is finished, call it when the cleanup is finished;
* 1. First call "entryAdScenario"
* 2. Then call "ATNative#checkAdStatus#isReady" to check if it is displayable
* 3. Finally call "getNativeAd" to display
* 4. Passing the scenario ID into scenario will only result in data reaching the dashboard funnel report (optional).
*/
ATNative.entryAdScenario("your Native placementID", "your scenarioID");
if (atNative == null){
return;
}
if(!atNative.checkAdStatus().isReady()){
return;
}
if (mATNativeAdView == null) {
mATNativeAdView = findViewById(R.id.native_ad_view); // Can be defined in xml layout.
}
if (mSelfRenderView == null) {
mSelfRenderView = mATNativeAdView.findViewById(R.id.native_selfrender_view); // Can be defined in xml layout.
}
NativeAd nativeAd = atNative.getNativeAd();
// After calling getNativeAd, developers can directly use ATNative#makeAdRequest to initiate preloading of the next ad.
// loadNativeAd();
if (nativeAd != null) {
if (mNativeAd != null) {
mNativeAd.destory();
}
mNativeAd = nativeAd;
mNativeAd.setNativeEventListener(new ATNativeEventListener() {
@Override
public void onAdImpressed(ATNativeAdView view, ATAdInfo atAdInfo) {
// ATAdInfo can distinguish ad platforms and obtain the ad placement ID of the ad platform, etc.
// Please refer to https://newdocs.takuad.com/docs/JSLSJN
Log.i(TAG, "native ad onAdImpressed:\n" + atAdInfo.toString());
}
@Override
public void onAdClicked(ATNativeAdView view, ATAdInfo atAdInfo) {
Log.i(TAG, "native ad onAdClicked:\n" + atAdInfo.toString());
}
@Override
public void onAdVideoStart(ATNativeAdView view) {
Log.i(TAG, "native ad onAdVideoStart");
}
@Override
public void onAdVideoEnd(ATNativeAdView view) {
Log.i(TAG, "native ad onAdVideoEnd");
}
@Override
public void onAdVideoProgress(ATNativeAdView view, int progress) {
Log.i(TAG, "native ad onAdVideoProgress:" + progress);
}
});
ATNativePrepareInfo nativePrepareInfo;
if (!mNativeAd.isNativeExpress()) {
// Self-Rendering, Draw Ads
nativePrepareInfo = new ATNativePrepareInfo();
bindSelfRenderView(this, mNativeAd.getAdMaterial(), mSelfRenderView, nativePrepareInfo)
mNativeAd.renderAdContainer(mATNativeAdView, mSelfRenderView);
} else {
// Template Rendering
mNativeAd.renderAdContainer(mATNativeAdView, null);
}
mNativeAd.prepare(mATNativeAdView, nativePrepareInfo);
}
}
public static void bindSelfRenderView(Context context, ATNativeMaterial adMaterial, View selfRenderView, ATNativePrepareInfo nativePrepareInfo) {
int padding = dip2px(context, 5);
selfRenderView.setPadding(padding, padding, padding, padding);
TextView titleView = (TextView) selfRenderView.findViewById(R.id.native_ad_title);
TextView descView = (TextView) selfRenderView.findViewById(R.id.native_ad_desc);
TextView ctaView = (TextView) selfRenderView.findViewById(R.id.native_ad_install_btn);
TextView adFromView = (TextView) selfRenderView.findViewById(R.id.native_ad_from);
FrameLayout iconArea = (FrameLayout) selfRenderView.findViewById(R.id.native_ad_image);
FrameLayout contentArea = (FrameLayout) selfRenderView.findViewById(R.id.native_ad_content_image_area);
final ATNativeImageView logoView = (ATNativeImageView) selfRenderView.findViewById(R.id.native_ad_logo);
View closeView = selfRenderView.findViewById(R.id.native_ad_close);
// bind view
List clickViewList = new ArrayList<>();//click views
String title = adMaterial.getTitle();
// title
if (!TextUtils.isEmpty(title)) {
titleView.setText(title);
nativePrepareInfo.setTitleView(titleView);//bind title
clickViewList.add(titleView);
titleView.setVisibility(View.VISIBLE);
} else {
titleView.setVisibility(View.GONE);
}
String descriptionText = adMaterial.getDescriptionText();
if (!TextUtils.isEmpty(descriptionText)) {
// desc
descView.setText(descriptionText);
nativePrepareInfo.setDescView(descView);//bind desc
clickViewList.add(descView);
descView.setVisibility(View.VISIBLE);
} else {
descView.setVisibility(View.GONE);
}
// icon
View adIconView = adMaterial.getAdIconView();
String iconImageUrl = adMaterial.getIconImageUrl();
iconArea.removeAllViews();
final ATNativeImageView iconView = new ATNativeImageView(context);
if (adIconView != null) {
iconArea.addView(adIconView);
nativePrepareInfo.setIconView(adIconView);//bind icon
clickViewList.add(adIconView);
iconArea.setVisibility(View.VISIBLE);
} else if (!TextUtils.isEmpty(iconImageUrl)) {
iconArea.addView(iconView);
iconView.setImage(iconImageUrl);
nativePrepareInfo.setIconView(iconView);//bind icon
clickViewList.add(iconView);
iconArea.setVisibility(View.VISIBLE);
} else {
iconArea.setVisibility(View.INVISIBLE);
}
// cta button
String callToActionText = adMaterial.getCallToActionText();
if (!TextUtils.isEmpty(callToActionText)) {
ctaView.setText(callToActionText);
nativePrepareInfo.setCtaView(ctaView);//bind cta button
clickViewList.add(ctaView);
ctaView.setVisibility(View.VISIBLE);
} else {
ctaView.setVisibility(View.GONE);
}
// media view
View mediaView = adMaterial.getAdMediaView(contentArea);
int mainImageHeight = adMaterial.getMainImageHeight();
int mainImageWidth = adMaterial.getMainImageWidth();
int realMainImageWidth = context.getResources().getDisplayMetrics().widthPixels - dip2px(context, 10);
int realMainHeight = 0;
FrameLayout.LayoutParams mainImageParam = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT
, FrameLayout.LayoutParams.WRAP_CONTENT);
if (mainImageWidth > 0 && mainImageHeight > 0 && mainImageWidth > mainImageHeight) {
realMainHeight = realMainImageWidth * mainImageHeight / mainImageWidth;
mainImageParam.width = realMainImageWidth;
mainImageParam.height = realMainHeight;
} else {
mainImageParam.width = FrameLayout.LayoutParams.MATCH_PARENT;
mainImageParam.height = realMainImageWidth * 600 / 1024;
}
contentArea.removeAllViews();
if (mediaView != null) {
if (mediaView.getParent() != null) {
((ViewGroup) mediaView.getParent()).removeView(mediaView);
}
mainImageParam.gravity = Gravity.CENTER;
mediaView.setLayoutParams(mainImageParam);
contentArea.addView(mediaView, mainImageParam);
clickViewList.add(mediaView);
contentArea.setVisibility(View.VISIBLE);
} else if (!TextUtils.isEmpty(adMaterial.getMainImageUrl())) {
ATNativeImageView imageView = new ATNativeImageView(context);
imageView.setImage(adMaterial.getMainImageUrl());
imageView.setLayoutParams(mainImageParam);
contentArea.addView(imageView, mainImageParam);
nativePrepareInfo.setMainImageView(imageView);//bind main image
clickViewList.add(imageView);
contentArea.setVisibility(View.VISIBLE);
} else {
contentArea.removeAllViews();
contentArea.setVisibility(View.GONE);
}
//Ad Logo
String adChoiceIconUrl = adMaterial.getAdChoiceIconUrl();
Bitmap adLogoBitmap = adMaterial.getAdLogo();
if (!TextUtils.isEmpty(adChoiceIconUrl)) {
logoView.setImage(adChoiceIconUrl);
nativePrepareInfo.setAdLogoView(logoView);//bind ad choice
logoView.setVisibility(View.VISIBLE);
} else if (adLogoBitmap != null) {
logoView.setImageBitmap(adLogoBitmap);
logoView.setVisibility(View.VISIBLE);
} else {
logoView.setImageBitmap(null);
logoView.setVisibility(View.GONE);
}
String adFrom = adMaterial.getAdFrom();
// ad from
if (!TextUtils.isEmpty(adFrom)) {
adFromView.setText(adFrom);
adFromView.setVisibility(View.VISIBLE);
} else {
adFromView.setVisibility(View.GONE);
}
nativePrepareInfo.setAdFromView(adFromView);//bind ad from
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(dip2px(context, 40), dip2px(context, 10));//ad choice
layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
nativePrepareInfo.setChoiceViewLayoutParams(layoutParams);//bind layout params for ad choice
nativePrepareInfo.setCloseView(closeView);//bind close button
nativePrepareInfo.setClickViewList(clickViewList);//bind click view list
if (nativePrepareInfo instanceof ATNativePrepareExInfo) {
List creativeClickViewList = new ArrayList<>();//click views
creativeClickViewList.add(ctaView);
((ATNativePrepareExInfo) nativePrepareInfo).setCreativeClickViewList(creativeClickViewList);//bind custom view list
}
}
public static int dip2px(Context context, float dipValue) {
float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
public void destroyAd() {
if (mNativeAd != null) {
mNativeAd.destory();
}
}
Refer to the self-rendering creative info instructions: Self-Rendering Ad Creative API