use of com.google.android.gms.ads.AdListener in project UltimateRecyclerView by cymcsg.
the class TestAdvancedAdmobActivity method createadmob.
private RelativeLayout createadmob() {
AdSize adSize = AdSize.SMART_BANNER;
DisplayMetrics dm = getResources().getDisplayMetrics();
double density = dm.density * 160;
double x = Math.pow(dm.widthPixels / density, 2);
double y = Math.pow(dm.heightPixels / density, 2);
double screenInches = Math.sqrt(x + y);
if (screenInches > 8) {
// > 728 X 90
adSize = AdSize.LEADERBOARD;
} else if (screenInches > 6) {
// > 468 X 60
adSize = AdSize.MEDIUM_RECTANGLE;
} else {
// > 320 X 50
adSize = AdSize.BANNER;
}
adSize = AdSize.MEDIUM_RECTANGLE;
final AdView mAdView = new AdView(this);
mAdView.setAdSize(adSize);
mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
// Create an ad request.
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
if (admob_test_mode)
// Optionally populate the ad request builder.
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
// Start loading the ad.
mAdView.loadAd(adRequestBuilder.build());
DisplayMetrics displaymetrics = new DisplayMetrics();
final RelativeLayout layout = AdGoogleDisplaySupport.initialSupport(this, displaymetrics);
final double ratio = AdGoogleDisplaySupport.ratioMatching(displaymetrics);
final int ad_height = AdGoogleDisplaySupport.defaultHeight(displaymetrics);
AdGoogleDisplaySupport.panelAdjust(mAdView, (int) (ad_height * ratio));
// get display info
/* G.display_w = displayMetrics.widthPixels;
G.display_h = displayMetrics.heightPixels;
G.scale = Math.max(G.display_w/1280.0f, G.display_h/800.0f);*/
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
int h = mAdView.getLayoutParams().height;
AdGoogleDisplaySupport.scale(mAdView, ratio);
AdGoogleDisplaySupport.panelAdjust(mAdView, (int) (h * ratio));
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
}
});
layout.addView(mAdView);
return layout;
}
use of com.google.android.gms.ads.AdListener in project quickstart-android by firebase.
the class MainActivity method onCreate.
// [END_EXCLUDE]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
// [END load_banner_ad]
// AdMob ad unit IDs are not currently stored inside the google-services.json file.
// Developers using AdMob can store them as custom values in a string resource file or
// simply use constants. Note that the ad units used here are configured to return only test
// ads, and should not be used outside this sample.
// [START instantiate_interstitial_ad]
// Create an InterstitialAd object. This same object can be re-used whenever you want to
// show an interstitial.
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
// [END instantiate_interstitial_ad]
// [START create_interstitial_ad_listener]
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
beginSecondActivity();
}
@Override
public void onAdLoaded() {
// [START_EXCLUDE]
if (mLoadInterstitialButton != null) {
mLoadInterstitialButton.setEnabled(true);
}
// [END_EXCLUDE]
}
@Override
public void onAdFailedToLoad(int i) {
// See https://goo.gl/sCZj0H for possible error codes.
Log.w(TAG, "onAdFailedToLoad:" + i);
}
});
// [END create_interstitial_ad_listener]
// [START display_interstitial_ad]
mLoadInterstitialButton = (Button) findViewById(R.id.load_interstitial_button);
mLoadInterstitialButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
beginSecondActivity();
}
}
});
// [END display_interstitial_ad]
// Disable button if an interstitial ad is not loaded yet.
mLoadInterstitialButton.setEnabled(mInterstitialAd.isLoaded());
}
use of com.google.android.gms.ads.AdListener in project Tapad by berict.
the class AboutFragment method setPresetInfo.
public void setPresetInfo() {
toolbar.setActionBar(a, v);
toolbar.setActionBarTitle(R.string.about);
toolbar.setActionBarPadding(a, v);
toolbar.setActionBarDisplayHomeAsUp(true);
if (currentPreset != null) {
// Cardview
w.getView(R.id.cardview_music_layout, a).setVisibility(View.VISIBLE);
Picasso.with(a).load("file:" + currentPreset.getAbout().getImage()).placeholder(R.drawable.ic_image_album_placeholder).error(R.drawable.ic_image_album_error).into(w.getImageView(R.id.cardview_music_image, v));
w.getTextView(R.id.cardview_music_song, v).setText(currentPreset.getAbout().getTitle());
w.getTextView(R.id.cardview_music_explore, v).setTextColor(currentPreset.getAbout().getActionbarColor());
w.getTextView(R.id.cardview_music_change, v).setTextColor(currentPreset.getAbout().getActionbarColor());
toolbar.setActionBarColor(currentPreset.getAbout().getActionbarColor(), a);
} else {
w.getView(R.id.cardview_music_layout, a).setVisibility(View.GONE);
toolbar.setActionBarColor(R.color.colorPrimary, a);
}
// artist
w.getView(R.id.cardview_music, v).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent.intentSharedElementWithExtra(a, "activity.AboutActivity", R.id.cardview_music_image, "transition", "about", "now_playing", 0, v);
}
});
w.getView(R.id.cardview_music_explore, v).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent.intentSharedElementWithExtra(a, "activity.AboutActivity", R.id.cardview_music_image, "transition", "about", "now_playing", 0, v);
}
});
w.getView(R.id.cardview_music_change, v).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isPresetVisible == false) {
intent.intent(a, "activity.PresetStoreActivity");
}
}
});
// preset store
w.getView(R.id.cardview_preset_store, v).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent.intentSharedElementWithExtra(a, "activity.PresetStoreActivity", R.id.cardview_preset_store_image, "transition", "about", "now_playing", 0, v);
}
});
w.getView(R.id.cardview_preset_store_explore, v).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent.intentSharedElementWithExtra(a, "activity.PresetStoreActivity", R.id.cardview_preset_store_image, "transition", "about", "now_playing", 0, v);
}
});
// tapad
w.getView(R.id.cardview_about, v).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent.intentSharedElementWithExtra(a, "activity.AboutActivity", R.id.cardview_about_image, "transition", "about", "tapad", 0, v);
}
});
w.getView(R.id.cardview_about_explore, v).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent.intentSharedElementWithExtra(a, "activity.AboutActivity", R.id.cardview_about_image, "transition", "about", "tapad", 0, v);
}
});
w.getView(R.id.cardview_about_settings, v).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
coord[2] = (int) event.getRawX();
coord[3] = (int) event.getRawY();
return false;
}
});
w.getView(R.id.cardview_about_settings, v).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isSettingVisible == false) {
anim.circularRevealInPx(R.id.placeholder, coord[2], coord[3], 0, (int) Math.hypot(coord[2], coord[3]) + 200, new AccelerateDecelerateInterpolator(), circularRevealDuration, 0, a);
Handler about = new Handler();
about.postDelayed(new Runnable() {
@Override
public void run() {
showSettingsFragment(a);
}
}, circularRevealDuration);
anim.fadeOut(R.id.placeholder, circularRevealDuration, fadeAnimDuration, a);
setSettingVisible(true);
}
}
});
// developer
w.getView(R.id.cardview_dev, v).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent.intentSharedElementWithExtra(a, "activity.AboutActivity", R.id.cardview_dev_image, "transition", "about", "dev", 0, v);
}
});
w.getView(R.id.cardview_dev_explore, v).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent.intentSharedElementWithExtra(a, "activity.AboutActivity", R.id.cardview_dev_image, "transition", "about", "dev", 0, v);
}
});
// Blank ads
if (ad.isConnected(a)) {
// connected to internet, check ad is working
ad.getNativeAdView(R.id.adView_about, a).setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Ad loaded
Log.d("AdView", "Loaded");
anim.fadeOut(R.id.cardview_ad_loading, 0, 400, v, a);
w.getView(R.id.cardview_ad_failed, v).setVisibility(View.GONE);
super.onAdLoaded();
}
@Override
public void onAdFailedToLoad(int i) {
// Ad failed to load
Log.d("AdView", "Failed to load");
anim.fadeOut(R.id.cardview_ad_loading, 0, 400, v, a);
anim.fadeIn(R.id.cardview_ad_failed, 400, 400, "adFailFadeIn", v, a);
super.onAdFailedToLoad(i);
}
});
} else {
// not connected to internet
Log.d("AdView", "Failed to connect to the internet");
w.getView(R.id.cardview_ad, v).setVisibility(View.GONE);
}
}
use of com.google.android.gms.ads.AdListener in project Space-Station-Tracker by Kiarasht.
the class MapsActivity method initializeAds.
/**
* Initialize ads when the activity is started for the first time
*/
private void initializeAds() {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
MobileAds.initialize(mContext, getString(R.string.app_ID_Main));
// Initiate the interstitial ad and onAdClosed listener
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
switch(mInterstitialAdActivity) {
case 0:
startActivity(new Intent(mContext, Locations.class));
break;
case 1:
startActivity(new Intent(mContext, PeopleinSpace.class));
break;
}
}
});
if (!mSharedPreferences.getBoolean("advertisement", false)) {
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().addTestDevice(getString(R.string.test_device)).build();
mAdView.loadAd(adRequest);
} else if (mAdView == null) {
findViewById(R.id.adView).setVisibility(View.GONE);
}
}
use of com.google.android.gms.ads.AdListener in project NetGuard by M66B.
the class ActivityMain method initAds.
private void initAds() {
// https://developers.google.com/android/reference/com/google/android/gms/ads/package-summary
MobileAds.initialize(getApplicationContext(), getString(R.string.ad_app_id));
final LinearLayout llAd = (LinearLayout) findViewById(R.id.llAd);
TextView tvAd = (TextView) findViewById(R.id.tvAd);
final AdView adView = (AdView) findViewById(R.id.adView);
SpannableString content = new SpannableString(getString(R.string.title_pro_ads));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
tvAd.setText(content);
tvAd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(ActivityMain.this, ActivityPro.class));
}
});
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);
switch(errorCode) {
case AdRequest.ERROR_CODE_INTERNAL_ERROR:
Log.w(TAG, "Ad load error=INTERNAL_ERROR");
break;
case AdRequest.ERROR_CODE_INVALID_REQUEST:
Log.w(TAG, "Ad load error=INVALID_REQUEST");
break;
case AdRequest.ERROR_CODE_NETWORK_ERROR:
Log.w(TAG, "Ad load error=NETWORK_ERROR");
break;
case AdRequest.ERROR_CODE_NO_FILL:
Log.w(TAG, "Ad load error=NO_FILL");
break;
default:
Log.w(TAG, "Ad load error=" + errorCode);
}
}
@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");
}
});
}
Aggregations