本文整理汇总了Java中com.google.android.gms.ads.NativeExpressAdView类的典型用法代码示例。如果您正苦于以下问题:Java NativeExpressAdView类的具体用法?Java NativeExpressAdView怎么用?Java NativeExpressAdView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NativeExpressAdView类属于com.google.android.gms.ads包,在下文中一共展示了NativeExpressAdView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeAds
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
public static void initializeAds(Context context, View bannerPlaceholder, NativeExpressAdView adView, AnalyticsHelper analyticsHelper, String screenName) {
initializeAds(context, adView);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
apply(bannerPlaceholder, GONE);
apply(adView, VISIBLE);
}
@Override
public void onAdFailedToLoad(int i) {
analyticsHelper.logScreenEvent(screenName, AD_FAILED_TO_LOAD);
}
@Override
public void onAdClicked() {
analyticsHelper.logScreenEvent(screenName, AD_CLICKED);
}
});
}
示例2: setUpAndLoadNativeExpressAds
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
private void setUpAndLoadNativeExpressAds() {
mCoordinatorLayout.post(new Runnable() {
@Override
public void run() {
mNativeExpressAdView = new NativeExpressAdView(getContext());
float scale = getActivity().getResources().getDisplayMetrics().density;
int adWidth = mCoordinatorLayout.getWidth();
AdSize adSize = new AdSize((int) (adWidth / scale), NATIVE_EXPRESS_AD_HEIGHT);
mNativeExpressAdView.setAdSize(adSize);
mNativeExpressAdView.setAdUnitId(getString(R.string.test_ad_unit_id));
mAdViewContainer.addView(mNativeExpressAdView);
// Load the first Native Express ad in the items list.
AdRequest request = new AdRequest.Builder()
.addTestDevice("872EB083722CD10CAB1DB046CEE82A2D")
.build();
mNativeExpressAdView.loadAd(request);
}
});
}
示例3: AdViewHolder
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
public AdViewHolder(View v ) {
super(v);
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
NativeExpressAdView adView = new NativeExpressAdView(v.getContext());
adView.setAdSize(new AdSize(AdSize.FULL_WIDTH, 80));
// Load ad type based on theme - dark or light
if (PreferenceManager.getDefaultSharedPreferences(v.getContext())
.getBoolean(PREF_DARK_THEME, false)) {
adView.setAdUnitId(DARK_AD_ID);
} else {
adView.setAdUnitId(LIGHT_AD_ID);
}
((LinearLayout) v).addView(adView, 1);
adView.loadAd(request);
}
示例4: request
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
@Override
protected void request(Context context, Map<String, String> networkData) {
if (context == null || networkData == null) {
invokeLoadFail(PNException.ADAPTER_ILLEGAL_ARGUMENTS);
} else {
String unitId = networkData.get(AdMob.KEY_UNIT_ID);
if (TextUtils.isEmpty(unitId)) {
invokeLoadFail(PNException.ADAPTER_MISSING_DATA);
} else {
mIsImpressionConfirmed = false;
mIsReady = false;
mAdView = null;
mNativeAd = new NativeExpressAdView(mContext);
mNativeAd.setAdSize(new AdSize(WIDTH,HEIGHT));
mNativeAd.setAdUnitId(unitId);
mNativeAd.setAdListener(mAdListener);
mNativeAd.loadAd(AdMob.getAdRequest(context));
}
}
}
示例5: request
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
@Override
protected void request(Context context, Map<String, String> networkData) {
if (context == null || networkData == null) {
invokeLoadFail(PNException.ADAPTER_ILLEGAL_ARGUMENTS);
} else {
String unitId = networkData.get(AdMob.KEY_UNIT_ID);
if (TextUtils.isEmpty(unitId)) {
invokeLoadFail(PNException.ADAPTER_MISSING_DATA);
} else {
mIsReady = false;
mAdView = null;
mIsImpressionConfirmed = false;
mNativeAd = new NativeExpressAdView(mContext);
mNativeAd.setAdSize(AdSize.MEDIUM_RECTANGLE);
mNativeAd.setAdUnitId(unitId);
mNativeAd.setAdListener(mAdListener);
mNativeAd.loadAd(AdMob.getAdRequest(context));
}
}
}
示例6: onCreateView
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_slash, container, false);
// initialize Admob
MobileAds.initialize(mActivity, APP_ID);
NativeExpressAdView adView = view.findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder()
// .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
// .addTestDevice("0ACA1878D607E6C4360F91E0A0379C2F")
// .addTestDevice("4DA2263EDB49C1F2C00F9D130B823096")
.build();
adView.loadAd(request);
if (!adView.isLoading()) {
adView.setVisibility(View.GONE);
}
return view;
}
示例7: fetchAd
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
/**
* Fetches a new native ad.
*/
protected synchronized void fetchAd(final NativeExpressAdView adView) {
if(mFetchFailCount > MAX_FETCH_ATTEMPT)
return;
Context context = mContext.get();
if (context != null) {
Log.i(TAG, "Fetching Ad now");
new Handler(context.getMainLooper()).post(new Runnable() {
@Override
public void run() {
adView.loadAd(getAdRequest()); //Fetching the ads item
}
});
} else {
mFetchFailCount++;
Log.i(TAG, "Context is null, not fetching Ad");
}
}
示例8: setupAd
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
/**
* Subscribing to the native ads events
* @param adView
*/
protected synchronized void setupAd(final NativeExpressAdView adView) {
if(mFetchFailCount > MAX_FETCH_ATTEMPT)
return;
if(!mPrefetchedAds.contains(adView))
mPrefetchedAds.add(adView);
adView.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int errorCode) {
super.onAdFailedToLoad(errorCode);
// Handle the failure by logging, altering the UI, etc.
onFailedToLoad(adView, errorCode);
}
@Override
public void onAdLoaded() {
super.onAdLoaded();
onFetched(adView);
}
});
}
示例9: prefetchAds
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
/**
* Creates N instances {@link NativeExpressAdView} from the next N taken instances {@link ExpressAdPreset}
* Will start async prefetch of ad blocks to use its further
* @return last created NativeExpressAdView
*/
private NativeExpressAdView prefetchAds(int cntToPrefetch){
NativeExpressAdView last = null;
for (int i = 0; i < cntToPrefetch; i++){
final NativeExpressAdView item = AdViewHelper.getExpressAdView(mContext, adFetcher.takeNextAdPreset());
adFetcher.setupAd(item);
//50 ms throttling to prevent a high-load of server
new Handler(mContext.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
adFetcher.fetchAd(item);
}
}, 50 * i);
last = item;
}
return last;
}
示例10: prefetchAds
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
/**
* Creates N instances {@link NativeExpressAdView} from the next N taken instances {@link ExpressAdPreset}
* Will start async prefetch of ad blocks to use its further
* @return last created NativeExpressAdView
*/
private NativeExpressAdView prefetchAds(int cntToPrefetch){
NativeExpressAdView last = null;
for (int i = 0; i < cntToPrefetch; i++) {
final NativeExpressAdView item = AdViewHelper.getExpressAdView(mContext, adFetcher.takeNextAdPreset());
adFetcher.setupAd(item);
//50 ms throttling to prevent a high-load of server
new Handler(mContext.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
adFetcher.fetchAd(item);
}
}, 50 * i);
last = item;
}
return last;
}
示例11: onBindViewHolder
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
if (viewHolder == null)
return;
if(viewHolder.getItemViewType() == getViewTypeAdExpress()) {
NativeHolder nativeExpressHolder = (NativeHolder) viewHolder;
ViewGroup wrapper = nativeExpressHolder.getAdViewWrapper();
int adPos = AdapterCalculator.getAdIndex(position);
NativeExpressAdView adView = adFetcher.getAdForIndex(adPos);
if (adView == null)
adView = prefetchAds(1);
AdViewWrappingStrategy.recycleAdViewWrapper(wrapper, adView);
//make sure the AdView for this position doesn't already have a parent of a different recycled NativeExpressHolder.
if (adView.getParent() != null)
((ViewGroup) adView.getParent()).removeView(adView);
AdViewWrappingStrategy.addAdViewToWrapper(wrapper, adView);
} else {
int origPos = AdapterCalculator.getOriginalContentPosition(position,
adFetcher.getFetchingAdsCount(), mAdapter.getItemCount());
mAdapter.onBindViewHolder(viewHolder, origPos);
}
}
示例12: onAdFailed
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
@Override
public void onAdFailed(int adIdx, int errorCode, Object adPayload) {
NativeExpressAdView adView = (NativeExpressAdView)adPayload;
if (adView != null) {
ViewParent parent = adView.getParent();
if(parent == null || parent instanceof RecyclerView)
adView.setVisibility(View.GONE);
else {
while (parent.getParent() != null && !(parent.getParent() instanceof RecyclerView))
parent = parent.getParent();
((View) parent).setVisibility(View.GONE);
}
}
int pos = getAdapterCalculator().translateAdToWrapperPosition(Math.max(adIdx,0));
notifyItemRangeChanged(pos, pos+15);
}
示例13: loadAdView
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
private void loadAdView() {
if (BuildConfig.IS_PREMIUM_USER || hasPremiumApp()) {
findViewById(R.id.card_ad_view).setVisibility(View.GONE);
findViewById(R.id.btn_remove_ads).setVisibility(View.GONE);
return;
}
mAdView = (NativeExpressAdView) findViewById(R.id.native_ad_view);
if (mAdView != null) {
mAdView.loadAd(new AdRequest.Builder().build());
}
}
示例14: loadNativeAd
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
protected void loadNativeAd() {
try {
mNativeExpressAdView = (NativeExpressAdView) findViewById(R.id.native_ad_view);
if (mNativeExpressAdView != null) {
if (BuildConfig.IS_PREMIUM_USER) {
mNativeExpressAdView.setVisibility(View.GONE);
} else {
mNativeExpressAdView.loadAd(new AdRequest.Builder().build());
}
}
} catch (Exception e) {
}
}
示例15: Initialize
import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
/**
* Initializes the ad view.
*EventName - Sets the subs that will handle the events.
*AdUnitId - Ad unit ID of a native ad.
*Width - Requested ad width.
*Height - Requested ad height.
*/
public void Initialize(final BA ba, String EventName, String AdUnitId, float Width, float Height) {
NativeExpressAdView ad = new NativeExpressAdView(ba.activity);
ad.setAdSize(new AdSize((int)Math.round(Width / Common.Density), (int)Math.round(Height / Common.Density)));
ad.setAdUnitId(AdUnitId);
setObject(ad);
super.Initialize(ba, EventName);
final String eventName = EventName.toLowerCase(BA.cul);
getObject().setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int e){
ba.raiseEvent(getObject(), eventName + "_failedtoreceivead", String.valueOf(e));
}
@Override
public void onAdLoaded() {
ba.raiseEvent(getObject(), eventName + "_receivead");
}
@Override
public void onAdClosed() {
ba.raiseEventFromDifferentThread(getObject(), null, 0, eventName + "_adscreendismissed", false, null);
}
@Override
public void onAdLeftApplication() {
//
}
@Override
public void onAdOpened() {
ba.raiseEventFromDifferentThread(getObject(), null, 0, eventName + "_presentscreen", false, null);
}
});
}