Package 

Class ResourceUtil


  • 
    public class ResourceUtil
    
                        

    A Utility for handling the changes in the Android Resources API and the support Drawables to correctly retrieve tinted Drawables

    • Method Summary

      Modifier and Type Method Description
      static Drawable tint(Context context, int drawableRes, int colorRes) Retrieves the drawable specified with the drawableRes using the colorRes to correctly tint it before returning the Drawable object.
      static Drawable tint(Context context, Drawable drawable, int colorRes) Retrieves the drawable specified with the drawable using the colorRes to correctly tint it before returning the Drawable object.
      static Drawable tintList(Context context, int drawableRes, int tintListRes) Retrieves the drawable specified with the drawableRes using the tintListRes to correctly tint it before returning the Drawable object.
      static Drawable tintList(Context context, Drawable drawable, int tintListRes) Retrieves the drawable specified with the drawable using the tintListRes to correctly tint it before returning the Drawable object.
      static Drawable getDrawable(Context context, int drawableResourceId) Retrieves the drawable specified with the resourceId.
      static int getResolvedResourceId(Context context, int attr) Resolves the reference to an attribute, returning the root resource id.
      static int getColor(Context context, int colorRes) Retrieves the color specified with the colorRes.
      static ColorStateList getColorStateList(Context context, int colorRes) Retrieves the ColorStateList specified with the colorRes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • tint

         static Drawable tint(Context context, int drawableRes, int colorRes)

        Retrieves the drawable specified with the drawableRes using the colorRes to correctly tint it before returning the Drawable object.

        Parameters:
        context - The context to use for retrieving the drawable
        drawableRes - The resource id for the drawable to retrieve
        colorRes - The resource id for the color to use for tinting
      • tint

         static Drawable tint(Context context, Drawable drawable, int colorRes)

        Retrieves the drawable specified with the drawable using the colorRes to correctly tint it before returning the Drawable object.

        Parameters:
        context - The context to use for retrieving the drawable
        drawable - The Drawable to tint
        colorRes - The resource id for the color to use for tinting
      • tintList

         static Drawable tintList(Context context, int drawableRes, int tintListRes)

        Retrieves the drawable specified with the drawableRes using the tintListRes to correctly tint it before returning the Drawable object.

        Parameters:
        context - The context to use for retrieving the drawable
        drawableRes - The resource id for the drawable to retrieve
        tintListRes - The resource id for the ColorStateList to use for tinting
      • tintList

         static Drawable tintList(Context context, Drawable drawable, int tintListRes)

        Retrieves the drawable specified with the drawable using the tintListRes to correctly tint it before returning the Drawable object.

        Parameters:
        context - The context to use for retrieving the drawable
        drawable - The Drawable to tint
        tintListRes - The resource id for the ColorStateList to use for tinting
      • getDrawable

         static Drawable getDrawable(Context context, int drawableResourceId)

        Retrieves the drawable specified with the resourceId. This is a helper method to deal with the API differences for retrieving drawables

        Parameters:
        context - The context to use when retrieving the drawable
        drawableResourceId - The id for the drawable to retrieve
      • getResolvedResourceId

        @AnyRes() static int getResolvedResourceId(Context context, int attr)

        Resolves the reference to an attribute, returning the root resource id.

        Parameters:
        context - The context to use when determining the root id
        attr - The attribute to resolve
      • getColor

         static int getColor(Context context, int colorRes)

        Retrieves the color specified with the colorRes. This is a helper method to deal with the API differences for retrieving colors.

        Parameters:
        context - The context to use when retrieving the color
        colorRes - The id for the color to retrieve
      • getColorStateList

         static ColorStateList getColorStateList(Context context, int colorRes)

        Retrieves the ColorStateList specified with the colorRes. This is a helper method to deal with the API differences for retrieving colors.

        Parameters:
        context - The context to use when retrieving the color
        colorRes - The id for the ColorStateList to retrieve