void stop() { Clog.d(Clog.publicFunctionsLogTag, Clog.getString(R.string.stop)); mAdFetcher.stop(); loadAdHasBeenCalled = false; }
/** * This must be called from the UI thread, * when permanently remove the AdView from the view hierarchy. */ public void destroy() { Clog.d(Clog.baseLogTag, "called destroy() on AdView"); if (this.lastDisplayable != null) { this.lastDisplayable.destroy(); this.lastDisplayable = null; } // Just in case, kill the adfetcher's service if (mAdFetcher != null) { mAdFetcher.stop(); } }
/** * Destroy this InterstitialAdView object. */ @Override public void destroy() { super.destroy(); Clog.d(Clog.publicFunctionsLogTag, Clog.getString(R.string.destroy_int)); if (this.mAdFetcher != null) mAdFetcher.stop(); adQueue.clear(); InterstitialAdView.INTERSTITIALADVIEW_TO_USE = null; }
void setPeriod(int period) { boolean periodChanged = this.period != period; this.period = period; if ((periodChanged) && !state.equals(STATE.STOPPED)) { // We should reset. Clog.d(Clog.baseLogTag, "AdFetcher refresh period changed to " + this.period); Clog.d(Clog.baseLogTag, "Resetting AdFetcher"); stop(); start(); } }
@Override public void tearDown() { super.tearDown(); if (adFetcher != null) { adFetcher.stop(); adFetcher.clearDurations(); } adFetcher = null; }
/** * Loads a new ad, if the ad space is visible. You should * have called setPlacementID before invoking this method. * * @return true means the ad will begin loading; false otherwise. */ @Override public boolean loadAd() { if (!isReadyToStart()) return false; if (mAdFetcher != null) { // Reload Ad Fetcher to get new ad at user's request mAdFetcher.stop(); mAdFetcher.clearDurations(); mAdFetcher.start(); if(this.getWindowVisibility() != VISIBLE){ loadedOffscreen = true; } return true; } return false; }
/** * Requests a new interstitial ad from the server and stores it in * a local queue. Note that interstitials have a timeout of 60 * seconds; you must show the interstitial (by calling * <code>show()</code>) within 60 seconds of getting a response; * otherwise, the ad will not show. * * @return <code>true</code> if the ad load was successfully * dispatched; <code>false</code> otherwise. */ @Override public boolean loadAd() { Clog.d(Clog.publicFunctionsLogTag, Clog.getString(R.string.load_ad_int)); if (!isReadyToStart()) return false; if (mAdFetcher != null) { // Load an interstitial ad mAdFetcher.stop(); mAdFetcher.start(); return true; } return false; }
/** * Call this to request a native ad for parameters described by this object. */ @Override public boolean loadAd() { if (listener == null) { // error message Clog.e(Clog.nativeLogTag, "No listener installed for this request, won't load a new ad"); return false; } if (isLoading) { Clog.e(Clog.nativeLogTag, "Still loading last native ad , won't load a new ad"); return false; } if (requestParameters.isReadyForRequest()) { mAdFetcher.stop(); mAdFetcher.clearDurations(); mAdFetcher.start(); isLoading = true; return true; } return false; }
setAdType(AdType.VIDEO); if (mAdFetcher.getState() == AdFetcher.STATE.AUTO_REFRESH) { mAdFetcher.stop();
@Test public void testStop() { if (adFetcher != null) { // not needed, but in case AdRequest is run server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.blank())); clearAAIDAsyncTasks(); // start an AdFetcher normally, until an AdRequest is queued adFetcher.start(); Lock.pause(1000); // added this so jenkins can have enough time to process assertExpectedBGTasksAfterOneAdRequest(1); assertNotSame(AdFetcher.STATE.STOPPED, adFetcher.getState()); adFetcher.stop(); // pause until a scheduler has a task in queue waitForTasks(); // Run the cancel command on AdRequest Robolectric.flushForegroundThreadScheduler(); // Run the pending AdRequest from start() -- should have been canceled while (Robolectric.getBackgroundThreadScheduler().areAnyRunnable()) { Robolectric.getBackgroundThreadScheduler().runOneTask(); } // A normally executed AdRequest will queue onPostExecute call to the UI thread, // but it should be canceled, and queue nothing int uiTaskCount = Robolectric.getForegroundThreadScheduler().size(); assertEquals(0, uiTaskCount); assertEquals(AdFetcher.STATE.STOPPED, adFetcher.getState()); } }