Exemple #1
0
    @Override
    protected void onPostExecute(AdFetchResult result) {
      if (!isMostCurrentTask()) {
        Log.d("MoPub", "Ad response is stale.");
        releaseResources();
        return;
      }

      // If cleanup() has already been called on the AdView, don't proceed.
      if (mAdView == null || mAdView.isDestroyed()) {
        if (result != null) {
          result.cleanup();
        }
        mAdFetcher.markTaskCompleted(mTaskId);
        releaseResources();
        return;
      }

      if (result == null) {
        if (mException != null) {
          Log.d("MoPub", "Exception caught while loading ad: " + mException);
        }

        mAdView.loadFailUrl();

        /*
         * There are numerous reasons for the ad fetch to fail, but only in the specific
         * case of actual server failure should we exponentially back off.
         *
         * Note: When we call AdView's loadFailUrl() from this block, AdView's mFailUrl
         * will always be null, forcing a scheduled refresh. Here, we place the exponential
         * backoff after AdView's loadFailUrl because we only want to increase refresh times
         * after the first failure refresh timer is scheduled, and not before.
         */
        if (mFetchStatus == FetchStatus.INVALID_SERVER_RESPONSE_BACKOFF) {
          exponentialBackoff();
          mFetchStatus = FetchStatus.NOT_SET;
        }
      } else {
        result.execute();
        result.cleanup();
      }

      mAdFetcher.markTaskCompleted(mTaskId);
      releaseResources();
    }
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
      AdView adView = (AdView) view;

      // Handle the special mopub:// scheme calls.
      if (url.startsWith("mopub://")) {
        Uri uri = Uri.parse(url);
        String host = uri.getHost();

        if (host.equals("finishLoad")) adView.adDidLoad();
        else if (host.equals("close")) adView.adDidClose();
        else if (host.equals("failLoad")) adView.loadFailUrl();
        else if (host.equals("custom")) adView.handleCustomIntentFromUri(uri);
        return true;
      }
      // Handle other phone intents.
      else if (url.startsWith("tel:")
          || url.startsWith("voicemail:")
          || url.startsWith("sms:")
          || url.startsWith("mailto:")
          || url.startsWith("geo:")
          || url.startsWith("google.streetview:")) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        try {
          getContext().startActivity(intent);
        } catch (ActivityNotFoundException e) {
          Log.w(
              "MoPub",
              "Could not handle intent with URI: "
                  + url
                  + ". Is this intent unsupported on your phone?");
        }
        return true;
      }

      url = urlWithClickTrackingRedirect(adView, url);
      Log.d("MoPub", "Ad clicked. Click URL: " + url);
      mMoPubView.adClicked();

      showBrowserAfterFollowingRedirectsForUrl(url);
      return true;
    }
 protected void loadFailUrl() {
   if (mAdView != null) mAdView.loadFailUrl();
 }
Exemple #4
0
 public void loadFailUrl() {
   if (mAdView == null) {
     return;
   }
   mAdView.loadFailUrl();
 }