Android Open Source - AdFlake-Client-Android Todacell Adapter






From Project

Back to project page AdFlake-Client-Android.

License

The source code is released under:

Apache License

If you think the Android project AdFlake-Client-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * TodacellAdapter.java (AdFlakeSDK-Android)
 */* w w w.j  av  a  2  s .  c o  m*/
 * Copyright ? 2013 MADE GmbH - All Rights Reserved.
 *
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * unless otherwise noted in the License section of this document header.
 *
 * @file TodacellAdapter.java
 * @copyright 2013 MADE GmbH. All rights reserved.
 * @section License
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.adflake.adapters;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.StrictMode;
import android.webkit.WebView;
import android.widget.RelativeLayout;

import com.adflake.AdFlakeLayout;
import com.adflake.AdFlakeTargeting;
import com.adflake.obj.Ration;
import com.adflake.util.AdFlakeUtil;
import com.todacell.TodacellBannerView;

/**
 * The Class TodacellAdapter.
 */
public class TodacellAdapter extends AdFlakeAdapter
{
  private TodacellBannerView  _todacellBannerView;

  /**
   * Instantiates a new todacell adapter.
   * 
   * @param adFlakeLayout
   *            the ad flake layout
   * @param ration
   *            the ration
   */
  public TodacellAdapter(AdFlakeLayout adFlakeLayout, Ration ration)
  {
    super(adFlakeLayout, ration);
  }

  /*
   * (non-Javadoc)
   * @see com.adflake.adapters.AdFlakeAdapter#handle()
   */
  @Override
  public void handle()
  {
    AdFlakeLayout adFlakeLayout = _adFlakeLayoutReference.get();
    if (adFlakeLayout == null)
      return;

    String publisherID = _ration.key;

    if (AdFlakeTargeting.getTestMode() == true)
      publisherID = "0";

    WebView webView = new WebView(adFlakeLayout.getContext());
    webView.setLayoutParams(new RelativeLayout.LayoutParams(0, 0));
    RelativeLayout relativeLayout = new RelativeLayout(adFlakeLayout.getContext());
    relativeLayout.setLayoutParams(adFlakeLayout.getOptimalRelativeLayoutParams());
    relativeLayout.addView(webView);

    final int width = AdFlakeUtil.BANNER_DEFAULT_WIDTH;
    final int height = AdFlakeUtil.BANNER_DEFAULT_HEIGHT;
    final int x = 0, y = 0;

    // NOTE: we're sorry for having to do this, there is a critical bug in
    // the Todacell SDK. Basically they're doing network IO on the main
    // thread which causes an exception to be thrown. So we fix that by
    // allowing network IO on the main thread.
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD)
    {
      disableStrictNetworkPolicy();
    }

    _todacellBannerView = new TodacellBannerView(relativeLayout, webView, publisherID, 99999, width, height, x, y);
    _todacellBannerView.start();

    // NOTE: another limitation in the Todacell SDK. There is no listener
    // that we can use to display the ad so we always have to assume that we
    // were able to receive an ad.
    adFlakeLayout.adapterDidReceiveAd(this, relativeLayout);
  }

  /**
   * Disable strict network policy for devices running gingerbread or later.
   * 
   * @remarks We have to do this due to a bug in the Todacell SDK. They're
   *          actually doing network IO on the mainthread.
   */
  @TargetApi(Build.VERSION_CODES.GINGERBREAD)
  private void disableStrictNetworkPolicy()
  {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
  }

  /*
   * (non-Javadoc)
   * @see com.adflake.adapters.AdFlakeAdapter#willDestroy()
   */
  @Override
  public void willDestroy()
  {
    if (_todacellBannerView != null)
    {
      if (_todacellBannerView.isRunning())
        _todacellBannerView.stop();
      _todacellBannerView = null;
    }
    super.willDestroy();
  }

}




Java Source Code List

com.adflake.AdFlakeLayout.java
com.adflake.AdFlakeManager.java
com.adflake.AdFlakeTargeting.java
com.adflake.adapters.AdColonyVideoAdsAdapter.java
com.adflake.adapters.AdFlakeAdapter.java
com.adflake.adapters.AmazonAdsAdapter.java
com.adflake.adapters.AppBrainAppLiftAdapter.java
com.adflake.adapters.BeachfrontVideoAdsAdapter.java
com.adflake.adapters.CustomAdapter.java
com.adflake.adapters.EventAdapter.java
com.adflake.adapters.GenericAdapter.java
com.adflake.adapters.GoogleAdMobAdsAdapter.java
com.adflake.adapters.GoogleAdMobVideoAdsAdapter.java
com.adflake.adapters.GreystripeAdapter.java
com.adflake.adapters.InMobiAdapter.java
com.adflake.adapters.JumptapAdapter.java
com.adflake.adapters.KomliMobileAdAdapter.java
com.adflake.adapters.LeadBoltAdapter.java
com.adflake.adapters.MdotMAdapter.java
com.adflake.adapters.MillennialAdapter.java
com.adflake.adapters.MobClixAdapter.java
com.adflake.adapters.MobFoxAdapter.java
com.adflake.adapters.TodacellAdapter.java
com.adflake.obj.Custom.java
com.adflake.obj.Extra.java
com.adflake.obj.Ration.java
com.adflake.sampleapp.SampleActivity.java
com.adflake.util.AdFlakeUtil.java