use of com.mopub.nativeads.MoPubRecyclerAdapter in project mopub-android-mediation by mopub.
the class NativeRecyclerViewFragment method onCreateView.
@Override
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
mAdConfiguration = MoPubSampleAdUnit.fromBundle(getArguments());
final View view = inflater.inflate(R.layout.recycler_view_fragment, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.native_recycler_view);
final DetailFragmentViewHolder viewHolder = DetailFragmentViewHolder.fromView(view);
final Button switchButton = (Button) view.findViewById(R.id.switch_button);
switchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
toggleRecyclerLayout();
}
});
viewHolder.mLoadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
updateRequestParameters(viewHolder);
if (mRecyclerAdapter != null) {
mRecyclerAdapter.refreshAds(mAdConfiguration.getAdUnitId(), mRequestParameters);
}
}
});
final String adUnitId = mAdConfiguration.getAdUnitId();
viewHolder.mDescriptionView.setText(mAdConfiguration.getDescription());
viewHolder.mAdUnitIdView.setText(adUnitId);
viewHolder.mKeywordsField.setText(getArguments().getString(MoPubListFragment.KEYWORDS_KEY, ""));
viewHolder.mUserDataKeywordsField.setText(getArguments().getString(MoPubListFragment.USER_DATA_KEYWORDS_KEY, ""));
updateRequestParameters(viewHolder);
final RecyclerView.Adapter originalAdapter = new DemoRecyclerAdapter();
mRecyclerAdapter = new MoPubRecyclerAdapter(getActivity(), originalAdapter, new MoPubNativeAdPositioning.MoPubServerPositioning());
MoPubStaticNativeAdRenderer moPubStaticNativeAdRenderer = 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 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 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 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());
// The first renderer that can handle a particular native ad gets used.
// We are prioritizing network renderers.
mRecyclerAdapter.registerAdRenderer(mintegralAdRenderer);
mRecyclerAdapter.registerAdRenderer(verizonNativeAdRenderer);
mRecyclerAdapter.registerAdRenderer(googlePlayServicesAdRenderer);
mRecyclerAdapter.registerAdRenderer(facebookAdRenderer);
mRecyclerAdapter.registerAdRenderer(pangleAdRenderer);
mRecyclerAdapter.registerAdRenderer(referenceNativeAdRenderer);
mRecyclerAdapter.registerAdRenderer(moPubStaticNativeAdRenderer);
mRecyclerView.setAdapter(mRecyclerAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mLayoutType = LayoutType.LINEAR;
mRecyclerAdapter.loadAds(mAdConfiguration.getAdUnitId(), mRequestParameters);
return view;
}
use of com.mopub.nativeads.MoPubRecyclerAdapter in project FastAdapter by mikepenz.
the class MopubAdsActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
// Handle Toolbar
setSupportActionBar(toolbar);
mAdapter = new MopubFastItemAdapter<>();
mAdapter.withOnClickListener(this);
for (int i = 65; i <= 90; i++) {
mAdapter.add(new LetterItem(String.valueOf((char) i)));
}
ViewBinder viewBinder = new ViewBinder.Builder(R.layout.native_ad_item).iconImageId(R.id.native_icon_image).titleId(R.id.native_title).textId(R.id.native_text).callToActionId(R.id.native_cta).privacyInformationIconImageId(R.id.native_privacy_information_icon_image).build();
MoPubRecyclerAdapter adapter = new MoPubRecyclerAdapter(this, mAdapter);
adapter.registerAdRenderer(new MoPubStaticNativeAdRenderer(viewBinder));
adapter.loadAds("76a3fefaced247959582d2d2df6f4757");
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 1));
mRecyclerView.setAdapter(adapter);
//provide the mopub adapter
mAdapter.withMoPubAdAdapter(adapter);
//restore selections (this has to be done after the items were added
mAdapter.withSavedInstanceState(savedInstanceState);
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
Aggregations