Native Inview Ads - Android 2.4

Native Inview Ads – Android 2.4

Our innovative Native InView Ad unit instantly transforms any content wall within an app into premium video inventory. Natively integrated into publishers’ content, Native InView champions the user experience with viewable and non-intrusive video advertising.

You can tap into Chocolate Exchange, Mopub, Facebook, AppLovin, Google AdMob, and Yahoo Flurry demand. You can also enable BYOD (Bring Your Own Demand) tags – in the format of VAST or VPAID – and have them compete with the aforementioned demand sources.



Mediation Partners

Mediation Partners



How to Enable Native InView Ad Unit

How to Enable Native InView Ad Unit

Note: You will see reference to InView In-Line and InView Push-Down throughout this guide documentation.
InView Push-Down can be placed on the top of a content wall and it will expand to show the video ad. Please note that currently, you can tap into Chocolate demand and BYOD (Bring Your Own Demand) demand with InView Push-Down unit.
InView In-Line can be placed anywhere in the content wall and it will always be in 300×250 size. You can tap into Chocolate, Mopub, Facebook, Applovin, Admob, Flurry and BYOD demand with InView In-Line.



Import Libraries.

Import Libraries.

import com.vdopia.ads.lw.LVDOAdRequest; import com.vdopia.ads.lw.LVDOAdSize; import com.vdopia.ads.lw.LVDOBannerAd; import com.vdopia.ads.lw.LVDOBannerAdListener; import com.vdopia.ads.lw.LVDOConstants;

To add InView In-Line Ad in your application, first, you have to create a Listview. Then you have to create ListView Adapter to render the data in Listview.



In Adapter class code, declare instance variables as shown below

In Adapter class code, declare instance variables as shown below

private int mAdPosition;
private boolean mAdLoaded;
private final String mApiKey;
private LVDOBannerAd mAdView;
private final LVDOAdSize mAdSize;



Create LVDOAdView instance

Create LVDOAdView instance

mAdView = new LVDOBannerAd(mActivity, mAdSize, mApiKey, this); Where, mActivity = context mAdSize = INVIEW_LEADERBOARD (for InView In-Line) or IAB_MRECT (for InView Push-Down) mApiKey = API key for your app - please contact us to get your API key this = LVDOBannerAdListener

Please contact Vdopia to obtain your API key. You can contact us at sdk-support@vdopia.com



Create LVDOAdRequest instance. Configure ad request parameters & targeting parameters for that instance.

Create LVDOAdRequest instance. Configure ad request parameters & targeting parameters for that instance.

LVDOAdRequest adRequest = new LVDOAdRequest(mActivity); LocationData locationData = new LocationData(this); adRequest.setLocation(locationData.getDeviceLocation()); // It is recommended that you update the below parameter - accurate info is required adRequest.setAppStoreUrl(""); adRequest.setRequester(""); adRequest.setAppDomain(""); adRequest.setAppName(""); adRequest.setCategory(""); adRequest.setPublisherDomain(""); // Passing on the following parameter values can result in better targeting and higher yield // For parameters you cannot populate, please comment them out adRequest.setDmaCode("807"); adRequest.setEthnicity("Asian"); adRequest.setPostalCode("94538"); adRequest.setCurrPostal("94539"); adRequest.setDmaCode("807"); adRequest.setAge("27"); adRequest.setMaritalStatus("single"); adRequest.setGender("m"); adRequest.setBirthday("yyyy-mm-dd");



Load the ad

mAdView.loadAd(adRequest);
Use onBannerAdLoaded() callback method to check Ad is loaded and once Ad is loaded, add the Ad in to your Listview. For InView Push down Ad implement animation for slide down and slide up in onBannerAdLoaded() and onBannerAdClosed() callback respectively.



Code Snippets Layout for List item

Code Snippets
Layout for List item

<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffffff" android:orientation="vertical"> <!-- Here the Actual list item is --> <LinearLayout android:id="@+id/list_item_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffffff" android:orientation="vertical" android:padding="7dp"> <TextView android:id="@+id/tvTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:singleLine="true" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#000000" android:textSize="18sp" /> <TextView android:id="@+id/tvDescription" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:ellipsize="end" android:maxLines="2" android:textColor="#666666" android:textSize="14sp" /> </LinearLayout> <!-- Here the Ad is --> <LinearLayout android:id="@+id/ad_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#000000" android:orientation="vertical" android:visibility="gone" /> </LinearLayout>

 

 



ListView Adapter to load the Ad in ListView

ListView Adapter to load the Ad in ListView

public class InviewVideoAdapter extends BaseAdapter { private static final String TAG = "InviewVideoAdapter"; private static final int TYPE_INVIEW = 1; private static final int TYPE_NEWSVIEW = 0; private int mAdPosition; private boolean mAdLoaded; private final String mApiKey; private LVDOBannerAd mAdView; private final LVDOAdSize mAdSize; private final List mNewsList; private final Activity mActivity; private final LayoutInflater mInflater; private Animation mSlideUp = null; private Animation mSlideDown = null; private Map mViews = new HashMap<>(); public InviewVideoAdapter(Activity activity, List channels, String mApiKey, LVDOAdSize mAdSize) { this.mActivity = activity; this.mApiKey = mApiKey; this.mAdSize = mAdSize; this.mNewsList = channels; this.mInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void setAdPosition(int adPosition) { mAdPosition = adPosition; if (mAdPosition == 0) { mSlideDown = AnimationUtils.loadAnimation(mActivity, R.anim.slide_down); mSlideUp = AnimationUtils.loadAnimation(mActivity, R.anim.slide_up); } } @Override public int getCount() { return mNewsList != null ? mNewsList.size() : 0; } @Override public Object getItem(int position) { return mNewsList.get(position); } @Override public long getItemId(int position) { return 0; } @Override public int getItemViewType(int position) { if (position == mAdPosition) { return TYPE_INVIEW; } return TYPE_NEWSVIEW; } @Override public int getViewTypeCount() { return TYPE_INVIEW + 1; } @Override public View getView(int position, View convertView, ViewGroup parent) { int type = getItemViewType(position); ViewHolder viewHolder; if (convertView == null) { viewHolder = new ViewHolder(); convertView = mInflater.inflate(R.layout.news_events_list_item, null); viewHolder.llFirst = (LinearLayout) convertView.findViewById(R.id.list_item_container); viewHolder.llSecond = (LinearLayout) convertView.findViewById(R.id.ad_layout); viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle); viewHolder.tvDescription = (TextView) convertView.findViewById(R.id.tvDescription); viewHolder.llFirst.setVisibility(View.VISIBLE); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } switch (type) { case TYPE_NEWSVIEW: viewHolder.llFirst.setVisibility(View.VISIBLE); viewHolder.llSecond.setVisibility(View.GONE); if (mNewsList != null && !mNewsList.get(position).getTitle().isEmpty()) { viewHolder.tvTitle.setText(mNewsList.get(position).getTitle()); viewHolder.tvDescription.setText(mNewsList.get(position).getDescription()); } break; case TYPE_INVIEW: viewHolder.llFirst.setVisibility(View.GONE); viewHolder.llSecond.setVisibility(View.VISIBLE); if (!mAdLoaded) { loadInviewAd(viewHolder.llSecond, position); } else { View view = mViews.get(position); if (view != null) { ViewGroup parentViewGroup = (ViewGroup) view.getParent(); if (parentViewGroup != null) { parentViewGroup.removeAllViews(); } viewHolder.llSecond.addView(view); } } break; default: Log.e(TAG, "Default View Type"); } return convertView; } private void loadInviewAd(final LinearLayout inViewAd, final int i) { LVDOAdRequest adRequest = new LVDOAdRequest(); LocationData locationData = new LocationData(this); adRequest.setLocation(locationData.getDeviceLocation()); // It is recommended that you update the below parameter - accurate info is required adRequest.setAppStoreUrl(""); adRequest.setRequester(""); adRequest.setAppDomain(""); adRequest.setAppName(""); adRequest.setCategory(""); adRequest.setPublisherDomain(""); // Passing on the following parameter values can result in better targeting and higher yield // For parameters you cannot populate, please comment them out adRequest.setDmaCode("807"); adRequest.setEthnicity("Asian"); adRequest.setPostalCode("94538"); adRequest.setCurrPostal("94539"); adRequest.setDmaCode("807"); adRequest.setAge("27"); adRequest.setMaritalStatus("single"); adRequest.setGender("m"); adRequest.setBirthday("yyyy-mm-dd"); mAdView = new LVDOBannerAd(mActivity, mAdSize, mApiKey, new LVDOBannerAdListener() { @Override public void onBannerAdLoaded(View banner) { Log.d(TAG, "Inview Inline Ad Loaded"); if (banner != null) { ViewGroup parentViewGroup = (ViewGroup) banner.getParent(); if (parentViewGroup != null) { parentViewGroup.removeAllViews(); } mViews.put(i, banner); mAdLoaded = true; inViewAd.addView(banner); if (mSlideDown != null) { inViewAd.startAnimation(mSlideDown); } } } @Override public void onBannerAdFailed(View banner, LVDOConstants.LVDOErrorCode errorCode) { Log.d(TAG, "Inview Inline Ad Failed " + errorCode.toString()); // mAdLoaded = false; } @Override public void onBannerAdClicked(View banner) { Log.d(TAG, "Inview Inline Ad Clicked"); } @Override public void onBannerAdCosed(View banner) { Log.d(TAG, "Inview Inline Ad Closed"); if (mAdSize == LVDOAdSize.INVIEW_LEADERBOARD) { return; } if (mSlideUp != null) { inViewAd.startAnimation(mSlideUp); mSlideUp.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { //do something on animation started } @Override public void onAnimationEnd(Animation animation) { mViews.remove(mAdPosition); inViewAd.removeAllViews(); } @Override public void onAnimationRepeat(Animation animation) { //do something on animation repeat } }); } else { removeViews(); } } private void removeViews() { mViews.remove(mAdPosition); inViewAd.setVisibility(View.GONE); inViewAd.removeAllViews(); } }); mAdView.loadAd(adRequest); } public void destroyView() { if (mAdView != null) { mAdView.destroyView(); } } static class ViewHolder { TextView tvTitle; TextView tvDescription; LinearLayout llFirst; LinearLayout llSecond; } }



Event Listeners

Event Listeners
You may track ad lifecycle events like request failures or click-through. This interface may be implemented by your activity or any other object.

public interface LVDOBannerAdListener { // Ad has been successfully loaded public void onBannerAdLoaded(View banner); // Failed to retrieve an ad // You can use the LVDOErrorCode value to diagnose the cause of failure public void onBannerAdFailed(View banner, LVDOConstants.LVDOErrorCode errorCode); // The user has clicked on the Ad public void onBannerAdClicked(View banner); // Ad is closed public void onBannerAdClosed(View banner); }

Let’s get started! Here are steps for integration

1. Add SDK to Android App as Compiled .aar (Gradle project)

To add the Vdopia SDK as an .aar in your project, the SDK from download section, and then copy the .aar to your application library directory.