Class DynamicDrawableUtils
java.lang.Object
com.pranavpandey.android.dynamic.util.DynamicDrawableUtils
Helper class to perform
Drawable
operations.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Drawable
colorizeDrawable
(Drawable drawable, boolean wrap, int color) Colorize and return the mutated drawable so that, all other references do not change.static Drawable
colorizeDrawable
(Drawable drawable, boolean wrap, int color, PorterDuff.Mode mode) Colorize and return the mutated drawable so that, all other references do not change.static Drawable
colorizeDrawable
(Drawable drawable, boolean wrap, ColorFilter colorFilter) Apply color filter and return the mutated drawable so that, all other references do not change.static Drawable
colorizeDrawable
(Drawable drawable, int color) Colorize and return the mutated drawable so that, all other references do not change.static Drawable
colorizeDrawable
(Drawable drawable, int color, PorterDuff.Mode mode) Colorize and return the mutated drawable so that, all other references do not change.static Drawable
colorizeDrawable
(Drawable drawable, ColorFilter colorFilter) Apply color filter and return the mutated drawable so that, all other references do not change.static Drawable
getCornerDrawable
(float cornerRadius) Get a gradient drawable according to the corner radius.static Drawable
getCornerDrawable
(float cornerRadius, int color) Get a gradient drawable according to the corner radius.static Drawable
getCornerDrawable
(int width, int height, float cornerRadius) Get a gradient drawable according to the corner radius.static Drawable
getCornerDrawable
(int width, int height, float cornerRadius, int color) Get a gradient drawable according to the corner radius.static Drawable
getCornerDrawable
(int width, int height, GradientDrawable drawable) Get a gradient drawable according to the supplied drawable.static Drawable
getCornerDrawable
(int width, int height, GradientDrawable drawable, int color) Get a gradient drawable according to the supplied drawable.static Drawable
getCornerDrawable
(GradientDrawable drawable) Get a gradient drawable according to the supplied drawable.static Drawable
getCornerDrawable
(GradientDrawable drawable, int color) Get a gradient drawable according to the supplied drawable.static void
setBackground
(View view, Drawable drawable) Set background of a given view in an efficient way by detecting the Android SDK at runtime.
-
Constructor Details
-
DynamicDrawableUtils
public DynamicDrawableUtils()
-
-
Method Details
-
setBackground
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
towrap
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
towrap
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
towrap
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
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
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
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
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
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.
-