/** * Pops interstitial ads from the queue until it finds one that * has not exceeded the 60 second timeout, and displays it in a * new activity. All ads in the queue which have exceeded the * timeout are removed. * * @return The number of remaining ads in the queue that do not * exceed the timeout. */ public int show() { return showWithAutoDismissDelay(-1); }
private void triggerBrowserLaunchEvent() { if (adView != null && adView instanceof InterstitialAdView) { ((InterstitialAdView) adView).browserLaunched(); } }
@Override public void backPressed() { // By default the AdActivity will finish onBackKeyPress. So just trigger onAdCollapsed. if (adView != null && adView.getAdDispatcher() != null) { adView.getAdDispatcher().onAdCollapsed(); } }
int attr = a.getIndex(i); if (attr == R.styleable.InterstitialAdView_placement_id) { setPlacementID(a.getString(attr)); Clog.d(Clog.xmlLogTag, Clog.getString(R.string.placement_id, a.getString(attr))); Clog.d(Clog.xmlLogTag, Clog.getString(R.string.xml_set_opens_native_browser)); this.setOpensNativeBrowser(a.getBoolean(attr, false)); } else if (attr == R.styleable.InterstitialAdView_show_loading_indicator) { Clog.d(Clog.xmlLogTag, Clog.getString(R.string.show_loading_indicator_xml)); setShowLoadingIndicator(a.getBoolean(attr, true)); } else if (attr == R.styleable.InterstitialAdView_load_landing_page_in_background) { setLoadsInBackground(a.getBoolean(attr, true)); Clog.d(Clog.xmlLogTag, Clog.getString(R.string.xml_load_landing_page_in_background, getLoadsInBackground()));
if (adView == null) return; adView.setAdImplementation(this); layout.setBackgroundColor(adView.getBackgroundColor()); layout.removeAllViews(); if (adView.getParent() != null) { ((ViewGroup) adView.getParent()).removeAllViews(); InterstitialAdQueueEntry iAQE = adView.getAdQueue().poll(); && (now - iAQE.getTime() > InterstitialAdView.MAX_AGE || now - iAQE.getTime() < 0)) { Clog.w(Clog.baseLogTag, Clog.getString(R.string.too_old)); iAQE = adView.getAdQueue().poll();
@Override public void setup() { super.setup(); bannerAdView = new BannerAdView(activity); bannerAdView.setPlacementID("0"); bannerAdView.setAdListener(this); bannerAdView.setAdSize(320, 50); bannerAdView.setAutoRefreshInterval(-1); interstitialAdView = new InterstitialAdView(activity); interstitialAdView.setPlacementID("0"); interstitialAdView.setAdListener(this); adLoaded = false; adFailed = false; adExpanded = false; adCollapsed = false; adClicked = false; adClickedWithUrl = false; }
boolean validAdExists = removeStaleAds(now); fireImpressionTracker(); Intent i = new Intent(getContext(), activity_clz); i.putExtra(AdActivity.INTENT_KEY_ACTIVITY_TYPE, AdActivity.ACTIVITY_TYPE_INTERSTITIAL); fireImpressionTracker(); getContext().startActivity(i); } catch (ActivityNotFoundException e) { INTERSTITIALADVIEW_TO_USE = null;
@Override public void onAdLoaded(AdView adView) { Clog.w(TestUtil.testLogTag, "BaseViewAdTest onAdLoaded"); adLoaded = true; if (adView.getMediaType() == MediaType.BANNER) { isBannerLoaded = true; } if (adView.getMediaType() == MediaType.INTERSTITIAL) { if (enableInterstitialShowonLoad) { if (isAutoDismissDelay) { interstitialAdView.showWithAutoDismissDelay(5); } else { interstitialAdView.show(); } } } }
@Test public void testContentUrl(){ interstitialAdView.addCustomKeywords("content_url", "www.appnexus.com"); String postData = getRequestParametersPostData(); assertTrue(postData.contains("\"key\":\"content_url\",\"value\":[\"www.appnexus.com\"]")); interstitialAdView.getRequestParameters().getCustomKeywords().contains("content_url"); }
@Test public void testANInterstitialWithoutAutoDismissAdDelay() { setInterstitialShowonLoad(true); setAutoDismissDelay(false); server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.banner())); // First queue a regular HTML banner response assertTrue(interstitialAdView.getAdType() == AdType.UNKNOWN); // First tests if ad_type is UNKNOWN initially executeInterstitialRequest(); //Checking if onAdLoaded is called or not assertTrue(adLoaded); //Creating shadow of the required activity ShadowActivity shadowActivity = shadowOf(activity); Intent startedIntent = shadowActivity.getNextStartedActivity(); //Checking if an AdActivity is opened or not assertEquals(AdActivity.class.getCanonicalName(), startedIntent.getComponent().getClassName()); //Checking if an INTENT_KEY_ACTIVITY_TYPE is equivalent to INTERSTITIAL or not assertEquals(startedIntent.getStringExtra(INTENT_KEY_ACTIVITY_TYPE), ACTIVITY_TYPE_INTERSTITIAL); //Checking if an INTENT_KEY_AUTODISMISS_DELAY is equual to 5 or not assertEquals(startedIntent.getIntExtra(INTENT_KEY_AUTODISMISS_DELAY, 0), -1); }
@Override protected void display(Displayable d) { // safety check: this should never evaluate to true if (!checkDisplayable(d)) { return; } if (lastDisplayable != null) { lastDisplayable.destroy(); } //Prevent responses from reaching this InterstitialAdView if it has been destroyed already if (!destroyed && !paused) { lastDisplayable = d; adQueue.add(new DisplayableInterstitialAdQueueEntry(d, System.currentTimeMillis(), false, null)); } else { if (d != null) { d.destroy(); } } }
@Override public void setup() { super.setup(); interstitialAdView = new InterstitialAdView(activity); requestParameters = interstitialAdView.requestParameters; }
@Test public void testANInterstitialWithAutoDismissAdDelay() throws InterruptedException { setInterstitialShowonLoad(true); setAutoDismissDelay(true); server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.banner())); // First queue a regular HTML banner response assertTrue(interstitialAdView.getAdType() == AdType.UNKNOWN); // First 2tests if ad_type is UNKNOW initially executeInterstitialRequest(); //Checking if onAdLoaded is called or not assertTrue(adLoaded); //Creating shadow of the required activity ShadowActivity shadowActivity = shadowOf(activity); Intent startedIntent = shadowActivity.getNextStartedActivity(); //Checking if an AdActivity is opened or not assertEquals(AdActivity.class.getCanonicalName(), startedIntent.getComponent().getClassName()); //Checking if an INTENT_KEY_ACTIVITY_TYPE is equivalent to INTERSTITIAL or not assertEquals(startedIntent.getStringExtra(INTENT_KEY_ACTIVITY_TYPE), ACTIVITY_TYPE_INTERSTITIAL); //Checking if an INTENT_KEY_AUTODISMISS_DELAY is equual to 5 or not assertEquals(startedIntent.getIntExtra(INTENT_KEY_AUTODISMISS_DELAY, 0), 5); }
@Override protected void displayMediated(MediatedDisplayable d) { // safety check: this should never evaluate to true if (!checkDisplayable(d)) { return; } if (lastDisplayable != null) { lastDisplayable.destroy(); } //Prevent responses from reaching this InterstitialAdView if it has been destroyed already if (!destroyed && !paused) { lastDisplayable = d; adQueue.add(new DisplayableInterstitialAdQueueEntry(d, System.currentTimeMillis(), true, d.getMAVC())); } else { if (d != null) { d.destroy(); } } }
private void dismissInterstitial() { if (adActivity != null) { if (adView != null && adView.getAdDispatcher() != null) { adView.getAdDispatcher().onAdCollapsed(); } adActivity.finish(); } }