use of com.mopub.nativeads.MoPubAdAdapter in project mopub-android-mediation by mopub.
the class NativeListViewFragment method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
mAdConfiguration = MoPubSampleAdUnit.fromBundle(getArguments());
final View view = inflater.inflate(R.layout.native_list_view_fragment, container, false);
final ListView listView = (ListView) view.findViewById(R.id.native_list_view);
final DetailFragmentViewHolder views = DetailFragmentViewHolder.fromView(view);
views.mLoadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
updateRequestParameters(views);
mAdAdapter.loadAds(mAdConfiguration.getAdUnitId(), mRequestParameters);
}
});
final String adUnitId = mAdConfiguration.getAdUnitId();
views.mDescriptionView.setText(mAdConfiguration.getDescription());
views.mAdUnitIdView.setText(adUnitId);
views.mKeywordsField.setText(getArguments().getString(MoPubListFragment.KEYWORDS_KEY, ""));
views.mUserDataKeywordsField.setText(getArguments().getString(MoPubListFragment.USER_DATA_KEYWORDS_KEY, ""));
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1);
for (int i = 0; i < 100; ++i) {
adapter.add("Item " + i);
}
// Create an ad adapter that gets its positioning information from the MoPub Ad Server.
// This adapter will be used in place of the original adapter for the ListView.
mAdAdapter = new MoPubAdAdapter(getActivity(), adapter, new MoPubServerPositioning());
// Set up a renderer that knows how to put ad data in your custom native view.
final MoPubStaticNativeAdRenderer staticAdRender = new MoPubStaticNativeAdRenderer(new ViewBinder.Builder(R.layout.native_ad_list_item).titleId(R.id.native_title).textId(R.id.native_text).mainImageId(R.id.native_main_image).iconImageId(R.id.native_icon_image).callToActionId(R.id.native_cta).privacyInformationIconImageId(R.id.native_privacy_information_icon_image).sponsoredTextId(R.id.native_sponsored_text_view).build());
// Set up a renderer for Facebook ads.
final FacebookAdRenderer facebookAdRenderer = new FacebookAdRenderer(new FacebookAdRenderer.FacebookViewBinder.Builder(R.layout.native_ad_fan_list_item).titleId(R.id.native_title).textId(R.id.native_text).mediaViewId(R.id.native_media_view).adIconViewId(R.id.native_icon).callToActionId(R.id.native_cta).adChoicesRelativeLayoutId(R.id.native_privacy_information_icon_layout).build());
// Set up a renderer for AdMob ads.
final GooglePlayServicesAdRenderer googlePlayServicesAdRenderer = new GooglePlayServicesAdRenderer(new GooglePlayServicesViewBinder.Builder(R.layout.video_ad_list_item).titleId(R.id.native_title).textId(R.id.native_text).mediaLayoutId(R.id.native_media_layout).iconImageId(R.id.native_icon_image).callToActionId(R.id.native_cta).privacyInformationIconImageId(R.id.native_privacy_information_icon_image).build());
// Set up a renderer for Pangle ads.
final PangleAdRenderer pangleAdRenderer = new PangleAdRenderer(new PangleAdViewBinder.Builder(R.layout.native_ad_pangle_list_item).callToActionId(R.id.native_cta).decriptionTextId(R.id.native_text).iconImageId(R.id.native_icon_image).titleId(R.id.native_title).mediaViewIdId(R.id.native_main_image).build());
// Set up a renderer for Verizon ads.
final VerizonNativeAdRenderer verizonNativeAdRenderer = new VerizonNativeAdRenderer(new ViewBinder.Builder(R.layout.native_ad_list_item).titleId(R.id.native_title).textId(R.id.native_text).mainImageId(R.id.native_main_image).iconImageId(R.id.native_icon_image).callToActionId(R.id.native_cta).privacyInformationIconImageId(R.id.native_privacy_information_icon_image).build());
// Set up a renderer for the reference network
final ReferenceNativeAdRenderer referenceNativeAdRenderer = new ReferenceNativeAdRenderer(new ReferenceNativeAdRenderer.ReferenceViewBinder.Builder(R.layout.native_ad_list_item).titleId(R.id.native_title).textId(R.id.native_text).mainImageId(R.id.native_main_image).iconImageId(R.id.native_icon_image).callToActionId(R.id.native_cta).adChoicesRelativeLayoutId(R.id.native_privacy_information_icon_layout).build());
// Set up a renderer for Mintegral ads
final MintegralAdRenderer mintegralAdRenderer = new MintegralAdRenderer(new MintegralAdRenderer.ViewBinder.Builder(R.layout.native_ad_list_item).titleId(R.id.native_title).textId(R.id.native_text).mainImageId(R.id.native_main_image).iconImageId(R.id.native_icon_image).callToActionId(R.id.native_cta).build());
// Register the renderers with the MoPubAdAdapter and then set the adapter on the ListView.
// The first renderer that can handle a particular native ad gets used.
// We are prioritizing network renderers.
mAdAdapter.registerAdRenderer(mintegralAdRenderer);
mAdAdapter.registerAdRenderer(referenceNativeAdRenderer);
mAdAdapter.registerAdRenderer(verizonNativeAdRenderer);
mAdAdapter.registerAdRenderer(googlePlayServicesAdRenderer);
mAdAdapter.registerAdRenderer(facebookAdRenderer);
mAdAdapter.registerAdRenderer(staticAdRender);
mAdAdapter.registerAdRenderer(pangleAdRenderer);
listView.setAdapter(mAdAdapter);
updateRequestParameters(views);
mAdAdapter.loadAds(mAdConfiguration.getAdUnitId(), mRequestParameters);
return view;
}
Aggregations