Search in sources :

Example 1 with MoPubStaticNativeAdRenderer

use of com.mopub.nativeads.MoPubStaticNativeAdRenderer 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;
}
Also used : PangleAdViewBinder(com.mopub.nativeads.PangleAdViewBinder) FacebookAdRenderer(com.mopub.nativeads.FacebookAdRenderer) MintegralAdRenderer(com.mopub.nativeads.MintegralAdRenderer) ReferenceNativeAdRenderer(com.mopub.nativeads.ReferenceNativeAdRenderer) PangleAdRenderer(com.mopub.nativeads.PangleAdRenderer) View(android.view.View) ListView(android.widget.ListView) MoPubStaticNativeAdRenderer(com.mopub.nativeads.MoPubStaticNativeAdRenderer) MoPubServerPositioning(com.mopub.nativeads.MoPubNativeAdPositioning.MoPubServerPositioning) ListView(android.widget.ListView) MoPubAdAdapter(com.mopub.nativeads.MoPubAdAdapter) VerizonNativeAdRenderer(com.mopub.nativeads.VerizonNativeAdRenderer) GooglePlayServicesViewBinder(com.mopub.nativeads.GooglePlayServicesViewBinder) PangleAdViewBinder(com.mopub.nativeads.PangleAdViewBinder) ViewBinder(com.mopub.nativeads.ViewBinder) GooglePlayServicesAdRenderer(com.mopub.nativeads.GooglePlayServicesAdRenderer) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with MoPubStaticNativeAdRenderer

use of com.mopub.nativeads.MoPubStaticNativeAdRenderer 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;
}
Also used : PangleAdViewBinder(com.mopub.nativeads.PangleAdViewBinder) FacebookAdRenderer(com.mopub.nativeads.FacebookAdRenderer) MintegralAdRenderer(com.mopub.nativeads.MintegralAdRenderer) PangleAdRenderer(com.mopub.nativeads.PangleAdRenderer) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MoPubStaticNativeAdRenderer(com.mopub.nativeads.MoPubStaticNativeAdRenderer) MoPubRecyclerAdapter(com.mopub.nativeads.MoPubRecyclerAdapter) Button(android.widget.Button) GooglePlayServicesAdRenderer(com.mopub.nativeads.GooglePlayServicesAdRenderer) ReferenceNativeAdRenderer(com.mopub.nativeads.ReferenceNativeAdRenderer) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) VerizonNativeAdRenderer(com.mopub.nativeads.VerizonNativeAdRenderer) RecyclerView(androidx.recyclerview.widget.RecyclerView) GooglePlayServicesViewBinder(com.mopub.nativeads.GooglePlayServicesViewBinder) ViewBinder(com.mopub.nativeads.ViewBinder) PangleAdViewBinder(com.mopub.nativeads.PangleAdViewBinder)

Example 3 with MoPubStaticNativeAdRenderer

use of com.mopub.nativeads.MoPubStaticNativeAdRenderer in project mopub-android-mediation by mopub.

the class NativeGalleryFragment 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_gallery_fragment, container, false);
    final DetailFragmentViewHolder views = DetailFragmentViewHolder.fromView(view);
    views.mLoadButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            updateRequestParameters(views);
            if (mStreamAdPlacer != null) {
                mStreamAdPlacer.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, ""));
    mViewPager = (ViewPager) view.findViewById(R.id.gallery_pager);
    updateRequestParameters(views);
    // Set up a renderer for a static native ad.
    final 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 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 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 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());
    // This ad placer is used to automatically insert ads into the ViewPager.
    mStreamAdPlacer = new MoPubStreamAdPlacer(getActivity());
    // The first renderer that can handle a particular native ad gets used.
    // We are prioritizing network renderers.
    mStreamAdPlacer.registerAdRenderer(mintegralAdRenderer);
    mStreamAdPlacer.registerAdRenderer(verizonNativeAdRenderer);
    mStreamAdPlacer.registerAdRenderer(googlePlayServicesAdRenderer);
    mStreamAdPlacer.registerAdRenderer(facebookAdRenderer);
    mStreamAdPlacer.registerAdRenderer(pangleAdRenderer);
    mStreamAdPlacer.registerAdRenderer(referenceNativeAdRenderer);
    mStreamAdPlacer.registerAdRenderer(moPubStaticNativeAdRenderer);
    mStreamAdPlacer.setAdLoadedListener(this);
    mPagerAdapter = new CustomPagerAdapter(getChildFragmentManager(), mStreamAdPlacer);
    mViewPager.setAdapter(mPagerAdapter);
    return view;
}
Also used : PangleAdViewBinder(com.mopub.nativeads.PangleAdViewBinder) FacebookAdRenderer(com.mopub.nativeads.FacebookAdRenderer) MintegralAdRenderer(com.mopub.nativeads.MintegralAdRenderer) ReferenceNativeAdRenderer(com.mopub.nativeads.ReferenceNativeAdRenderer) PangleAdRenderer(com.mopub.nativeads.PangleAdRenderer) View(android.view.View) TextView(android.widget.TextView) MoPubStaticNativeAdRenderer(com.mopub.nativeads.MoPubStaticNativeAdRenderer) VerizonNativeAdRenderer(com.mopub.nativeads.VerizonNativeAdRenderer) GooglePlayServicesViewBinder(com.mopub.nativeads.GooglePlayServicesViewBinder) ViewBinder(com.mopub.nativeads.ViewBinder) PangleAdViewBinder(com.mopub.nativeads.PangleAdViewBinder) GooglePlayServicesAdRenderer(com.mopub.nativeads.GooglePlayServicesAdRenderer) MoPubStreamAdPlacer(com.mopub.nativeads.MoPubStreamAdPlacer)

Example 4 with MoPubStaticNativeAdRenderer

use of com.mopub.nativeads.MoPubStaticNativeAdRenderer 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);
}
Also used : LetterItem(com.mikepenz.fastadapter.app.items.LetterItem) MoPubRecyclerAdapter(com.mopub.nativeads.MoPubRecyclerAdapter) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ViewBinder(com.mopub.nativeads.ViewBinder) MoPubStaticNativeAdRenderer(com.mopub.nativeads.MoPubStaticNativeAdRenderer)

Example 5 with MoPubStaticNativeAdRenderer

use of com.mopub.nativeads.MoPubStaticNativeAdRenderer in project mopub-android-mediation by mopub.

the class NativeManualFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    final View view = inflater.inflate(R.layout.native_manual_fragment, container, false);
    final DetailFragmentViewHolder viewHolder = DetailFragmentViewHolder.fromView(view);
    mAdConfiguration = MoPubSampleAdUnit.fromBundle(getArguments());
    mAdContainer = view.findViewById(R.id.parent_view);
    viewHolder.mLoadButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            updateRequestParameters(viewHolder);
            if (mAdContainer != null) {
                mAdContainer.removeAllViews();
            }
            if (mMoPubNative != null) {
                mMoPubNative.makeRequest(mRequestParameters);
            } else {
                logToast(getActivity(), getName() + " failed to load. MoPubNative instance is null.");
            }
        }
    });
    String adUnitId = null;
    if (mAdConfiguration != null) {
        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);
    mMoPubNative = new MoPubNative(getContext(), adUnitId, new MoPubNative.MoPubNativeNetworkListener() {

        @Override
        public void onNativeLoad(NativeAd nativeAd) {
            NativeAd.MoPubNativeEventListener moPubNativeEventListener = new NativeAd.MoPubNativeEventListener() {

                @Override
                public void onImpression(View view) {
                    // The ad has registered an impression. You may call any app logic that
                    // depends on having the ad view shown.
                    logToast(getActivity(), getName() + " impressed.");
                }

                @Override
                public void onClick(View view) {
                    logToast(getActivity(), getName() + " clicked.");
                }
            };
            // In a manual integration, any interval that is at least 2 is acceptable
            final AdapterHelper adapterHelper = new AdapterHelper(getContext(), 0, 2);
            final View adView;
            adView = adapterHelper.getAdView(null, null, nativeAd, new ViewBinder.Builder(0).build());
            nativeAd.setMoPubNativeEventListener(moPubNativeEventListener);
            if (mAdContainer != null) {
                mAdContainer.addView(adView);
            } else {
                logToast(getActivity(), getName() + " failed to show. Ad container is null.");
            }
        }

        @Override
        public void onNativeFail(NativeErrorCode errorCode) {
            logToast(getActivity(), getName() + " failed to load: " + errorCode.toString());
        }
    });
    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 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 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 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.
    mMoPubNative.registerAdRenderer(mintegralAdRenderer);
    mMoPubNative.registerAdRenderer(facebookAdRenderer);
    mMoPubNative.registerAdRenderer(googlePlayServicesAdRenderer);
    mMoPubNative.registerAdRenderer(verizonNativeAdRenderer);
    mMoPubNative.registerAdRenderer(pangleAdRenderer);
    mMoPubNative.registerAdRenderer(referenceNativeAdRenderer);
    mMoPubNative.registerAdRenderer(moPubStaticNativeAdRenderer);
    mMoPubNative.makeRequest(mRequestParameters);
    return view;
}
Also used : PangleAdViewBinder(com.mopub.nativeads.PangleAdViewBinder) FacebookAdRenderer(com.mopub.nativeads.FacebookAdRenderer) MintegralAdRenderer(com.mopub.nativeads.MintegralAdRenderer) NativeErrorCode(com.mopub.nativeads.NativeErrorCode) PangleAdRenderer(com.mopub.nativeads.PangleAdRenderer) AdapterHelper(com.mopub.nativeads.AdapterHelper) MoPubStaticNativeAdRenderer(com.mopub.nativeads.MoPubStaticNativeAdRenderer) GooglePlayServicesAdRenderer(com.mopub.nativeads.GooglePlayServicesAdRenderer) MoPubNative(com.mopub.nativeads.MoPubNative) ReferenceNativeAdRenderer(com.mopub.nativeads.ReferenceNativeAdRenderer) View(android.view.View) NativeAd(com.mopub.nativeads.NativeAd) VerizonNativeAdRenderer(com.mopub.nativeads.VerizonNativeAdRenderer) GooglePlayServicesViewBinder(com.mopub.nativeads.GooglePlayServicesViewBinder) ViewBinder(com.mopub.nativeads.ViewBinder) PangleAdViewBinder(com.mopub.nativeads.PangleAdViewBinder)

Aggregations

MoPubStaticNativeAdRenderer (com.mopub.nativeads.MoPubStaticNativeAdRenderer)6 ViewBinder (com.mopub.nativeads.ViewBinder)5 View (android.view.View)4 FacebookAdRenderer (com.mopub.nativeads.FacebookAdRenderer)4 GooglePlayServicesAdRenderer (com.mopub.nativeads.GooglePlayServicesAdRenderer)4 GooglePlayServicesViewBinder (com.mopub.nativeads.GooglePlayServicesViewBinder)4 MintegralAdRenderer (com.mopub.nativeads.MintegralAdRenderer)4 PangleAdRenderer (com.mopub.nativeads.PangleAdRenderer)4 PangleAdViewBinder (com.mopub.nativeads.PangleAdViewBinder)4 ReferenceNativeAdRenderer (com.mopub.nativeads.ReferenceNativeAdRenderer)4 VerizonNativeAdRenderer (com.mopub.nativeads.VerizonNativeAdRenderer)4 TextView (android.widget.TextView)2 MoPubNative (com.mopub.nativeads.MoPubNative)2 MoPubRecyclerAdapter (com.mopub.nativeads.MoPubRecyclerAdapter)2 NativeAd (com.mopub.nativeads.NativeAd)2 NativeErrorCode (com.mopub.nativeads.NativeErrorCode)2 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1