• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NativeExpressAdView类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.android.gms.ads.NativeExpressAdView的典型用法代码示例。如果您正苦于以下问题:Java NativeExpressAdView类的具体用法?Java NativeExpressAdView怎么用?Java NativeExpressAdView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NativeExpressAdView类属于com.google.android.gms.ads包,在下文中一共展示了NativeExpressAdView类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
        }
    });
}
 
开发者ID:albertogiunta,项目名称:justintrain-client-android,代码行数:22,代码来源:Ads.java


示例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);
        }
    });
}
 
开发者ID:mvescovo,项目名称:item-reaper,代码行数:21,代码来源:ItemDetailsFragment.java


示例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);
}
 
开发者ID:elixsr,项目名称:FwdPortForwardingApp,代码行数:20,代码来源:RuleListAdapter.java


示例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));
        }
    }
}
 
开发者ID:pubnative,项目名称:pubnative-android-sdk,代码行数:23,代码来源:AdMobNativeExpressAdapter.java


示例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));
        }
    }
}
 
开发者ID:pubnative,项目名称:pubnative-android-sdk,代码行数:22,代码来源:AdMobNativeExpressAdapter.java


示例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;
    }
 
开发者ID:Art2Cat,项目名称:MoonlightNote,代码行数:20,代码来源:SlashFragment.java


示例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");
    }
}
 
开发者ID:clockbyte,项目名称:admobadapter,代码行数:23,代码来源:AdmobFetcherExpress.java


示例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);
        }
    });
}
 
开发者ID:clockbyte,项目名称:admobadapter,代码行数:25,代码来源:AdmobFetcherExpress.java


示例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;
}
 
开发者ID:clockbyte,项目名称:admobadapter,代码行数:22,代码来源:AdmobExpressAdapterWrapper.java


示例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;
}
 
开发者ID:clockbyte,项目名称:admobadapter,代码行数:22,代码来源:AdmobExpressRecyclerAdapterWrapper.java


示例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);
    }
}
 
开发者ID:clockbyte,项目名称:admobadapter,代码行数:24,代码来源:AdmobExpressRecyclerAdapterWrapper.java


示例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);
}
 
开发者ID:clockbyte,项目名称:admobadapter,代码行数:17,代码来源:AdmobExpressRecyclerAdapterWrapper.java


示例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());
    }
}
 
开发者ID:tranleduy2000,项目名称:ascii_generate,代码行数:12,代码来源:MainActivity.java


示例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) {

    }
}
 
开发者ID:tranleduy2000,项目名称:ascii_generate,代码行数:15,代码来源:AdBannerActivity.java


示例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);

		}
	});
}
 
开发者ID:AnywhereSoftware,项目名称:B4A_FirebaseAdMob,代码行数:40,代码来源:AdViewWrapper.java


示例16: 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;
            mAdView = null;
            mNativeAd = new NativeExpressAdView(mContext);

            DisplayMetrics displayMetrics = new DisplayMetrics();

            if(context instanceof Activity) {
                ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
                int heightDP = PNDeviceUtils.convertPxToDp(displayMetrics.heightPixels, context);
                heightDP = Math.min(Math.max(heightDP, MIN_HEIGHT), MAX_HEIGHT);
                int widthDP = PNDeviceUtils.convertPxToDp(displayMetrics.widthPixels, context);
                widthDP = Math.min(Math.max(widthDP, MIN_WIDTH), MAX_WIDTH);
                mNativeAd.setAdSize(new AdSize(widthDP, heightDP));
                mNativeAd.setAdUnitId(unitId);
                mNativeAd.setAdListener(mAdListener);
                mNativeAd.loadAd(AdMob.getAdRequest(context));
            } else {
                invokeLoadFail(PNException.ADAPTER_ILLEGAL_ARGUMENTS);
            }
        }
    }
}
 
开发者ID:pubnative,项目名称:pubnative-android-sdk,代码行数:32,代码来源:AdMobNativeExpressAdapter.java


示例17: initBannerAds

import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
private void initBannerAds() {
    // Look up the AdView as a resource and load a request.
    NativeExpressAdView adView = (NativeExpressAdView)this.findViewById(R.id.main_adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("BABB35E2F44BD42D7B74D736D34239F2")
            .build();
    adView.loadAd(adRequest);

    //Mechanism to prevent interstitial displaying when banner is active
    adView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            // Code to be executed when an ad finishes loading.
            isAdActive = false;
        }
        @Override
        public void onAdOpened() {
            // Code to be executed when an ad opens an overlay that
            // covers the screen.
            isAdActive = true;
        }

        @Override
        public void onAdLeftApplication() {
            // Code to be executed when the user has left the app.
            isAdActive = true;
        }

    });
}
 
开发者ID:ruibar,项目名称:android-protwall,代码行数:32,代码来源:ActivityFirst.java


示例18: getExpressAdView

import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
public static NativeExpressAdView getExpressAdView(Context context, ExpressAdPreset expressAdPreset) {
    NativeExpressAdView adView = new NativeExpressAdView(context);
    AdSize adSize = expressAdPreset.getAdSize();
    adView.setAdSize(adSize);
    adView.setAdUnitId(expressAdPreset.getAdUnitId());
    adView.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
            adSize.getHeightInPixels(context)));

    //set video options
    if(expressAdPreset.getVideoOptions() != null)
    adView.setVideoOptions(expressAdPreset.getVideoOptions());

    return adView;
}
 
开发者ID:clockbyte,项目名称:admobadapter,代码行数:15,代码来源:AdViewHelper.java


示例19: onFetched

import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
/**
 * A handler for received native ads
 * @param adView
 */
private synchronized void onFetched(NativeExpressAdView adView) {
    Log.i(TAG, "onAdFetched");
    mFetchFailCount = 0;
    mNoOfFetchedAds++;
    onAdLoaded(mNoOfFetchedAds - 1);
}
 
开发者ID:clockbyte,项目名称:admobadapter,代码行数:11,代码来源:AdmobFetcherExpress.java


示例20: onFailedToLoad

import com.google.android.gms.ads.NativeExpressAdView; //导入依赖的package包/类
/**
 * A handler for failed native ads
 * @param adView
 */
private synchronized void onFailedToLoad(NativeExpressAdView adView, int errorCode) {
    Log.i(TAG, "onAdFailedToLoad " + errorCode);
    mFetchFailCount++;
    mNoOfFetchedAds = Math.max(mNoOfFetchedAds - 1, 0);
    //Since Fetch Ad is only called once without retries
    //hide ad row / rollback its count if still not added to list
    mPrefetchedAds.remove(adView);
    onAdFailed(mNoOfFetchedAds - 1, errorCode, adView);
}
 
开发者ID:clockbyte,项目名称:admobadapter,代码行数:14,代码来源:AdmobFetcherExpress.java



注:本文中的com.google.android.gms.ads.NativeExpressAdView类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PathConsumer2D类代码示例发布时间:2022-05-21
下一篇:
Java AnnotationAction类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap