com.google.android.gms.ads.formats.NativeAppInstallAdView Java Examples
The following examples show how to use
com.google.android.gms.ads.formats.NativeAppInstallAdView.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdmobRecyclerAdapterWrapper.java From admobadapter with Apache License 2.0 | 6 votes |
@Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { if (viewHolder==null) return; int itemViewType = viewHolder.getItemViewType(); if(itemViewType == getViewTypeAdInstall()) { NativeAppInstallAdView lvi1 = (NativeAppInstallAdView) viewHolder.itemView; NativeAppInstallAd ad1 = (NativeAppInstallAd) getItem(position); getInstallAdsLayoutContext().bind(lvi1, ad1); } else if(itemViewType == getViewTypeAdContent()) { NativeContentAdView lvi2 = (NativeContentAdView) viewHolder.itemView; NativeContentAd ad2 = (NativeContentAd) getItem(position); getContentAdsLayoutContext().bind(lvi2, ad2); } else{ int origPos = AdapterCalculator.getOriginalContentPosition(position, adFetcher.getFetchedAdsCount(), mAdapter.getItemCount()); mAdapter.onBindViewHolder(viewHolder, origPos); } }
Example #2
Source File: MyTargetNativeAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
@Override public void trackView(final View view) { view.post(new Runnable() { @Override public void run() { if (view instanceof NativeAppInstallAdView) { NativeAppInstallAdView appInstallAdView = (NativeAppInstallAdView) view; final ArrayList<View> assetViews = new ArrayList<>(); if (appInstallAdView.getHeadlineView() != null) { assetViews.add(appInstallAdView.getHeadlineView()); } if (appInstallAdView.getBodyView() != null) { assetViews.add(appInstallAdView.getBodyView()); } if (appInstallAdView.getCallToActionView() != null) { assetViews.add(appInstallAdView.getCallToActionView()); } if (appInstallAdView.getIconView() != null) { assetViews.add(appInstallAdView.getIconView()); } if (appInstallAdView.getImageView() != null) { assetViews.add(appInstallAdView.getImageView()); } if (appInstallAdView.getPriceView() != null) { assetViews.add(appInstallAdView.getPriceView()); } if (appInstallAdView.getStarRatingView() != null) { assetViews.add(appInstallAdView.getStarRatingView()); } if (appInstallAdView.getStoreView() != null) { assetViews.add(appInstallAdView.getStoreView()); } if (appInstallAdView.getMediaView() != null) { assetViews.add(mediaAdView); } nativeAd.registerView(view, assetViews); } else { Log.w(TAG, "Failed to register view for interaction."); } } }); }
Example #3
Source File: InstallAppAdLayoutContext.java From admobadapter with Apache License 2.0 | 4 votes |
@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); }
Example #4
Source File: DFPCustomControlsFragment.java From android-ads with Apache License 2.0 | 4 votes |
/** * Populates a {@link NativeAppInstallAdView} object with data from a given * {@link NativeAppInstallAd}. * * @param nativeAppInstallAd the object containing the ad's assets * @param adView the view to be populated */ private void populateAppInstallAdView(NativeAppInstallAd nativeAppInstallAd, NativeAppInstallAdView adView) { adView.setHeadlineView(adView.findViewById(R.id.appinstall_headline)); adView.setBodyView(adView.findViewById(R.id.appinstall_body)); adView.setCallToActionView(adView.findViewById(R.id.appinstall_call_to_action)); adView.setIconView(adView.findViewById(R.id.appinstall_app_icon)); adView.setPriceView(adView.findViewById(R.id.appinstall_price)); adView.setStarRatingView(adView.findViewById(R.id.appinstall_stars)); adView.setStoreView(adView.findViewById(R.id.appinstall_store)); // Some assets are guaranteed to be in every NativeAppInstallAd. ((TextView) adView.getHeadlineView()).setText(nativeAppInstallAd.getHeadline()); ((TextView) adView.getBodyView()).setText(nativeAppInstallAd.getBody()); ((Button) adView.getCallToActionView()).setText(nativeAppInstallAd.getCallToAction()); ((ImageView) adView.getIconView()).setImageDrawable(nativeAppInstallAd.getIcon() .getDrawable()); // Get the video controller for the ad. One will always be provided, even if the ad doesn't // have a video asset. VideoController videoController = nativeAppInstallAd.getVideoController(); MediaView mediaView = adView.findViewById(R.id.appinstall_media); ImageView mainImageView = adView.findViewById(R.id.appinstall_image); // Apps can check the VideoController's hasVideoContent property to determine if the // NativeAppInstallAd has a video asset. if (videoController.hasVideoContent()) { mainImageView.setVisibility(View.GONE); adView.setMediaView(mediaView); } else { mediaView.setVisibility(View.GONE); adView.setImageView(mainImageView); // At least one image is guaranteed. List<NativeAd.Image> images = nativeAppInstallAd.getImages(); mainImageView.setImageDrawable(images.get(0).getDrawable()); } // These assets aren't guaranteed to be in every NativeAppInstallAd, so it's important to // check before trying to display them. if (nativeAppInstallAd.getPrice() == null) { adView.getPriceView().setVisibility(View.INVISIBLE); } else { adView.getPriceView().setVisibility(View.VISIBLE); ((TextView) adView.getPriceView()).setText(nativeAppInstallAd.getPrice()); } if (nativeAppInstallAd.getStore() == null) { adView.getStoreView().setVisibility(View.INVISIBLE); } else { adView.getStoreView().setVisibility(View.VISIBLE); ((TextView) adView.getStoreView()).setText(nativeAppInstallAd.getStore()); } if (nativeAppInstallAd.getStarRating() == null) { adView.getStarRatingView().setVisibility(View.INVISIBLE); } else { ((RatingBar) adView.getStarRatingView()) .setRating(nativeAppInstallAd.getStarRating().floatValue()); adView.getStarRatingView().setVisibility(View.VISIBLE); } // Assign native ad object to the native view. adView.setNativeAd(nativeAppInstallAd); customControlsView.setVideoController(videoController); refresh.setEnabled(true); }
Example #5
Source File: DFPCustomControlsFragment.java From googleads-mobile-android-examples with Apache License 2.0 | 4 votes |
/** * Populates a {@link NativeAppInstallAdView} object with data from a given * {@link NativeAppInstallAd}. * * @param nativeAppInstallAd the object containing the ad's assets * @param adView the view to be populated */ private void populateAppInstallAdView(NativeAppInstallAd nativeAppInstallAd, NativeAppInstallAdView adView) { adView.setHeadlineView(adView.findViewById(R.id.appinstall_headline)); adView.setBodyView(adView.findViewById(R.id.appinstall_body)); adView.setCallToActionView(adView.findViewById(R.id.appinstall_call_to_action)); adView.setIconView(adView.findViewById(R.id.appinstall_app_icon)); adView.setPriceView(adView.findViewById(R.id.appinstall_price)); adView.setStarRatingView(adView.findViewById(R.id.appinstall_stars)); adView.setStoreView(adView.findViewById(R.id.appinstall_store)); // Some assets are guaranteed to be in every NativeAppInstallAd. ((TextView) adView.getHeadlineView()).setText(nativeAppInstallAd.getHeadline()); ((TextView) adView.getBodyView()).setText(nativeAppInstallAd.getBody()); ((Button) adView.getCallToActionView()).setText(nativeAppInstallAd.getCallToAction()); ((ImageView) adView.getIconView()).setImageDrawable(nativeAppInstallAd.getIcon() .getDrawable()); // Get the video controller for the ad. One will always be provided, even if the ad doesn't // have a video asset. VideoController videoController = nativeAppInstallAd.getVideoController(); MediaView mediaView = adView.findViewById(R.id.appinstall_media); ImageView mainImageView = adView.findViewById(R.id.appinstall_image); // Apps can check the VideoController's hasVideoContent property to determine if the // NativeAppInstallAd has a video asset. if (videoController.hasVideoContent()) { mainImageView.setVisibility(View.GONE); adView.setMediaView(mediaView); } else { mediaView.setVisibility(View.GONE); adView.setImageView(mainImageView); // At least one image is guaranteed. List<NativeAd.Image> images = nativeAppInstallAd.getImages(); mainImageView.setImageDrawable(images.get(0).getDrawable()); } // These assets aren't guaranteed to be in every NativeAppInstallAd, so it's important to // check before trying to display them. if (nativeAppInstallAd.getPrice() == null) { adView.getPriceView().setVisibility(View.INVISIBLE); } else { adView.getPriceView().setVisibility(View.VISIBLE); ((TextView) adView.getPriceView()).setText(nativeAppInstallAd.getPrice()); } if (nativeAppInstallAd.getStore() == null) { adView.getStoreView().setVisibility(View.INVISIBLE); } else { adView.getStoreView().setVisibility(View.VISIBLE); ((TextView) adView.getStoreView()).setText(nativeAppInstallAd.getStore()); } if (nativeAppInstallAd.getStarRating() == null) { adView.getStarRatingView().setVisibility(View.INVISIBLE); } else { ((RatingBar) adView.getStarRatingView()) .setRating(nativeAppInstallAd.getStarRating().floatValue()); adView.getStarRatingView().setVisibility(View.VISIBLE); } // Assign native ad object to the native view. adView.setNativeAd(nativeAppInstallAd); customControlsView.setVideoController(videoController); refresh.setEnabled(true); }