Пример #1
0
 public void onAdFetchFailure() {
   Log.d("MoPub", "AdSense failed. Trying another");
   MoPubView view = mMoPubViewReference.get();
   if (view != null) {
     view.loadFailUrl();
   }
 }
Пример #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();
  }
  @Override
  public void onBannerFailed(MoPubErrorCode errorCode) {
    if (isInvalidated()) return;

    if (mMoPubView != null) {
      if (errorCode == null) {
        errorCode = UNSPECIFIED;
      }
      cancelTimeout();
      mMoPubView.loadFailUrl(errorCode);
    }
  }
Пример #4
0
    public void execute() {
      AdView adView = mWeakAdView.get();
      if (adView == null || adView.isDestroyed()) {
        return;
      }

      adView.setIsLoading(false);
      MoPubView mpv = adView.mMoPubView;

      if (mHeader == null) {
        Log.i("MoPub", "Couldn't call custom method because the server did not specify one.");
        mpv.loadFailUrl();
        return;
      }

      String methodName = mHeader.getValue();
      Log.i("MoPub", "Trying to call method named " + methodName);

      Class<? extends Activity> c;
      Method method;
      Activity userActivity = mpv.getActivity();
      try {
        c = userActivity.getClass();
        method = c.getMethod(methodName, MoPubView.class);
        method.invoke(userActivity, mpv);
      } catch (NoSuchMethodException e) {
        Log.d(
            "MoPub",
            "Couldn't perform custom method named "
                + methodName
                + "(MoPubView view) because your activity class has no such method");
        mpv.loadFailUrl();
        return;
      } catch (Exception e) {
        Log.d("MoPub", "Couldn't perform custom method named " + methodName);
        mpv.loadFailUrl();
        return;
      }
    }
Пример #5
0
  public void loadAdSense(String params) {
    try {
      Class.forName("com.google.ads.GoogleAdView");
    } catch (ClassNotFoundException e) {
      Log.d("MoPub", "Couldn't find AdSense SDK. Trying next ad...");
      loadFailUrl();
      return;
    }

    try {
      Class<?> adapterClass = (Class<?>) Class.forName("com.mopub.mobileads.AdSenseAdapter");

      Class<?>[] parameterTypes = new Class[2];
      parameterTypes[0] = MoPubView.class;
      parameterTypes[1] = String.class;

      Constructor<?> constructor = adapterClass.getConstructor(parameterTypes);

      Object[] args = new Object[2];
      args[0] = this;
      args[1] = params;

      mAdSenseAdapter = constructor.newInstance(args);

      Method loadAdMethod = adapterClass.getMethod("loadAd", (Class[]) null);
      loadAdMethod.invoke(mAdSenseAdapter, (Object[]) null);
    } catch (ClassNotFoundException e) {
      Log.d("MoPub", "Couldn't find AdSenseAdapter class.  Trying next ad...");
      loadFailUrl();
      return;
    } catch (Exception e) {
      Log.d("MoPub", "Couldn't create AdSenseAdapter class.  Trying next ad...");
      loadFailUrl();
      return;
    }
  }
Пример #6
0
  protected void loadNativeSDK(HashMap<String, String> paramsHash) {
    if (mAdapter != null) mAdapter.invalidate();

    String type = paramsHash.get("X-Adtype");
    mAdapter = BaseAdapter.getAdapterForType(type);

    if (mAdapter != null) {
      Log.i("MoPub", "Loading native adapter for type: " + type);
      String jsonParams = paramsHash.get("X-Nativeparams");
      mAdapter.init(this, jsonParams);
      mAdapter.loadAd();
    } else {
      Log.i("MoPub", "Couldn't load native adapter. Trying next ad...");
      loadFailUrl();
    }
  }
  public CustomEventBannerAdapter(MoPubView moPubView, String className, String classData) {
    mHandler = new Handler();
    mMoPubView = moPubView;
    mContext = moPubView.getContext();
    mLocalExtras = new HashMap<String, Object>();
    mServerExtras = new HashMap<String, String>();
    mTimeout =
        new Runnable() {
          @Override
          public void run() {
            Log.d("MoPub", "Third-party network timed out.");
            onBannerFailed(NETWORK_TIMEOUT);
            invalidate();
          }
        };

    Log.d("MoPub", "Attempting to invoke custom event: " + className);
    try {
      mCustomEventBanner = CustomEventBannerFactory.create(className);
    } catch (Exception exception) {
      Log.d("MoPub", "Couldn't locate or instantiate custom event: " + className + ".");
      mMoPubView.loadFailUrl(ADAPTER_NOT_FOUND);
      return;
    }

    // Attempt to load the JSON extras into mServerExtras.
    try {
      mServerExtras = Json.jsonStringToMap(classData);
    } catch (Exception exception) {
      Log.d("MoPub", "Failed to create Map from JSON: " + classData + exception.toString());
    }

    mLocalExtras = mMoPubView.getLocalExtras();
    if (mMoPubView.getLocation() != null) {
      mLocalExtras.put("location", mMoPubView.getLocation());
    }
    if (mMoPubView.getAdViewController() != null) {
      mLocalExtras.put(AD_CONFIGURATION_KEY, mMoPubView.getAdViewController().getAdConfiguration());
    }
  }