/**
   * Called upon user click. Attempts open mopubnativebrowser links in the device browser and all
   * other links in the MoPub in-app browser.
   */
  @VisibleForTesting
  void handleClick(final List<String> clickThroughTrackers, final String clickThroughUrl) {
    makeTrackingHttpRequest(clickThroughTrackers, getContext(), BaseEvent.Name.CLICK_REQUEST);

    if (clickThroughUrl == null) {
      return;
    }

    broadcastAction(ACTION_INTERSTITIAL_CLICK);

    if (Intents.isNativeBrowserScheme(clickThroughUrl)) {
      try {
        final Intent intent = Intents.intentForNativeBrowserScheme(clickThroughUrl);
        Intents.startActivity(getContext(), intent);
        return;
      } catch (UrlParseException e) {
        MoPubLog.d(e.getMessage());
      } catch (IntentNotResolvableException e) {
        MoPubLog.d("Could not handle intent for URI: " + clickThroughUrl + ". " + e.getMessage());
      }

      return;
    }

    Bundle bundle = new Bundle();
    bundle.putString(MoPubBrowser.DESTINATION_URL_KEY, clickThroughUrl);

    getBaseVideoViewControllerListener()
        .onStartActivityForResult(MoPubBrowser.class, MOPUB_BROWSER_REQUEST_CODE, bundle);
  }
示例#2
0
  protected void loadCustomEvent(String customEventClassName, Map<String, String> serverExtras) {
    if (mAdViewController == null) {
      return;
    }
    if (TextUtils.isEmpty(customEventClassName)) {
      MoPubLog.d("Couldn't invoke custom event because the server did not specify one.");
      loadFailUrl(ADAPTER_NOT_FOUND);
      return;
    }

    if (mCustomEventBannerAdapter != null) {
      mCustomEventBannerAdapter.invalidate();
    }

    MoPubLog.d("Loading custom event adapter.");

    mCustomEventBannerAdapter =
        CustomEventBannerAdapterFactory.create(
            this,
            customEventClassName,
            serverExtras,
            mAdViewController.getBroadcastIdentifier(),
            mAdViewController.getAdReport());
    mCustomEventBannerAdapter.loadAd();
  }
示例#3
0
  public MoPubView(Context context, AttributeSet attrs) {
    super(context, attrs);

    ManifestUtils.checkWebViewActivitiesDeclared(context);

    mContext = context;
    mScreenVisibility = getVisibility();

    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);

    // There is a rare bug in Froyo/2.2 where creation of a WebView causes a
    // NullPointerException. (http://code.google.com/p/android/issues/detail?id=10789)
    // It happens when the WebView can't access the local file store to make a cache file.
    // Here, we'll work around it by trying to create a file store and then just go inert
    // if it's not accessible.
    if (WebViewDatabase.getInstance(context) == null) {
      MoPubLog.e(
          "Disabling MoPub. Local cache file is inaccessible so MoPub will "
              + "fail if we try to create a WebView. Details of this Android bug found at:"
              + "http://code.google.com/p/android/issues/detail?id=10789");
      return;
    }

    mAdViewController = AdViewControllerFactory.create(context, this);
    registerScreenStateBroadcastReceiver();
  }
示例#4
0
 public boolean getAutorefreshEnabled() {
   if (mAdViewController != null) return mAdViewController.getAutorefreshEnabled();
   else {
     MoPubLog.d("Can't get autorefresh status for destroyed MoPubView. " + "Returning false.");
     return false;
   }
 }
 @Override
 public void didDismissRewardedVideo(String location) {
   // This is called before didCloseRewardedVideo and didClickRewardedVideo
   super.didDismissRewardedVideo(location);
   MoPubRewardedVideoManager.onRewardedVideoClosed(ChartboostRewardedVideo.class, location);
   MoPubLog.d("Chartboost rewarded video dismissed for location " + location + ".");
 }
示例#6
0
 public boolean getTesting() {
   if (mAdViewController != null) return mAdViewController.getTesting();
   else {
     MoPubLog.d("Can't get testing status for destroyed MoPubView. " + "Returning false.");
     return false;
   }
 }
示例#7
0
 private void unregisterScreenStateBroadcastReceiver() {
   try {
     mContext.unregisterReceiver(mScreenStateReceiver);
   } catch (Exception IllegalArgumentException) {
     MoPubLog.d("Failed to unregister screen state broadcast receiver (never registered).");
   }
 }
 @Override
 public void showVideo() {
   if (hasVideoAvailable()) {
     Chartboost.showRewardedVideo(mLocation);
   } else {
     MoPubLog.d("Attempted to show Chartboost rewarded video before it was available.");
   }
 }
 @Override
 protected void performAction(
     @NonNull final Context context,
     @NonNull final Uri uri,
     @NonNull final UrlHandler urlHandler)
     throws IntentNotResolvableException {
   MoPubLog.d("Link to about page ignored.");
 }
示例#10
0
  protected void adLoaded() {
    MoPubLog.d("adLoaded");

    if (mBannerAdListener != null) {
      mBannerAdListener.onBannerLoaded(this);
    } else if (mOnAdLoadedListener != null) {
      mOnAdLoadedListener.OnAdLoaded(this);
    }
  }
  /**
   * Substitutes each {@code %s} in {@code template} with an argument. These are matched by position
   * - the first {@code %s} gets {@code args[0]}, etc.
   */
  private static String format(String template, Object... args) {
    template = String.valueOf(template); // null -> "null"

    try {
      return String.format(template, args);
    } catch (IllegalFormatException exception) {
      MoPubLog.e("MoPub preconditions had a format exception: " + exception.getMessage());
      return template;
    }
  }
示例#12
0
 Context getContextOrDestroy() {
   final Context context = mContext.get();
   if (context == null) {
     destroy();
     MoPubLog.d(
         "Weak reference to Activity Context in MoPubNative became null. This instance"
             + " of MoPubNative is destroyed and No more requests will be processed.");
   }
   return context;
 }
    @Override
    public void didFailToLoadRewardedVideo(String location, CBError.CBImpressionError error) {
      super.didFailToLoadRewardedVideo(location, error);

      if (mLocationsToLoad.contains(location)) {
        MoPubLog.d("Chartboost rewarded video cache failed for location " + location + ".");
        MoPubRewardedVideoManager.onRewardedVideoLoadFailure(
            ChartboostRewardedVideo.class, location, VIDEO_DOWNLOAD_ERROR);
        mLocationsToLoad.remove(location);
      }
    }
    @Override
    public void didCacheRewardedVideo(String location) {
      super.didCacheRewardedVideo(location);

      if (mLocationsToLoad.contains(location)) {
        MoPubLog.d("Chartboost rewarded video cached for location " + location + ".");
        MoPubRewardedVideoManager.onRewardedVideoLoadSuccess(
            ChartboostRewardedVideo.class, location);
        mLocationsToLoad.remove(location);
      }
    }
示例#15
0
 private void downloadCompanionAd() {
   if (mVastCompanionAd != null) {
     try {
       final HttpGet httpGet = initializeHttpGet(mVastCompanionAd.getImageUrl(), getContext());
       final DownloadTask downloadTask = new DownloadTask(this);
       AsyncTasks.safeExecuteOnExecutor(downloadTask, httpGet);
     } catch (Exception e) {
       MoPubLog.d("Failed to download companion ad", e);
     }
   }
 }
 final void loadCustomEvent(Activity activity, Map map, Map map1) {
   try {
     if (checkAndInitializeSdk(activity, map, map1)) {
       MoPubLifecycleManager.getInstance(activity).addLifecycleListener(getLifecycleListener());
     }
     loadWithSdkInitialized(activity, map, map1);
     return;
   }
   // Misplaced declaration of an exception variable
   catch (Activity activity) {
     MoPubLog.e(activity.getMessage());
   }
 }
示例#17
0
 @VisibleForTesting
 void onAdError(@NonNull final VolleyError volleyError) {
   MoPubLog.d("Native ad request failed.", volleyError);
   if (volleyError instanceof MoPubNetworkError) {
     MoPubNetworkError error = (MoPubNetworkError) volleyError;
     switch (error.getReason()) {
       case BAD_BODY:
         mMoPubNativeNetworkListener.onNativeFail(INVALID_RESPONSE);
         return;
       case BAD_HEADER_DATA:
         mMoPubNativeNetworkListener.onNativeFail(INVALID_RESPONSE);
         return;
       case WARMING_UP:
         // Used for the sample app to signal a toast.
         // This is not customer-facing except in the sample app.
         MoPubLog.c(MoPubErrorCode.WARMUP.toString());
         mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE);
         return;
       case NO_FILL:
         mMoPubNativeNetworkListener.onNativeFail(EMPTY_AD_RESPONSE);
         return;
       case UNSPECIFIED:
       default:
         mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED);
         return;
     }
   } else {
     // Process our other status code errors.
     NetworkResponse response = volleyError.networkResponse;
     if (response != null && response.statusCode >= 500 && response.statusCode < 600) {
       mMoPubNativeNetworkListener.onNativeFail(SERVER_ERROR_RESPONSE_CODE);
     } else if (response == null && !DeviceUtils.isNetworkAvailable(mContext.get())) {
       MoPubLog.c(String.valueOf(MoPubErrorCode.NO_CONNECTION.toString()));
       mMoPubNativeNetworkListener.onNativeFail(CONNECTION_ERROR);
     } else {
       mMoPubNativeNetworkListener.onNativeFail(UNSPECIFIED);
     }
   }
 }
 private static boolean checkUiThreadInternal(
     boolean allowThrow, String errorMessageTemplate, Object... errorMessageArgs) {
   // Check that the main looper is the current looper.
   if (Looper.getMainLooper().equals(Looper.myLooper())) {
     return true;
   }
   String errorMessage = format(errorMessageTemplate, errorMessageArgs);
   if (allowThrow) {
     throw new IllegalStateException(errorMessage);
   }
   MoPubLog.e(errorMessage);
   return false;
 }
 @Override
 public void didCompleteRewardedVideo(String location, int reward) {
   super.didCompleteRewardedVideo(location, reward);
   MoPubLog.d(
       "Chartboost rewarded video completed for location "
           + location
           + " with "
           + "reward amount "
           + reward);
   MoPubRewardedVideoManager.onRewardedVideoCompleted(
       ChartboostRewardedVideo.class,
       location,
       MoPubReward.success(MoPubReward.NO_REWARD_LABEL, reward));
 }
 public void handleUrl(
     UrlHandler urlHandler,
     @NonNull final Context context,
     @NonNull final Uri destinationUri,
     final boolean fromUserInteraction)
     throws IntentNotResolvableException {
   MoPubLog.d("Ad event URL: " + destinationUri);
   if (mRequiresUserInteraction && !fromUserInteraction) {
     throw new IntentNotResolvableException(
         "Attempted to handle action without user " + "interaction.");
   } else {
     performAction(context, destinationUri, urlHandler);
   }
 }
 private static boolean checkStateInternal(
     boolean expression,
     boolean allowThrow,
     String errorMessageTemplate,
     Object... errorMessageArgs) {
   if (expression) {
     return true;
   }
   String errorMessage = format(errorMessageTemplate, errorMessageArgs);
   if (allowThrow) {
     throw new IllegalStateException(errorMessage);
   }
   MoPubLog.e(errorMessage);
   return false;
 }
 private static boolean checkNotNullInternal(
     Object reference,
     boolean allowThrow,
     String errorMessageTemplate,
     Object... errorMessageArgs) {
   if (reference != null) {
     return true;
   }
   String errorMessage = format(errorMessageTemplate, errorMessageArgs);
   if (allowThrow) {
     throw new NullPointerException(errorMessage);
   }
   MoPubLog.e(errorMessage);
   return false;
 }
    List getAbsoluteProgressTrackers()
    {
        ArrayList arraylist;
        Object obj;
        Iterator iterator1;
        arraylist = new ArrayList();
        for (Iterator iterator = getVideoTrackersByAttribute("start").iterator(); iterator.hasNext(); arraylist.add(new VastAbsoluteProgressTracker((String)iterator.next(), 2000))) { }
        obj = XmlUtils.getFirstMatchingChildNode(mLinearNode, "TrackingEvents");
        if (obj == null)
        {
            break MISSING_BLOCK_LABEL_263;
        }
        iterator1 = XmlUtils.getMatchingChildNodes(((Node) (obj)), "Tracking", "event", Collections.singletonList("progress")).iterator();
_L2:
        String s;
        Object obj1;
        if (!iterator1.hasNext())
        {
            break; /* Loop/switch isn't completed */
        }
        obj1 = (Node)iterator1.next();
        s = XmlUtils.getAttributeValue(((Node) (obj1)), "offset");
        if (s == null)
        {
            continue; /* Loop/switch isn't completed */
        }
        s = s.trim();
        if (!Strings.isAbsoluteTracker(s))
        {
            continue; /* Loop/switch isn't completed */
        }
        obj1 = XmlUtils.getNodeValue(((Node) (obj1)));
        Integer integer = Strings.parseAbsoluteOffset(s);
        if (integer != null)
        {
            try
            {
                arraylist.add(new VastAbsoluteProgressTracker(((String) (obj1)), integer.intValue()));
            }
            catch (NumberFormatException numberformatexception)
            {
                MoPubLog.d(String.format("Failed to parse VAST progress tracker %s", new Object[] {
                    s
                }));
            }
        }
        if (true) goto _L2; else goto _L1
 final void setStarRating(@Nullable final Double starRating) {
   if (starRating == null) {
     mStarRating = null;
   } else if (starRating >= MIN_STAR_RATING && starRating <= MAX_STAR_RATING) {
     mStarRating = starRating;
   } else {
     MoPubLog.d(
         "Ignoring attempt to set invalid star rating ("
             + starRating
             + "). Must be "
             + "between "
             + MIN_STAR_RATING
             + " and "
             + MAX_STAR_RATING
             + ".");
   }
 }
示例#25
0
  @Deprecated
  @NonNull
  public View getAdView(
      @Nullable final View convertView,
      @Nullable final ViewGroup parent,
      @Nullable final NativeResponse nativeResponse,
      @Nullable final ViewBinder viewBinder,
      @Nullable @SuppressWarnings("unused") final MoPubNativeListener moPubNativeListener) {
    final Activity activity = mActivity.get();
    if (activity == null) {
      MoPubLog.w(
          "Weak reference to Activity Context in"
              + " AdapterHelper became null. Returning empty view.");
      return new View(mApplicationContext);
    }

    return NativeAdViewHelper.getAdView(convertView, parent, activity, nativeResponse, viewBinder);
  }
示例#26
0
  private void loadNativeAd(
      @Nullable final RequestParameters requestParameters, @Nullable final Integer sequenceNumber) {
    final Context context = getContextOrDestroy();
    if (context == null) {
      return;
    }

    final NativeUrlGenerator generator =
        new NativeUrlGenerator(context).withAdUnitId(mAdUnitId).withRequest(requestParameters);

    if (sequenceNumber != null) {
      generator.withSequenceNumber(sequenceNumber);
    }

    final String endpointUrl = generator.generateUrlString(Constants.HOST);

    if (endpointUrl != null) {
      MoPubLog.d("Loading ad from: " + endpointUrl);
    }

    requestNativeAd(endpointUrl);
  }
示例#27
0
 @Deprecated
 protected void adWillLoad(String url) {
   MoPubLog.d("adWillLoad: " + url);
   if (mOnAdWillLoadListener != null) mOnAdWillLoadListener.OnAdWillLoad(this, url);
 }
 @Override
 public void didClickRewardedVideo(String location) {
   super.didClickRewardedVideo(location);
   MoPubRewardedVideoManager.onRewardedVideoClicked(ChartboostRewardedVideo.class, location);
   MoPubLog.d("Chartboost rewarded video clicked for location " + location + ".");
 }
 @Override
 public void didDisplayRewardedVideo(String location) {
   super.didDisplayRewardedVideo(location);
   MoPubLog.d("Chartboost rewarded video displayed for location " + location + ".");
   MoPubRewardedVideoManager.onRewardedVideoStarted(ChartboostRewardedVideo.class, location);
 }
示例#30
0
 protected void trackNativeImpression() {
   MoPubLog.d("Tracking impression for native adapter.");
   if (mAdViewController != null) mAdViewController.trackImpression();
 }