Class DynamicAdUtils

java.lang.Object
com.pranavpandey.android.dynamic.ads.util.DynamicAdUtils

public class DynamicAdUtils extends Object
Helper class to perform ads related operations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
    Factor to calculate the acceptable ad size.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.google.android.gms.ads.AdSize
    getAdSize(Context activity)
    Returns the ad size for the supplied activity.
    static com.google.android.gms.ads.AdSize
    getAdSize(Context activity, View container)
    Returns the ad size for the supplied activity and container.
    static int
    Returns the orientation for the app open ad.
    static boolean
    isOnlyStore(com.google.android.gms.ads.nativead.NativeAd nativeAd)
    Checks whether the ad has only the store data.
    static void
    set(ImageView imageView, Drawable drawable)
    Set drawable for the image view and manage its visibility according to the data.
    static void
    set(RatingBar ratingBar, float rating)
    Set rating value for the rating bar.
    static void
    set(TextView textView, CharSequence text)
    Set text for the text view and manage its visibility according to the data.
    static void
    setEnabled(View view, boolean enabled)
    Set a view enabled or disabled.
    static void
    setVisibility(View view, int visibility)
    Set visibility for the view.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • AD_SIZE_FACTOR

      public static final float AD_SIZE_FACTOR
      Factor to calculate the acceptable ad size.
      See Also:
  • Constructor Details

    • DynamicAdUtils

      public DynamicAdUtils()
  • Method Details

    • getAdSize

      @NonNull public static com.google.android.gms.ads.AdSize getAdSize(@Nullable Context activity, @Nullable View container)
      Returns the ad size for the supplied activity and container.
      Parameters:
      activity - The activity to calculate the ad size.
      container - The ad container to be used.
      Returns:
      The ad size for the supplied activity and container.
      See Also:
      • AdSize.FLUID
    • getAdSize

      @NonNull public static com.google.android.gms.ads.AdSize getAdSize(@Nullable Context activity)
      Returns the ad size for the supplied activity.
      Parameters:
      activity - The activity to calculate the ad size.
      Returns:
      The ad size for the supplied activity.
      See Also:
    • getAppOpenAdOrientation

      public static int getAppOpenAdOrientation(@Nullable Context activity)
      Returns the orientation for the app open ad.
      Parameters:
      activity - The activity to retrieve the screen orientation.
      Returns:
      The orientation for the app open ad.
      See Also:
      • AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT
      • AppOpenAd.APP_OPEN_AD_ORIENTATION_LANDSCAPE
    • isOnlyStore

      public static boolean isOnlyStore(@Nullable com.google.android.gms.ads.nativead.NativeAd nativeAd)
      Checks whether the ad has only the store data.
      Parameters:
      nativeAd - The ad to be checked.
      Returns:
      true if the ad has only the store data.
    • set

      public static void set(@Nullable ImageView imageView, @Nullable Drawable drawable)
      Set drawable for the image view and manage its visibility according to the data.
      Parameters:
      imageView - The image view to set the drawable.
      drawable - The drawable to be set.
    • set

      public static void set(@Nullable TextView textView, @Nullable CharSequence text)
      Set text for the text view and manage its visibility according to the data.
      Parameters:
      textView - The text view to set the text.
      text - The text to be set.
    • set

      public static void set(@Nullable RatingBar ratingBar, float rating)
      Set rating value for the rating bar.
      Parameters:
      ratingBar - The rating bar to set the rating.
      rating - The rating value to be set.
    • setVisibility

      public static void setVisibility(@Nullable View view, int visibility)
      Set visibility for the view.
      Parameters:
      view - The view to set the visibility.
      visibility - The visibility to be set.
    • setEnabled

      public static void setEnabled(@Nullable View view, boolean enabled)
      Set a view enabled or disabled.
      Parameters:
      view - The view to be enabled or disabled.
      enabled - true to enable the view.