本文整理汇总了Java中com.google.android.gms.ads.NativeExpressAdView.setAdListener方法的典型用法代码示例。如果您正苦于以下问题:Java NativeExpressAdView.setAdListener方法的具体用法?Java NativeExpressAdView.setAdListener怎么用?Java NativeExpressAdView.setAdListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.ads.NativeExpressAdView
的用法示例。
在下文中一共展示了NativeExpressAdView.setAdListener方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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));
}
}
}
示例3: 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));
}
}
}
示例4: 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);
}
});
}
示例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 {
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);
}
}
}
}
示例6: 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;
}
});
}
示例7: AdNativeExpress
import com.google.android.gms.ads.NativeExpressAdView; //导入方法依赖的package包/类
public AdNativeExpress(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
LayoutInflater.from(context).inflate(R.layout.ad_native_express_view, this);
mNativeAdLayout = (FrameLayout) findViewById(R.id.ad_layout);
mProgress = findViewById(R.id.progress);
mAdText = findViewById(R.id.ad_text);
mGHImage = (AppCompatImageView) findViewById(R.id.gh_image);
findViewById(R.id.remove_ad).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ViewUtils.dialogDonate(v.getContext()).show();
}
});
mNativeExpressAdView = new NativeExpressAdView(context);
mNativeExpressAdView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
mNativeExpressAdView.setAdUnitId(getContext().getString(Utils.DARK_THEME ?
R.string.native_express_id_dark : R.string.native_express_id_light));
mNativeExpressAdView.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
mNativeLoading = false;
mNativeLoaded = false;
mNativeFailedLoading = true;
loadGHAd();
}
@Override
public void onAdLoaded() {
super.onAdLoaded();
mNativeLoaded = true;
mNativeLoading = false;
mNativeFailedLoading = false;
mProgress.setVisibility(GONE);
mNativeAdLayout.addView(mNativeExpressAdView);
}
});
}