Exemplo n.º 1
0
    public void execute() {
      AdView adView = mWeakAdView.get();
      if (adView == null || adView.isDestroyed()) {
        return;
      }

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

      if (mParamsMap == null) {
        Log.i("MoPub", "Couldn't invoke custom event because the server did not specify one.");
        moPubView.adFailed();
        return;
      }

      moPubView.loadCustomEvent(mParamsMap);
    }
Exemplo n.º 2
0
  public void loadAd() {
    MoPubView view = mMoPubViewReference.get();
    if (view == null) {
      return;
    }

    mAdView = new GoogleAdView(view.getContext());

    // The following parameters are required.  Fail if they aren't set
    JSONObject object;
    String pubId;
    String companyName;
    String appName;
    try {
      object = (JSONObject) new JSONTokener(mParams).nextValue();
      pubId = object.getString("Gclientid");
      companyName = object.getString("Gcompanyname");
      appName = object.getString("Gappname");
    } catch (JSONException e) {
      view.adFailed();
      return;
    }

    // The rest of the parameters are optional
    AdSenseSpec.AdType adtype = AdType.TEXT_IMAGE;
    Boolean testState = false;
    String keywords = "";
    String channelId = "";
    try {
      String at = object.getString("Gadtype");
      if (at.equals("GADAdSenseTextAdType")) {
        adtype = AdType.TEXT;
      } else if (at.equals("GADAdSenseImageAdType")) {
        adtype = AdType.IMAGE;
      }
    } catch (JSONException e) {
    }
    try {
      testState = object.getString("Gtestadrequest").equals("1");
    } catch (JSONException e) {
    }
    try {
      keywords = object.getString("Gkeywords");
    } catch (JSONException e) {
    }
    try {
      channelId = object.getString("Gchannelids");
    } catch (JSONException e) {
    }

    if (keywords == null || keywords.equals("")) {
      keywords = "None";
    }

    AdSenseSpec adSenseSpec =
        new AdSenseSpec(pubId) // Specify client ID. (Required)
            .setCompanyName(companyName) // Set company name. (Required)
            .setAppName(appName) // Set application name. (Required)
            .setKeywords(keywords) // Specify keywords.
            .setChannel(channelId) // Set channel ID.
            .setAdType(adtype) // Set ad type to Text.
            // .setExpandDirection(AdSenseSpec.ExpandDirection.TOP)
            .setAdTestEnabled(testState); // Keep

    if (view.getAdWidth() == 300 && view.getAdHeight() == 250) {
      adSenseSpec.setAdFormat(AdFormat.FORMAT_300x250);
    } else {
      adSenseSpec.setAdFormat(AdFormat.FORMAT_320x50);
    }

    mAdView.setAdViewListener(this);
    Log.d("MoPub", "Showing AdSense ad...");

    // The GoogleAdView has to be in the view hierarchy to make a request
    mAdView.setVisibility(View.INVISIBLE);
    view.addView(
        mAdView,
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));

    mAdView.showAds(adSenseSpec);
  }
Exemplo n.º 3
0
 private void adDidFail() {
   Log.i("MoPub", "Ad failed to load.");
   mIsLoading = false;
   scheduleRefreshTimerIfEnabled();
   mMoPubView.adFailed();
 }