Class ResourceHelper


  • public final class ResourceHelper
    extends java.lang.Object
    Helper class to provide various conversion method used in handling android resources.
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int getColor​(java.lang.String value)
      Returns the color value represented by the given string value
      static int getColorType​(java.lang.String value)
      Returns the TypedValue color type represented by the given string value
      static int getInternalResourceId​(java.lang.String idName)  
      static android.util.TypedValue getValue​(java.lang.String attribute, java.lang.String value, boolean requireUnit)
      Returns the raw value from the given attribute float-type value string.
      static boolean parseFloatAttribute​(java.lang.String attribute, java.lang.String value, android.util.TypedValue outValue, boolean requireUnit)
      Parse a float attribute and return the parsed value into a given TypedValue.
      • Methods inherited from class java.lang.Object

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

      • ResourceHelper

        public ResourceHelper()
    • Method Detail

      • getColor

        public static int getColor​(java.lang.String value)
        Returns the color value represented by the given string value
        Parameters:
        value - the color value
        Returns:
        the color as an int
        Throws:
        java.lang.NumberFormatException - if the conversion failed.
      • getColorType

        public static int getColorType​(java.lang.String value)
        Returns the TypedValue color type represented by the given string value
        Parameters:
        value - the color value
        Returns:
        the color as an int. For backwards compatibility, will return a default of ARGB8 if value format is unrecognized.
      • getInternalResourceId

        public static int getInternalResourceId​(java.lang.String idName)
      • getValue

        public static android.util.TypedValue getValue​(java.lang.String attribute,
                                                       java.lang.String value,
                                                       boolean requireUnit)
        Returns the raw value from the given attribute float-type value string. This object is only valid until the next call on to ResourceHelper.
        Parameters:
        attribute - Attribute name.
        value - Attribute value.
        requireUnit - whether the value is expected to contain a unit.
        Returns:
        The typed value.
      • parseFloatAttribute

        public static boolean parseFloatAttribute​(java.lang.String attribute,
                                                  java.lang.String value,
                                                  android.util.TypedValue outValue,
                                                  boolean requireUnit)
        Parse a float attribute and return the parsed value into a given TypedValue.
        Parameters:
        attribute - the name of the attribute. Can be null if requireUnit is false.
        value - the string value of the attribute
        outValue - the TypedValue to receive the parsed value
        requireUnit - whether the value is expected to contain a unit.
        Returns:
        true if success.