Download File
Download Project
Settings
Line Wrap
Themes
default
ambiance
bespin
dracula
eclipse
material
mbo
mdn-like
neat
solarized dark
ttcn
zenburn
AppInstallAdPlacement.java
package com.google.example.gms.nativeads; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import com.google.android.gms.ads.formats.NativeAppInstallAdView; /** * The {@link AppInstallAdPlacement} class represents a single placement of an App Install ad. It * returns a {@link View} that contains a previously loaded ad or will be filled with a new ad once * it completes loading. */ public class AppInstallAdPlacement implements AdPlacement { private AppInstallAdFetcher mFetcher; /** * Creates a new instance of {@link AppInstallAdPlacement} with the given fetcher * * @param fetcher the fetcher that will retrieve and cache native ads for this placement */ public AppInstallAdPlacement(AppInstallAdFetcher fetcher) { mFetcher = fetcher; } /** * Creates or reuses a {@link FrameLayout} for this ad placement, filling it asynchronously * with the assets for its {@link com.google.android.gms.ads.formats.NativeAppInstallAd}. * * @param convertView a {@link View} to reuse if possible * @param parent The {@link ViewGroup} into which the {@link View} will be placed * @return a {@link FrameLayout} that contains or will contain the ad assets for this placement */ @Override public View getView(View convertView, ViewGroup parent) { // For each native ad, a FrameLayout is created and returned to the ListView as // the item's root view. This allows the fetcher to asynchronously request an ad, which // will be converted into a set of Views and placed into the FrameLayout by the // ViewHolder object. FrameLayout frameLayout = (FrameLayout) convertView; AppInstallAdViewHolder holder = (frameLayout == null) ? null : (AppInstallAdViewHolder) frameLayout.getTag(); // If the holder is null, either this is the first time the item has been displayed, or // convertView held a different type of item before. In either case, a new FrameLayout // and ViewHolder should be created and used. if (holder == null) { frameLayout = new FrameLayout(parent.getContext()); LayoutInflater inflater = (LayoutInflater) parent.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); NativeAppInstallAdView adView = (NativeAppInstallAdView) inflater .inflate(R.layout.item_app_install_ad, frameLayout, false); frameLayout.addView(adView); holder = new AppInstallAdViewHolder(adView); frameLayout.setTag(holder); } // This statement kicks off the ad loading process. The ViewHolder has some interface // methods that will be invoked when the ad is ready to be displayed or fails to load. mFetcher.loadAd(frameLayout.getContext(), holder); // The FrameLayout is returned to the ListView so it will have something to show for the // item right now. The FrameLayout will be filled with native ad assets later, once the // ad has finished loading. return frameLayout; } }