本文整理汇总了Java中com.google.android.gms.ads.AdView.setAdListener方法的典型用法代码示例。如果您正苦于以下问题:Java AdView.setAdListener方法的具体用法?Java AdView.setAdListener怎么用?Java AdView.setAdListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.ads.AdView
的用法示例。
在下文中一共展示了AdView.setAdListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeAds
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
public static void initializeAds(Context context, View bannerPlaceholder, AdView 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: setupGoogleAds
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
private void setupGoogleAds() {
mAdView = (AdView) findViewById(R.id.adView);
if (mAdView != null) {
mAdView.setVisibility(View.GONE);
if (!isPro()) {
AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
mAdView.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int errorCode) {
super.onAdFailedToLoad(errorCode);
mAdView.setVisibility(View.GONE);
}
@Override
public void onAdLoaded() {
super.onAdLoaded();
mAdView.setVisibility(View.VISIBLE);
}
});
mAdView.loadAd(adRequest);
if (!checkDataConnection()) {
mAdView.setVisibility(View.GONE);
}
}
}
}
示例3: addAdView
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
public void addAdView(final AdView adView) {
mAdViews.add(adView);
adView.setAdListener(new AppearAdListener(adView));
if (mAdsEnabled) {
if (!mInit) {
adView.loadAd(new AdRequest.Builder().build());
} else {
mInit = false;
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
}, 1000);
}
}
}
示例4: onCreate
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
load();
a = (RelativeLayout) findViewById(R.id.lay);
mAdView = (AdView) findViewById(R.id.adView);
mAdView.setVisibility(View.GONE);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
mAdView.setVisibility(View.VISIBLE);
}
});
}
示例5: AdDialogHelper
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
/**
* Constructor
*
* @param activity
* @param fragmentTag
*/
public AdDialogHelper(FragmentActivity activity, String fragmentTag) {
mActivity = activity;
mFragmentTag = fragmentTag;
mAdDialogFragment = new AdDialogFragment();
mAdDialogFragment.setCancelable(false);
// Create the adView
mAdView = new AdView(activity);
mAdView.setAdUnitId(activity.getString(R.string.admob_in_game_ad_unit));
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdListener(this);
if (AdsHelper.shoulShowAds(activity)) {
AdsHelper.requestAd(mAdView);
}
}
示例6: onActivityCreated
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle bundle) {
super.onActivityCreated(bundle);
// Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in
// values/strings.xml.
mAdView = (AdView) getView().findViewById(R.id.adView);
// The current version of AdMob breaks rotation animations on some devices.
// Setting the layer type of the ad to Software or Hardware fixes it.
// https://code.google.com/p/android/issues/detail?id=70914
mAdView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
// Create an ad request.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(getString(R.string.test_device_id))
.build();
// Start loading the ad in the background.
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int errorCode) {
mAdView.setVisibility(View.GONE);
super.onAdFailedToLoad(errorCode);
}
});
}
示例7: requestAd
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
/**
* Interface called by the AN SDK to request an ad from the mediating SDK.
*
* @param mBC the object which will be called with events from the 3rd party SDK
* @param activity the activity from which this is launched
* @param parameter String parameter received from the server for instantiation of this object
* @param adUnitID The 3rd party placement , in adMob this is the adUnitID
* @param width Width of ad
* @param height Height of ad
* @param targetingParameters targetingParameters
*/
@Override
public View requestAd(MediatedBannerAdViewController mBC, Activity activity, String parameter,
String adUnitID, int width, int height, TargetingParameters targetingParameters) {
adListener = new GooglePlayAdListener(mBC, super.getClass().getSimpleName());
adListener.printToClog(String.format(" - requesting an ad: [%s, %s, %dx%d]",
parameter, adUnitID, width, height));
adView = new AdView(activity);
adView.setAdUnitId(adUnitID);
adView.setAdSize(new AdSize(width, height));
adView.setAdListener(adListener);
try {
adView.loadAd(buildRequest(targetingParameters));
} catch (NoClassDefFoundError e) {
// This can be thrown by Play Services on Honeycomb.
adListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NO_FILL);
}
return adView;
}
示例8: onCreate
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean isDark = preferences.getBoolean("DARK_THEME_KEY", false);
if (isDark)
setTheme(R.style.AppThemeDark);
else
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.view_created_matrix);
adCard = (CardView) findViewById(R.id.AdCard);
if (!((GlobalValues) getApplication()).DonationKeyFound()) {
AdView mAdView = (AdView) findViewById(R.id.adViewCreatedView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.setAdListener(new AdLoadListener(adCard));
mAdView.loadAd(adRequest);
} else {
((ViewGroup) adCard.getParent()).removeView(adCard);
}
int index = getIntent().getIntExtra("INDEX", -1);
if (getSupportActionBar() != null && index != (-1))
getSupportActionBar().setTitle(((GlobalValues) getApplication()).GetCompleteList().get(index).GetName());
ViewMatrixFragment viewMatrixFragment = new ViewMatrixFragment();
Bundle bundle = new Bundle();
bundle.putInt("INDEX", getIntent().getIntExtra("INDEX", -1));
viewMatrixFragment.setArguments(bundle);
if (savedInstanceState == null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.FragmentContainer, viewMatrixFragment, "VIEW_TAG").commit();
}
}
示例9: onCreate
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
isDark = preferences.getBoolean("DARK_THEME_KEY", false);
if (isDark)
setTheme(R.style.AppThemeDark);
else
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.help_layout);
adCard = (CardView) findViewById(R.id.AddCardFAQ);
if (!((GlobalValues) getApplication()).DonationKeyFound()) {
AdView faqAd = (AdView) findViewById(R.id.adViewFaq);
AdRequest adRequest = new AdRequest.Builder().build();
faqAd.setAdListener(new AdLoadListener(adCard));
faqAd.loadAd(adRequest);
} else {
((ViewGroup) adCard.getParent()).removeView(adCard);
//remove cardView from main layout
}
if (isDark) {
SetThisColorToCard(ContextCompat.getColor(this, R.color.DarkcolorPrimary));
SetThisColorToAllQuestions(ContextCompat.getColor(this, R.color.DarkcolorAccent));
} else {
SetThisColorToAllQuestions(ContextCompat.getColor(this, R.color.colorAccent));
}
}
示例10: initSlideInOnLoadAnimation
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
private void initSlideInOnLoadAnimation(@NonNull final AdView adView) {
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
adView.startAnimation(
AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_in_from_bottom));
}
});
}
示例11: initAds
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
private void initAds() {
// https://developers.google.com/android/reference/com/google/android/gms/ads/package-summary
MobileAds.initialize(getApplicationContext(), getString(R.string.admob_banner_id));
final LinearLayout llAd = (LinearLayout) findViewById(R.id.llAd);
TextView tvAd = (TextView) findViewById(R.id.tvAd);
final AdView adView = (AdView) findViewById(R.id.adView);
tvAd.setText(getString(R.string.ads_off_text));
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
Log.i(TAG, "Ad loaded");
llAd.setVisibility(View.GONE);
}
@Override
public void onAdFailedToLoad(int errorCode) {
llAd.setVisibility(View.VISIBLE);
}
@Override
public void onAdOpened() {
Log.i(TAG, "Ad opened");
}
@Override
public void onAdClosed() {
Log.i(TAG, "Ad closed");
}
@Override
public void onAdLeftApplication() {
Log.i(TAG, "Ad left app");
}
});
}
示例12: showBannerAd
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
/**
* Loads AdMob banner into MainActivity
*/
public static void showBannerAd(final ViewGroup viewGroup, final AdView banner, final View view) {
banner.loadAd(new AdRequest.Builder().build());
banner.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
setupContentViewPadding(viewGroup, banner.getHeight());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
setBottomMargin(view, -(banner.getHeight() / 4));
}
}
});
}
示例13: createViewInstance
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
@Override
public AdView createViewInstance(ThemedReactContext context) {
//Log.d("ReactAdMobManager", "inside create view instance");
mAdView = new AdView(context);
mAdView.setAdSize(AdSize.LARGE_BANNER);
mAdView.setAdUnitId("ca-app-pub-3587283398271880/9131849251");
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
System.out.println("ad banner finished loading!");
ReactAdMobManager.d = true;
}
});
// Create an ad request.
if(!ReactAdMobManager.d){
AdRequest adRequest = new AdRequest.Builder().addTestDevice("D57F5B8E254117FD").build();
//adRequest.
mAdView.loadAd(adRequest);
}else{
mAdView.resume();
}
return mAdView;
}
示例14: onCreate
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout layout = new RelativeLayout(this);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
View gameView = initializeForView(new AdMobDemo(this), config);
layout.addView(gameView);
adView = new AdView(this);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
int visiblity = adView.getVisibility();
adView.setVisibility(AdView.GONE);
adView.setVisibility(visiblity);
Log.i(TAG, "Ad Loaded...");
}
});
adView.setAdSize(AdSize.SMART_BANNER);
//http://www.google.com/admob
adView.setAdUnitId("INSERT AD ID HERE");
AdRequest.Builder builder = new AdRequest.Builder();
//run once before uncommenting the following line. Get TEST device ID from the logcat logs.
//builder.addTestDevice("INSERT TEST DEVICE ID HERE");
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
layout.addView(adView, adParams);
adView.loadAd(builder.build());
setContentView(layout);
}
示例15: loadBannerAd
import com.google.android.gms.ads.AdView; //导入方法依赖的package包/类
/**
* Loads the banner ads in the items list.
*/
private void loadBannerAd(final int index) {
if (index >= mRecyclerViewItems.size()) {
return;
}
Object item = mRecyclerViewItems.get(index);
if (!(item instanceof AdView)) {
throw new ClassCastException("Expected item at index " + index + " to be a banner ad"
+ " ad.");
}
final AdView adView = (AdView) item;
// Set an AdListener on the AdView to wait for the previous banner ad
// to finish loading before loading the next ad in the items list.
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
// The previous banner ad loaded successfully, call this method again to
// load the next ad in the items list.
loadBannerAd(index + ITEMS_PER_AD);
}
@Override
public void onAdFailedToLoad(int errorCode) {
// The previous banner ad failed to load. Call this method again to load
// the next ad in the items list.
Log.e("MainActivity", "The previous banner ad failed to load. Attempting to"
+ " load the next banner ad in the items list.");
loadBannerAd(index + ITEMS_PER_AD);
}
});
// Load the banner ad.
adView.loadAd(new AdRequest.Builder().build());
}