public NativeAdView inflateView(ViewGroup root) throws IllegalArgumentException{ if(root == null) throw new IllegalArgumentException("root should be not null"); // Inflate a layout and add it to the parent ViewGroup. LayoutInflater inflater = (LayoutInflater) root.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); return (NativeAdView) inflater .inflate(getAdLayoutId(), root, false); }
private NativeAdView onCreateItemView(ViewGroup parent, int viewType) { if (viewType == getViewTypeAdInstall()) return getInstallAdsLayoutContext().inflateView(parent); else if (viewType == getViewTypeAdContent()) return getContentAdsLayoutContext().inflateView(parent); else return null; }
private static void destroy(@NonNull final View view, @IdRes final int viewId) { final View adView = view.findViewById(viewId); if (adView instanceof NativeAdView) ((NativeAdView)adView).destroy(); }
@Override public void clear(@NonNull final View view) { super.clear(view); if (view instanceof NativeAdView) ((NativeAdView)view).destroy(); }
@Override public void bind(NativeAdView nativeAdView, NativeAd nativeAd) throws ClassCastException{ if (nativeAdView == null || nativeAd == null) return; if(!(nativeAd instanceof NativeAppInstallAd) || !(nativeAdView instanceof NativeAppInstallAdView)) throw new ClassCastException(); NativeAppInstallAd ad = (NativeAppInstallAd) nativeAd; NativeAppInstallAdView adView = (NativeAppInstallAdView) nativeAdView; // Locate the view that will hold the headline, set its text, and call the // NativeAppInstallAdView's setHeadlineView method to register it. TextView tvHeader = (TextView) adView.findViewById(R.id.tvHeader); tvHeader.setText(ad.getHeadline()); adView.setHeadlineView(tvHeader); TextView tvDescription = (TextView) adView.findViewById(R.id.tvDescription); tvDescription.setText(ad.getBody()); adView.setBodyView(tvDescription); ImageView ivLogo = (ImageView) adView.findViewById(R.id.ivLogo); if(ad.getIcon()!=null) ivLogo.setImageDrawable(ad.getIcon().getDrawable()); adView.setIconView(ivLogo); Button btnAction = (Button) adView.findViewById(R.id.btnAction); btnAction.setText(ad.getCallToAction()); adView.setCallToActionView(btnAction); TextView tvStore = (TextView) adView.findViewById(R.id.tvStore); tvStore.setText(ad.getStore()); adView.setStoreView(tvStore); TextView tvPrice = (TextView) adView.findViewById(R.id.tvPrice); tvPrice.setText(ad.getPrice()); adView.setPriceView(tvPrice); ImageView ivImage = (ImageView) adView.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 NativeAppInstallAdView's setNativeAd method to register the // NativeAd. adView.setNativeAd(ad); }
@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); }
public abstract void bind(NativeAdView nativeAdView, NativeAd nativeAd);