com.google.ads
Class AdSize

java.lang.Object
  extended by com.google.ads.AdSize

public class AdSize
extends Object

The different sizes of ads supported.


Field Summary
static int AUTO_HEIGHT
          A flag used to denote that an ad's height will be determined automatically.
static AdSize BANNER
          Size of MMA standard banner ad.
static int FULL_WIDTH
          A flag used to denote that an ad is full-width.
static AdSize IAB_BANNER
          Size of IAB standard full banner ad.
static AdSize IAB_LEADERBOARD
          Size of IAB standard leaderboard ad.
static AdSize IAB_MRECT
          Side of IAB standard medium rectangle ad.
static AdSize IAB_WIDE_SKYSCRAPER
          Size of skyscraper ad.
static int LANDSCAPE_AD_HEIGHT
          Constant for height of ads in landscape mode.
static int LARGE_AD_HEIGHT
          Constant for height of ads on large devices in both orientations.
static int PORTRAIT_AD_HEIGHT
          Constant for height of ads in portrait mode.
static AdSize SMART_BANNER
          A dynamically sized banner that is full-width and auto-height.
 
Constructor Summary
AdSize(int width, int height)
          Constructs a custom AdSize.
 
Method Summary
static AdSize createAdSize(AdSize adSize, Context context)
          DO NOT USE THIS FACTORY.
 boolean equals(Object other)
          Compares two AdSizes.
 AdSize findBestSize(AdSize... options)
          Chained method to find the most appropriate size for this AdSize.
 int getHeight()
          Returns the height of the AdSize.
 int getHeightInPixels(Context context)
          Returns the height of the AdSize in physical pixels.
 int getWidth()
          Returns the width of the AdSize.
 int getWidthInPixels(Context context)
          Returns the width of the AdSize in physical pixels.
 int hashCode()
          Returns an integer hash code for this AdSize.
 boolean isAutoHeight()
          Returns whether AdSize is auto height.
 boolean isCustomAdSize()
          Returns whether AdSize is for a custom-sized ad.
 boolean isFullWidth()
          Returns whether AdSize is full width.
 boolean isSizeAppropriate(int width, int height)
          Reports whether the provided dimensions are appropriate for an ad of the requested size.
 String toString()
          Returns the AdSize as a String.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

FULL_WIDTH

public static final int FULL_WIDTH
A flag used to denote that an ad is full-width. The width is determined by the current width of the device. A full-width ad determines its width during initialization of the AdSize and never changes after that.

For example, new AdSize(AdSize.FULL_WIDTH, AdSize.SMARTPHONE_PORTRAIT_AD_HEIGHT) might become 360x50 dip wide in portrait mode. If the device is rotated to landscape mode and the app handles its own configuration changes (by adding configChanges to the AndroidManifest.xml file), the ad will continue to be 360x50 dip in landscape mode.

If instead, the app tears down and recreates the Activity (the default behavior on Android), the AdSize will be reinitialized and will determine a new width. So in the above example, the ad might become 640x50 dip wide in landscape mode to take up the full-width of the device.

See Also:
Constant Field Values

AUTO_HEIGHT

public static final int AUTO_HEIGHT
A flag used to denote that an ad's height will be determined automatically. The height is determined as a percentage of the maximum height of the device. An auto-height ad determines its height during initialization of the AdSize and never changes after that.

For example, new AdSize(AdSize.FULL_WIDTH, AdSize.AUTO_HEIGHT) might become 360x50 dip wide in portrait mode on a 720x1280 pixel screen with a density of 2.0. If the device is rotated to landscape mode and the app handles its own configuration changes (by adding configChanges to the AndroidManifest.xml file), the ad will continue to be 360x50 dip in landscape mode.

If instead, the app tears down and recreates the Activity (the default behavior on Android), the AdSize will be reinitialized and will determine a new height (and width due to FULL_WIDTH). So in the above example, the ad might become 640x32 dip wide in landscape mode to take up the full-width of the device and less height.

On a screen 400 dip tall or less, the ad will be 32 dip tall. On a screen 720 dip tall or less, the ad will be 50 dip tall. Otherwise, it will be 90 dip tall. As a result, most phones will be 32 dip tall in landscape and 50 dip tall in portrait. Most tablets will be 90 dip tall in both orientations.

See Also:
Constant Field Values

LANDSCAPE_AD_HEIGHT

public static final int LANDSCAPE_AD_HEIGHT
Constant for height of ads in landscape mode. This is for smaller devices like phones and is only intended to be used if you explicitly want to specify an ad height. Most developers should prefer to use SMART_BANNER.

See Also:
Constant Field Values

PORTRAIT_AD_HEIGHT

public static final int PORTRAIT_AD_HEIGHT
Constant for height of ads in portrait mode. This is for smaller devices like phones and is only intended to be used if you explicitly want to specify an ad height. Most developers should prefer to use SMART_BANNER.

See Also:
Constant Field Values

LARGE_AD_HEIGHT

public static final int LARGE_AD_HEIGHT
Constant for height of ads on large devices in both orientations. This is for larger devices like tablets and is only intended to be used if you explicitly want to specify an ad height. Most developers should prefer to use SMART_BANNER.

See Also:
Constant Field Values

SMART_BANNER

public static final AdSize SMART_BANNER
A dynamically sized banner that is full-width and auto-height. See the documentation for FULL_WIDTH and AUTO_HEIGHT for more details regarding the algorithms used to generate this AdSize.


BANNER

public static final AdSize BANNER
Size of MMA standard banner ad.


IAB_MRECT

public static final AdSize IAB_MRECT
Side of IAB standard medium rectangle ad.


IAB_BANNER

public static final AdSize IAB_BANNER
Size of IAB standard full banner ad.


IAB_LEADERBOARD

public static final AdSize IAB_LEADERBOARD
Size of IAB standard leaderboard ad.


IAB_WIDE_SKYSCRAPER

public static final AdSize IAB_WIDE_SKYSCRAPER
Size of skyscraper ad. Currently, not supported by the Google-AdMob network. Only supported for mediation ad requests.

Constructor Detail

AdSize

public AdSize(int width,
              int height)
Constructs a custom AdSize. WARNING: Be cautious using this constructor because it may affect your fill rate. Consider using one of the predefined AdSize constants instead.

Parameters:
width - the width of the AdSize in density-independent pixels.
height - the height of the AdSize in density-independent pixels.
Method Detail

createAdSize

public static AdSize createAdSize(AdSize adSize,
                                  Context context)
DO NOT USE THIS FACTORY. USE THE AdSize CONSTRUCTOR. Factory for AdSize. For normal sized ads, we return an ad with the same properties as the original. For smart sized ads, we return an ad based on the application's context. If a context is not included, or is null, we return to using a 320x50 sized ad.

Parameters:
adSize - the AdSize object from which to copy attributes.
context - the context of the AdSize.

equals

public boolean equals(Object other)
Compares two AdSizes.

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns an integer hash code for this AdSize.

Overrides:
hashCode in class Object

getWidth

public int getWidth()
Returns the width of the AdSize.


getHeight

public int getHeight()
Returns the height of the AdSize.


isFullWidth

public boolean isFullWidth()
Returns whether AdSize is full width.

Returns:
whether AdSize is full width.

isAutoHeight

public boolean isAutoHeight()
Returns whether AdSize is auto height.

Returns:
whether AdSize is auto height.

isCustomAdSize

public boolean isCustomAdSize()
Returns whether AdSize is for a custom-sized ad.

Returns:
whether ad is for custom sizes.

toString

public String toString()
Returns the AdSize as a String.

Overrides:
toString in class Object

getWidthInPixels

public int getWidthInPixels(Context context)
Returns the width of the AdSize in physical pixels.


getHeightInPixels

public int getHeightInPixels(Context context)
Returns the height of the AdSize in physical pixels.


isSizeAppropriate

public boolean isSizeAppropriate(int width,
                                 int height)
Reports whether the provided dimensions are appropriate for an ad of the requested size. This is meant for use by mediation adapters.

Parameters:
width - Width of the space to check.
height - Height of the space to check.
Returns:
true if the given size is appropriate, false otherwise.

findBestSize

public AdSize findBestSize(AdSize... options)
Chained method to find the most appropriate size for this AdSize. This is meant for use by mediation adapters.

Usage:

 MySize m = adSize.findBestSize(
     new AdSize.SizeOption(100, 20, MySize.MiniBanner),
     new AdSize.SizeOption(320, 45, MySize.Banner),
     new AdSize.SizeOption(480, 100, MySize.HugeBanner));
 

Parameters:
options - AdSize instances defining ad size representations and the object that represents them.
Returns:
Best fit value or null if no sizes are appropriate.