Android Open Source - AdFlake-Client-Android Ad Flake Util






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

/**
 * AdFlakeUtil.java (AdFlakeSDK-Android)
 */*from  w w w  .  j  a  v  a 2 s  .  c om*/
 * 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 AdFlakeUtil.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.util;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.util.DisplayMetrics;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;

/**
 * The AdFlakeUtil class provides common methods and values used by the AdFlake
 * SDK.
 */
public class AdFlakeUtil
{
  public static final String  urlConfig          = "http://api.adflake.com/get?appid=%s&appver=%d&client=2";
  public static final String  urlImpression        = "http://metrics.adflake.com/impression?appid=%s&nid=%s&type=%d&uuid=%s&country_code=%s&appver=%d&client=2";
  public static final String  urlClick          = "http://metrics.adflake.com/click?appid=%s&nid=%s&type=%d&uuid=%s&country_code=%s&appver=%d&client=2";
  public static final String  urlCustom          = "http://api.adflake.com/custom?appid=%s&nid=%s&uuid=%s&country_code=%s%s&appver=%d&client=2";

  public static final String  locationString        = "&location=%f,%f&location_timestamp=%d";

  // Don't change anything below this line
  /***********************************************/

  public static final int    BANNER_DEFAULT_HEIGHT    = 50;
  public static final int    BANNER_DEFAULT_WIDTH    = 320;

  public static final int    VERSION            = 400;

  public static final String  ADFLAKE            = "AdFlake SDK";

  public static final int    NETWORK_TYPE_ADMOB      = 1;
  public static final int    NETWORK_TYPE_JUMPTAP    = 2;
  public static final int    NETWORK_TYPE_VIDEOEGG    = 3;
  public static final int    NETWORK_TYPE_MEDIALETS    = 4;
  public static final int    NETWORK_TYPE_LIVERAIL    = 5;
  public static final int    NETWORK_TYPE_MILLENNIAL    = 6;
  public static final int    NETWORK_TYPE_GREYSTRIP    = 7;
  public static final int    NETWORK_TYPE_QUATTRO    = 8;
  public static final int    NETWORK_TYPE_CUSTOM      = 9;
  public static final int    NETWORK_TYPE_ADFLAKE    = 10;
  public static final int    NETWORK_TYPE_MOBCLIX    = 11;
  public static final int    NETWORK_TYPE_MDOTM      = 12;
  public static final int    NETWORK_TYPE_4THSCREEN    = 13;
  public static final int    NETWORK_TYPE_ADSENSE    = 14;
  public static final int    NETWORK_TYPE_DOUBLECLICK  = 15;
  public static final int    NETWORK_TYPE_GENERIC    = 16;
  public static final int    NETWORK_TYPE_EVENT      = 17;
  public static final int    NETWORK_TYPE_INMOBI      = 18;
  public static final int    NETWORK_TYPE_KOMLIMOBILE  = 20;
  public static final int    NETWORK_TYPE_ONERIOT    = 23;
  public static final int    NETWORK_TYPE_NEXAGE      = 24;
  public static final int    NETWORK_TYPE_AMAZONADS    = 25;
  public static final int    NETWORK_TYPE_LEADBOLT    = 26;
  public static final int    NETWORK_TYPE_MOBFOX      = 27;
  public static final int    NETWORK_TYPE_MOJIVA      = 28;
  public static final int    NETWORK_TYPE_HUNTMOBILE    = 29;
  public static final int    NETWORK_TYPE_TODACELL    = 30;
  public static final int    NETWORK_TYPE_APPBRAIN    = 31;
  public static final int    NETWORK_TYPE_ADCOLONY    = 32;
  public static final int    NETWORK_TYPE_ADMOB_VIDEO  = 33;
  public static final int    NETWORK_TYPE_BEACHFRONT    = 34;

  public static final int    CUSTOM_TYPE_BANNER      = 1;
  public static final int    CUSTOM_TYPE_ICON      = 2;

  private static double    density            = -1;

  /**
   * Convert to hex.
   * 
   * @param data
   *            the data
   * @return the string
   */
  public static String convertToHex(byte[] data)
  {
    StringBuffer buf = new StringBuffer();
    for (byte element : data)
    {
      int halfbyte = (element >>> 4) & 0x0F;
      int two_halfs = 0;
      do
      {
        if ((0 <= halfbyte) && (halfbyte <= 9))
        {
          buf.append((char) ('0' + halfbyte));
        }
        else
        {
          buf.append((char) ('a' + (halfbyte - 10)));
        }
        halfbyte = element & 0x0F;
      } while (two_halfs++ < 1);
    }
    return buf.toString();
  }

  /**
   * Gets the screen density for the device.
   * 
   * @param activity
   *            is the current activity.
   * @return A double value representing the device's screen density.
   */
  public static double getDensity(Activity activity)
  {
    if (density == -1)
    {
      DisplayMetrics displayMetrics = new DisplayMetrics();
      activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
      density = displayMetrics.density;
    }

    return density;
  }

  /**
   * Converts device independent pixels to screen pixels.
   * 
   * @param dipPixels
   *            is the amount of device independent pixels.
   * @param density
   *            is the device's screen density.
   * @return An integer representing the value in screen pixels.
   */
  public static int convertToScreenPixels(int dipPixels, double density)
  {
    return (int) convertToScreenPixels((double) dipPixels, density);
  }

  /**
   * Converts device independent pixels to screen pixels.
   * 
   * @param dipPixels
   *            is the amount of device independent pixels.
   * @param density
   *            is the device's screen density.
   * @return A double representing the value in screen pixels.
   */
  public static double convertToScreenPixels(double dipPixels, double density)
  {
    return (density > 0) ? (dipPixels * density) : dipPixels;
  }

  /**
   * Gets the md5 hashed and upper-cased device id.
   * 
   * @param context
   *            the application context.
   * @return The encoded device id.
   */
  public static String getEncodedDeviceId(Context context)
  {
    String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

    String hashedId;
    if ((androidId == null) || isEmulator())
    {
      hashedId = md5("emulator");
    }
    else
    {
      hashedId = md5(androidId);
    }

    if (hashedId == null)
    {
      return null;
    }

    return hashedId.toUpperCase(Locale.US);
  }

  /**
   * Method for returning an md5 hash of a string.
   * 
   * @param val
   *            the string to hash.
   * @return A hex string representing the md5 hash of the input.
   */
  private static String md5(String val)
  {
    String result = null;

    if ((val != null) && (val.length() > 0))
    {
      try
      {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(val.getBytes(), 0, val.length());
        result = String.format("%032X", new BigInteger(1, md5.digest()));
      }
      catch (NoSuchAlgorithmException nsae)
      {
        result = val.substring(0, 32);
      }
    }

    return result;
  }

  /**
   * Checks whether or not the running device is an emulator.
   * 
   * @return Boolean indicating if the app is currently running in an
   *         emulator.
   */
  public static boolean isEmulator()
  {
    return (Build.BOARD.equals("unknown") && Build.DEVICE.equals("generic") && Build.BRAND.equals("generic"));
  }
}




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