Class DynamicDrawableUtils

java.lang.Object
com.pranavpandey.android.dynamic.util.DynamicDrawableUtils

public class DynamicDrawableUtils extends Object
Helper class to perform Drawable operations.
  • Constructor Details

    • DynamicDrawableUtils

      public DynamicDrawableUtils()
  • Method Details

    • setBackground

      public static void setBackground(@Nullable View view, @Nullable Drawable drawable)
      Set background of a given view in an efficient way by detecting the Android SDK at runtime.
      Parameters:
      view - The view to set the background.
      drawable - The background drawable to be set.
      See Also:
    • colorizeDrawable

      @Nullable public static Drawable colorizeDrawable(@Nullable Drawable drawable, boolean wrap, @NonNull ColorFilter colorFilter)
      Apply color filter and return the mutated drawable so that, all other references do not change.
      Parameters:
      drawable - The drawable to be colorized.
      wrap - true to wrap the drawable so that it may be used for tinting across the different API levels.
      colorFilter - The color filter to be applied on the drawable.
      Returns:
      The drawable after applying the color filter.
      See Also:
    • colorizeDrawable

      @Nullable public static Drawable colorizeDrawable(@Nullable Drawable drawable, boolean wrap, @ColorInt int color, @Nullable PorterDuff.Mode mode)
      Colorize and return the mutated drawable so that, all other references do not change.
      Parameters:
      drawable - The drawable to be colorized.
      color - The color to colorize the drawable.
      wrap - true to wrap the drawable so that it may be used for tinting across the different API levels.
      mode - The porter duff mode to be used.
      Returns:
      The drawable after applying the color filter.
      See Also:
    • colorizeDrawable

      @Nullable public static Drawable colorizeDrawable(@Nullable Drawable drawable, @ColorInt int color, @Nullable PorterDuff.Mode mode)
      Colorize and return the mutated drawable so that, all other references do not change.
      Parameters:
      drawable - The drawable to be colorized.
      color - The color to colorize the drawable.
      mode - The porter duff mode to be used.
      Returns:
      The drawable after applying the color filter.
      See Also:
    • colorizeDrawable

      @Nullable public static Drawable colorizeDrawable(@Nullable Drawable drawable, boolean wrap, @ColorInt int color)
      Colorize and return the mutated drawable so that, all other references do not change.
      Parameters:
      drawable - The drawable to be colorized.
      wrap - true to wrap the drawable so that it may be used for tinting across the different API levels.
      color - The color to colorize the drawable.
      Returns:
      The drawable after applying the color filter.
      See Also:
    • colorizeDrawable

      @Nullable public static Drawable colorizeDrawable(@Nullable Drawable drawable, @ColorInt int color)
      Colorize and return the mutated drawable so that, all other references do not change.
      Parameters:
      drawable - The drawable to be colorized.
      color - The color to colorize the drawable.
      Returns:
      The drawable after applying the color filter.
    • colorizeDrawable

      @Nullable public static Drawable colorizeDrawable(@Nullable Drawable drawable, @NonNull ColorFilter colorFilter)
      Apply color filter and return the mutated drawable so that, all other references do not change.
      Parameters:
      drawable - The drawable to be colorized.
      colorFilter - The color filter to be applied on the drawable.
      Returns:
      The drawable after applying the color filter.
      See Also:
    • getCornerDrawable

      @NonNull public static Drawable getCornerDrawable(int width, int height, @NonNull GradientDrawable drawable, @ColorInt int color)
      Get a gradient drawable according to the supplied drawable.
      Parameters:
      width - The width in dip for the drawable.
      height - The height in dip for the drawable.
      drawable - The drawable drawable to create the gradient drawable.
      color - The color for the drawable.
      Returns:
      The gradient drawable according to the supplied parameters.
    • getCornerDrawable

      @NonNull public static Drawable getCornerDrawable(int width, int height, @NonNull GradientDrawable drawable)
      Get a gradient drawable according to the supplied drawable.
      Parameters:
      width - The width in dip for the drawable.
      height - The height in dip for the drawable.
      drawable - The drawable drawable to create the gradient drawable.
      Returns:
      The gradient drawable according to the supplied parameters.
    • getCornerDrawable

      @NonNull public static Drawable getCornerDrawable(@NonNull GradientDrawable drawable, @ColorInt int color)
      Get a gradient drawable according to the supplied drawable.
      Parameters:
      drawable - The drawable drawable to create the gradient drawable.
      color - The color for the drawable.
      Returns:
      The gradient drawable according to the supplied parameters.
    • getCornerDrawable

      @NonNull public static Drawable getCornerDrawable(@NonNull GradientDrawable drawable)
      Get a gradient drawable according to the supplied drawable.
      Parameters:
      drawable - The drawable drawable to create the gradient drawable.
      Returns:
      The gradient drawable according to the supplied parameters.
    • getCornerDrawable

      @NonNull public static Drawable getCornerDrawable(int width, int height, float cornerRadius, @ColorInt int color)
      Get a gradient drawable according to the corner radius.
      Parameters:
      width - The width in dip for the drawable.
      height - The height in dip for the drawable.
      cornerRadius - The corner size in dip for the drawable.
      color - The color for the drawable.
      Returns:
      The gradient drawable according to the supplied parameters.
    • getCornerDrawable

      @NonNull public static Drawable getCornerDrawable(int width, int height, float cornerRadius)
      Get a gradient drawable according to the corner radius.
      Parameters:
      width - The width in dip for the drawable.
      height - The height in dip for the drawable.
      cornerRadius - The corner size in dip for the drawable.
      Returns:
      The gradient drawable according to the supplied parameters.
    • getCornerDrawable

      @NonNull public static Drawable getCornerDrawable(float cornerRadius, @ColorInt int color)
      Get a gradient drawable according to the corner radius.
      Parameters:
      cornerRadius - The corner size in dip for the drawable.
      color - The color for the drawable.
      Returns:
      The gradient drawable according to the supplied parameters.
    • getCornerDrawable

      @NonNull public static Drawable getCornerDrawable(float cornerRadius)
      Get a gradient drawable according to the corner radius.
      Parameters:
      cornerRadius - The corner size in dip for the drawable.
      Returns:
      The gradient drawable according to the supplied parameters.