com.google.android.gms.ads.AdListener Java Examples

The following examples show how to use com.google.android.gms.ads.AdListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From BusyBox with Apache License 2.0 6 votes vote down vote up
private void setupInstallInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.install_interstitials_id);

    for (int i = 0; i < interstitialsInstallAd.length; i++) {
        if (!interstitialIsReady(interstitialsInstallAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsInstallAd[finalI] = null;
                    setupInstallInterstitialsAd();
                }
            };

            interstitialsInstallAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #2
Source File: MainActivity.java    From BusyBox with Apache License 2.0 6 votes vote down vote up
private void setupInstallInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.install_interstitials_id);

    for (int i = 0; i < interstitialsInstallAd.length; i++) {
        if (!interstitialIsReady(interstitialsInstallAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsInstallAd[finalI] = null;
                    setupInstallInterstitialsAd();
                }
            };

            interstitialsInstallAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #3
Source File: SongBroadCast.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
void showAd(Context con) {
    if (AppSettings.playAdCount%AppSettings.adOffset==0 && AppSettings.playAdCount!=0 && AppSettings.showAds) {
        Log.e(TAG, "showAd: Showing Ad..." );
        //TODO: Change ad unit ID, Sample ca-app-pub-3940256099942544/1033173712
        mInterstitialAd = new InterstitialAd(con);
        mInterstitialAd.setAdUnitId("ca-app-pub-1164424526503510/4801416648");
        mInterstitialAd.loadAd(new AdRequest.Builder().build());
        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdFailedToLoad(int i) {
                super.onAdFailedToLoad(i);
                Log.e(TAG, "onAdFailedToLoad: Ad failed to load: " + i);
            }

            @Override
            public void onAdLoaded() {
                super.onAdLoaded();
                mInterstitialAd.show();
            }
        });
    }
}
 
Example #4
Source File: PlayerActivity2.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
public static void showAd() {
    if (!AppSettings.showAds)
        return;
    //TODO: Change ad unit ID, Sample ca-app-pub-3940256099942544/1033173712
    mInterstitialAd = new InterstitialAd(activity);
    mInterstitialAd.setAdUnitId("ca-app-pub-1164424526503510/4801416648");
    mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("07153BA64BB64F7C3F726B71C4AE30B9").build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);
            Log.e(TAG, "onAdFailedToLoad: Ad failed to load: " + i);
        }

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            mInterstitialAd.show();
        }
    });
}
 
Example #5
Source File: MainActivity.java    From BusyBox with Apache License 2.0 6 votes vote down vote up
private void setupSettingsInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.settings_interstitials_id);

    for (int i = 0; i < interstitialsSettingsAd.length; i++) {
        if (!interstitialIsReady(interstitialsSettingsAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsSettingsAd[finalI] = null;
                    setupSettingsInterstitialsAd();
                    startActivity(new Intent(MainActivity.this, SettingsActivity.class));
                }
            };

            interstitialsSettingsAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #6
Source File: YTutils.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
public static void showInterstitialAd(Context activity) {
    if (!AppSettings.showAds)
        return;
    //TODO: Change ad unit ID, Sample ca-app-pub-3940256099942544/1033173712
    InterstitialAd mInterstitialAd = new InterstitialAd(activity);
    mInterstitialAd.setAdUnitId("ca-app-pub-1164424526503510/4801416648");
    mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("07153BA64BB64F7C3F726B71C4AE30B9").build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);
            Log.e(TAG, "onAdFailedToLoad: Ad failed to load: " + i);
        }

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            mInterstitialAd.show();
        }
    });
}
 
Example #7
Source File: YTutils.java    From YTPlayer with GNU General Public License v3.0 6 votes vote down vote up
public static void showAd(Context con) {

        try {
            InterstitialAd mInterstitialAd = new InterstitialAd(con);
            mInterstitialAd.setAdUnitId("ca-app-pub-1164424526503510/4801416648");
            mInterstitialAd.loadAd(new AdRequest.Builder().addTestDevice("07153BA64BB64F7C3F726B71C4AE30B9").build());
            mInterstitialAd.setAdListener(new AdListener() {
                @Override
                public void onAdFailedToLoad(int i) {
                    super.onAdFailedToLoad(i);
                    Log.e(TAG, "onAdFailedToLoad: Ad failed to load: " + i);
                }

                @Override
                public void onAdLoaded() {
                    super.onAdLoaded();
                    mInterstitialAd.show();
                }
            });
        } catch (Exception ignored) {
        }
    }
 
Example #8
Source File: MainActivity.java    From BusyBox with Apache License 2.0 6 votes vote down vote up
private void setupTabInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.tabs_interstitials_id);

    for (int i = 0; i < interstitialsTabAd.length; i++) {
        if (!interstitialIsReady(interstitialsTabAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsTabAd[finalI] = null;
                    setupTabInterstitialsAd();
                }
            };

            interstitialsTabAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #9
Source File: MainActivity.java    From USB_Mass_Storage_Enabler with MIT License 6 votes vote down vote up
void initADs() {

		if(enableADs) {
			//https://firebase.google.com/docs/admob/android/quick-start
			MobileAds.initialize(getApplicationContext(), getString(R.string.ad_app_id));
			AdView mAdView = (AdView) findViewById(R.id.adView);
			AdRequest adRequest = new AdRequest.Builder().build();
			mAdView.loadAd(adRequest);
			Log.d(LOG_TAG, "Ads initialized..");

			mInterstitialAd = new InterstitialAd(this);
			mInterstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
			mInterstitialAd.setAdListener(new AdListener() {
				@Override
				public void onAdClosed() {
					//requestNewInterstitial();
				}
			});

			requestNewInterstitial();
		}
	}
 
Example #10
Source File: HomeFragment.java    From Android with MIT License 6 votes vote down vote up
private void Ads(View v) {
    //adView = view.findViewById(R.id.adView);
    View adContainer = v.findViewById(R.id.adMobView);
   // Log.e("TAG :BANNERhomefragment",ADMOB_PLEX_BANNER_1);

    AdView mAdView = new AdView(mContext);
    mAdView.setAdSize(AdSize.SMART_BANNER);
    mAdView.setAdUnitId(ADMOB_PLEX_BANNER_1);
    ((RelativeLayout)adContainer).addView(mAdView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    mInterstitialAd = new InterstitialAd(getActivity());
    mInterstitialAd.setAdUnitId(ADMOB_PLEX_INTERSTITIAL_1);
    mInterstitialAd.loadAd(new AdRequest.Builder().build());
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {

        }
    });

}
 
Example #11
Source File: AdsManager.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
public static void showFullScreenAdsIfRequired(final StateActivity activity) {
    if (Premium.isPremiumUser(activity)) return;
    final InterstitialAd interstitialAd = new InterstitialAd(activity.getApplicationContext());
    interstitialAd.setAdUnitId(AdConstants.AdUnitId.AD_UNIT_ID_INTERSTITIAL);
    AdRequest.Builder request = new AdRequest.Builder();
    if (BuildConfig.DEBUG) {
        request.addTestDevice(TEST_DEVICE_ID);
    }
    interstitialAd.loadAd(request.build());
    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            if (!activity.isFinishing() && activity.isActivityVisible()
                    && !Premium.isPremiumUser(activity)) {
                interstitialAd.show();
            }
        }
    });
}
 
Example #12
Source File: ViewStoryActivity.java    From Instagram-Profile-Downloader with MIT License 6 votes vote down vote up
@Override
public void onBackPressed() {
    if (interstitialAd.isLoaded()) {
        interstitialAd.show();
        interstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                super.onAdClosed();
                finish();
            }
        });
    } else {
        super.onBackPressed();
        finish();
        overridePendingTransition(R.anim.enter_signin, R.anim.exit_main);
    }

}
 
Example #13
Source File: InterstitialAdActivity.java    From Instagram-Profile-Downloader with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_interstitial_ad);

    mInterstitialAd = new InterstitialAd(this);

    // set the ad unit ID
    mInterstitialAd.setAdUnitId("ca-app-pub-7814549536543810/9305872827");

    AdRequest adRequest = new AdRequest.Builder()
            .build();

    // Load ads into Interstitial Ads
    mInterstitialAd.loadAd(adRequest);

    mInterstitialAd.setAdListener(new AdListener() {
        public void onAdLoaded() {
            showInterstitial();
        }
    });
}
 
Example #14
Source File: DemoActivity.java    From prebid-mobile-android with Apache License 2.0 6 votes vote down vote up
private void setupAMInterstitial(String id) {
    amInterstitial = new PublisherInterstitialAd(this);
    amInterstitial.setAdUnitId(id);
    amInterstitial.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            amInterstitial.show();
        }

        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);
            AlertDialog.Builder builder;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                builder = new AlertDialog.Builder(DemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
            } else {
                builder = new AlertDialog.Builder(DemoActivity.this);
            }
            builder.setTitle("Failed to load AdManager interstitial ad")
                    .setMessage("Error code: " + i)
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .show();
        }
    });
}
 
Example #15
Source File: HackChatInterstitialAd.java    From hack.chat-android with MIT License 6 votes vote down vote up
/**
 * Sets up the interstitial ad object.
 */
private void setUpInterstitialAd() throws Exception {
    if (!(advertable instanceof  Activity)) {
        throw new Exception("Only Activity class can implement HackChatInterstitialAdvertable.");
    }
    interstitialAd = new InterstitialAd((Activity) advertable);
    interstitialAd.setAdUnitId(adUnitId);

    interstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            advertable.onInterstitialAdClosed();
        }
    });

    requestInterstitialAd();
}
 
Example #16
Source File: MainActivity.java    From BusyBox with Apache License 2.0 6 votes vote down vote up
private void setupSettingsInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.settings_interstitials_id);

    for (int i = 0; i < interstitialsSettingsAd.length; i++) {
        if (!interstitialIsReady(interstitialsSettingsAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsSettingsAd[finalI] = null;
                    setupSettingsInterstitialsAd();
                    startActivity(new Intent(MainActivity.this, SettingsActivity.class));
                }
            };

            interstitialsSettingsAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #17
Source File: MainActivity.java    From BusyBox with Apache License 2.0 6 votes vote down vote up
private void setupTabInterstitialsAd() {
    String[] ids = getResources().getStringArray(R.array.tabs_interstitials_id);

    for (int i = 0; i < interstitialsTabAd.length; i++) {
        if (!interstitialIsReady(interstitialsTabAd[i])) {
            final int finalI = i;

            AdListener adListener = new AdListener() {
                @Override public void onAdClosed() {
                    super.onAdClosed();
                    interstitialsTabAd[finalI] = null;
                    setupTabInterstitialsAd();
                }
            };

            interstitialsTabAd[i] = newInterstitialAd(ids[i], adListener);
        }
    }
}
 
Example #18
Source File: AdmobFetcherExpress.java    From admobadapter with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
        }
    });
}
 
Example #19
Source File: AdmobFetcherBanner.java    From admobadapter with Apache License 2.0 6 votes vote down vote up
/**
 * Subscribing to the banner ads events
 * @param adView
 */
protected synchronized void setupAd(final AdView 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);
        }
    });
}
 
Example #20
Source File: AdViewIdlingResource.java    From quickstart-android with Apache License 2.0 6 votes vote down vote up
public AdViewIdlingResource(AdView adView) {
    if (adView == null) {
        throw new IllegalArgumentException(
                "Can't initialize AdViewIdlingResource with null AdView.");
    }

    this.mAdView = adView;
    this.mAdListener = new AdListener() {
        @Override
        public void onAdFailedToLoad(int i) {
            transitionToIdle();
        }

        @Override
        public void onAdLoaded() {
            transitionToIdle();
        }
    };

    mAdView.setAdListener(mAdListener);
}
 
Example #21
Source File: GADManager.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
private void initAD(){
    mInterstitialAd = new InterstitialAd(context);
    mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            requestNewInterstitial();
        }

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();

            Toast.makeText(context, "广告加载完成, 点击show按钮显示广告", Toast.LENGTH_LONG).show();

            Log.e("tag","onAdLoaded");
        }
    });
    requestNewInterstitial();
}
 
Example #22
Source File: AdMobComboProvider.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void showInterstitial(final InterstitialPoint ret) {
    Game.instance().runOnUiThread(() -> {
        if (mInterstitialAd == null) {
            EventCollector.logException("mInterstitialAd == null");
            AdsUtilsCommon.interstitialFailed(AdMobComboProvider.this, ret);
            return;
        }

        if (!mInterstitialAd.isLoaded()) {
            EventCollector.logException("not loaded");
            AdsUtilsCommon.interstitialFailed(AdMobComboProvider.this, ret);
            return;
        }

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                requestNewInterstitial();
                ret.returnToWork(true);
            }
        });
        mInterstitialAd.show();
    });

}
 
Example #23
Source File: MainActivity.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
private InterstitialAd newInterstitialAd(String placementId, AdListener listener) {
    InterstitialAd interstitialAd = new InterstitialAd(this);
    interstitialAd.setAdListener(listener);
    interstitialAd.setAdUnitId(placementId);
    interstitialAd.loadAd(getAdRequest());
    return interstitialAd;
}
 
Example #24
Source File: AdmobFetcher.java    From admobadapter with Apache License 2.0 5 votes vote down vote up
/**
 * Subscribing to the native ads events
 */
protected synchronized void setupAds() {
    String unitId = getReleaseUnitId() != null ? getReleaseUnitId() : getDefaultUnitId();
    AdLoader.Builder adloaderBuilder = new AdLoader.Builder(mContext.get(), unitId)
            .withAdListener(new AdListener() {
                @Override
                public void onAdFailedToLoad(int errorCode) {
                    // Handle the failure by logging, altering the UI, etc.
                    Log.i(TAG, "onAdFailedToLoad " + errorCode);
                    lockFetch.set(false);
                    mFetchFailCount++;
                    mFetchingAdsCnt--;
                    ensurePrefetchAmount();
                    onAdFailed( mPrefetchedAdList.size(), errorCode, null);
                }
            })
            .withNativeAdOptions(new NativeAdOptions.Builder()
                    // Methods in the NativeAdOptions.Builder class can be
                    // used here to specify individual options settings.
                    .build());
    if(getAdTypeToFetch().contains(EAdType.ADVANCED_INSTALLAPP))
        adloaderBuilder.forAppInstallAd(new NativeAppInstallAd.OnAppInstallAdLoadedListener() {
                @Override
                public void onAppInstallAdLoaded(NativeAppInstallAd appInstallAd) {
                    onAdFetched(appInstallAd);
                }
            });
    if(getAdTypeToFetch().contains(EAdType.ADVANCED_CONTENT))
        adloaderBuilder.forContentAd(new NativeContentAd.OnContentAdLoadedListener() {
                @Override
                public void onContentAdLoaded(NativeContentAd contentAd) {
                    onAdFetched(contentAd);
                }
            });

    adLoader = adloaderBuilder.build();
}
 
Example #25
Source File: AdLayout.java    From KernelAdiutor with GNU General Public License v3.0 5 votes vote down vote up
public AdLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    setOrientation(VERTICAL);

    LayoutInflater.from(context).inflate(R.layout.ad_layout_view, this);
    FrameLayout mAdLayout = findViewById(R.id.ad_layout);
    mProgress = findViewById(R.id.progress);
    mAdText = findViewById(R.id.ad_text);
    mGHImage = findViewById(R.id.gh_image);

    findViewById(R.id.remove_ad).setOnClickListener(v
            -> ViewUtils.dialogDonate(v.getContext()).show());

    mAdView = new AdView(context);
    mAdView.setAdSize(AdSize.SMART_BANNER);
    mAdView.setAdUnitId("ca-app-pub-1851546461606210/7537613480");
    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            mAdFailedLoading = false;
            mProgress.setVisibility(GONE);
            if (mAdView.getParent() == null) {
                mAdLayout.addView(mAdView);
            }
        }

        @Override
        public void onAdFailedToLoad(int i) {
            super.onAdFailedToLoad(i);
            mAdFailedLoading = true;
            loadGHAd();
        }
    });
    mAdView.loadAd(new AdRequest.Builder().build());
}
 
Example #26
Source File: MainActivity.java    From GooglePlayServiceLocationSupport with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mOldLocation = (TextView) findViewById(R.id.oldlocation);
    mNewLocation = (TextView) findViewById(R.id.newlocation);
    AdView mAdView = (AdView) findViewById(R.id.adView);

    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId(getResources().getString(R.string.interstitial_ad));
    mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            startActivity(new Intent(MainActivity.this, FragmentLocationActivity.class));
        }
    });
    AdRequest adRequest = new AdRequest.Builder().build();
    mInterstitialAd.loadAd(adRequest);

    adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    findViewById(R.id.btn_fragment).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInterstitialAd != null && mInterstitialAd.isLoaded())
                mInterstitialAd.show();
            else startActivity(new Intent(MainActivity.this, FragmentLocationActivity.class));
        }
    });
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
}
 
Example #27
Source File: MainActivity.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
private void setupBanners() {
    AdRequest.Builder builder = new AdRequest.Builder();
    if (App.isDebuggable()) {
        builder.addTestDevice(DeviceUtils.getDeviceId());
    }

    adViewTiers[currentAdViewIndex] = new AdView(this);
    adViewTiers[currentAdViewIndex].setAdSize(AdSize.SMART_BANNER);
    adViewTiers[currentAdViewIndex]
        .setAdUnitId(getResources().getStringArray(R.array.banners_id)[currentAdViewIndex]);
    adViewTiers[currentAdViewIndex].setAdListener(new AdListener() {
        @Override public void onAdFailedToLoad(int errorCode) {
            if (currentAdViewIndex != (adViewTiers.length - 1)) {
                currentAdViewIndex++;
                setupBanners();
            } else if (adContainer.getVisibility() == View.VISIBLE) {
                Technique.SLIDE_OUT_DOWN.getComposer().hideOnFinished().playOn(adContainer);
            }
        }

        @Override public void onAdLoaded() {
            adContainer.setVisibility(View.VISIBLE);
            if (adContainer.getChildCount() != 0) {
                adContainer.removeAllViews();
            }
            adContainer.addView(adViewTiers[currentAdViewIndex]);
            Analytics.newEvent("on_ad_loaded")
                .put("id", adViewTiers[currentAdViewIndex].getAdUnitId()).log();
        }
    });

    adViewTiers[currentAdViewIndex].loadAd(builder.build());
}
 
Example #28
Source File: GenerateShortcutHelper.java    From TvAppRepo with Apache License 2.0 5 votes vote down vote up
static InterstitialAd showVisualAd(Activity activity) {
    final InterstitialAd video =  new InterstitialAd(activity);
    video.setAdUnitId(activity.getString(R.string.interstitial_ad_unit_id));
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .build();
    video.loadAd(adRequest);
    Log.d(TAG, "Loading ad");

    video.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            Log.d(TAG, "Ad loaded");
            // Show video as soon as possible
            video.show();
        }

        @Override
        public void onAdClosed() {
            super.onAdClosed();
            Log.d(TAG, "Ad closed");
        }
    });

    return video;
}
 
Example #29
Source File: MainActivity.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
private void setupBanners() {
    AdRequest.Builder builder = new AdRequest.Builder();
    if (App.isDebuggable()) {
        builder.addTestDevice(DeviceUtils.getDeviceId());
    }

    adViewTiers[currentAdViewIndex] = new AdView(this);
    adViewTiers[currentAdViewIndex].setAdSize(AdSize.SMART_BANNER);
    adViewTiers[currentAdViewIndex]
        .setAdUnitId(getResources().getStringArray(R.array.banners_id)[currentAdViewIndex]);
    adViewTiers[currentAdViewIndex].setAdListener(new AdListener() {
        @Override public void onAdFailedToLoad(int errorCode) {
            if (currentAdViewIndex != (adViewTiers.length - 1)) {
                currentAdViewIndex++;
                setupBanners();
            } else if (adContainer.getVisibility() == View.VISIBLE) {
                Technique.SLIDE_OUT_DOWN.getComposer().hideOnFinished().playOn(adContainer);
            }
        }

        @Override public void onAdLoaded() {
            adContainer.setVisibility(View.VISIBLE);
            if (adContainer.getChildCount() != 0) {
                adContainer.removeAllViews();
            }
            adContainer.addView(adViewTiers[currentAdViewIndex]);
            Analytics.newEvent("on_ad_loaded")
                .put("id", adViewTiers[currentAdViewIndex].getAdUnitId()).log();
        }
    });

    adViewTiers[currentAdViewIndex].loadAd(builder.build());
}
 
Example #30
Source File: MainUI.java    From Busybox-Installer-No-Root with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_ui);

    context = getApplicationContext();

    MobileAds.initialize(this);

    mAdView = findViewById(R.id.adView);
    mAdView.loadAd(new AdRequest.Builder().build());

    Toolbar toolbar = findViewById(R.id.toolbar);

    setSupportActionBar(toolbar);

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            mAdView.loadAd(new AdRequest.Builder().build());
        }
    });

    if(savedInstanceState == null){
        MenuItem selected = navigationView.getMenu().findItem(R.id.method1);
        selected.setCheckable(true);
        selected.setChecked(true);
        newFragment(0);
    }
}