Package android.util

Class TypedValue

java.lang.Object
android.util.TypedValue

public class TypedValue extends Object
Container for a dynamically typed data value. Primarily used with Resources for holding resource values.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Complex data: mask to extract mantissa information (after shifting by COMPLEX_MANTISSA_SHIFT).
    static final int
    Complex data: bit location of mantissa information.
    static final int
    Complex data: the mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn
    static final int
    Complex data: the mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn
    static final int
    Complex data: the mantissa is an integral number -- i.e., 0xnnnnnn.0
    static final int
    Complex data: the mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn
    static final int
    Complex data: mask to extract radix information (after shifting by COMPLEX_RADIX_SHIFT).
    static final int
    Complex data: where the radix information is, telling where the decimal place appears in the mantissa.
    static final int
    TYPE_DIMENSION complex unit: Value is Device Independent Pixels.
    static final int
    TYPE_FRACTION complex unit: A basic fraction of the overall size.
    static final int
    TYPE_FRACTION complex unit: A fraction of the parent size.
    static final int
    TYPE_DIMENSION complex unit: Value is in inches.
    static final int
    Complex data: mask to extract unit information (after shifting by COMPLEX_UNIT_SHIFT).
    static final int
    TYPE_DIMENSION complex unit: Value is in millimeters.
    static final int
    TYPE_DIMENSION complex unit: Value is in points.
    static final int
    TYPE_DIMENSION complex unit: Value is raw pixels.
    static final int
    Complex data: bit location of unit information.
    static final int
    TYPE_DIMENSION complex unit: Value is a scaled pixel.
    static final int
    TYPE_NULL data indicating the value was explicitly set to null.
    static final int
    TYPE_NULL data indicating the value was not specified.
    static final int
    If density is equal to this value, then the density should be treated as the system's default density value:
    static final int
    If density is equal to this value, then there is no density associated with the resource and it should not be scaled.
    int
    The type held by this value, as defined by the constants here.
    static final int
    The data field holds an attribute resource identifier (referencing an attribute in the current theme style, not a resource entry).
    static final int
    The data field holds a complex number encoding a dimension value.
    static final int
    The data an attribute resource identifier, which needs to be resolved before it can be used like a TYPE_ATTRIBUTE.
    static final int
    The data holds a dynamic res table reference, which needs to be resolved before it can be used like TYPE_REFERENCE
    static final int
    Identifies the start of integer values that were specified as color constants (starting with '#').
    static final int
    Identifies the start of plain integer values.
    static final int
    The data field holds an IEEE 754 floating point number.
    static final int
    The data field holds a complex number encoding a fraction of a container.
    static final int
    The data field holds 0 or 1 that was originally specified as "false" or "true".
    static final int
    The data field holds a color that was originally specified as #argb.
    static final int
    The data field holds a color that was originally specified as #aarrggbb.
    static final int
    The data field holds a color that was originally specified as #rgb.
    static final int
    The data field holds a color that was originally specified as #rrggbb.
    static final int
    The data field holds a number that was originally specified in decimal.
    static final int
    The data field holds a number that was originally specified in hexadecimal (0xn).
    static final int
    Identifies the end of integer values that were specified as color constants.
    static final int
    Identifies the end of plain integer values.
    static final int
    The value contains no data.
    static final int
    The data field holds a resource identifier.
    static final int
    The string field holds string data.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    coerceToString(int type, int data)
    Perform type conversion as per coerceToString on an explicitly supplied type and data.
    static float
    complexToFloat(int complex)
    Retrieve the base value from a complex data integer.

    Methods inherited from class java.lang.Object

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

    • TYPE_NULL

      public static final int TYPE_NULL
      The value contains no data.
      See Also:
    • TYPE_REFERENCE

      public static final int TYPE_REFERENCE
      The data field holds a resource identifier.
      See Also:
    • TYPE_ATTRIBUTE

      public static final int TYPE_ATTRIBUTE
      The data field holds an attribute resource identifier (referencing an attribute in the current theme style, not a resource entry).
      See Also:
    • TYPE_STRING

      public static final int TYPE_STRING
      The string field holds string data. In addition, if data is non-zero then it is the string block index of the string and assetCookie is the set of assets the string came from.
      See Also:
    • TYPE_FLOAT

      public static final int TYPE_FLOAT
      The data field holds an IEEE 754 floating point number.
      See Also:
    • TYPE_DIMENSION

      public static final int TYPE_DIMENSION
      The data field holds a complex number encoding a dimension value.
      See Also:
    • TYPE_FRACTION

      public static final int TYPE_FRACTION
      The data field holds a complex number encoding a fraction of a container.
      See Also:
    • TYPE_DYNAMIC_REFERENCE

      public static final int TYPE_DYNAMIC_REFERENCE
      The data holds a dynamic res table reference, which needs to be resolved before it can be used like TYPE_REFERENCE
      See Also:
    • TYPE_DYNAMIC_ATTRIBUTE

      public static final int TYPE_DYNAMIC_ATTRIBUTE
      The data an attribute resource identifier, which needs to be resolved before it can be used like a TYPE_ATTRIBUTE.
      See Also:
    • TYPE_FIRST_INT

      public static final int TYPE_FIRST_INT
      Identifies the start of plain integer values. Any type value from this to TYPE_LAST_INT means the data field holds a generic integer value.
      See Also:
    • TYPE_INT_DEC

      public static final int TYPE_INT_DEC
      The data field holds a number that was originally specified in decimal.
      See Also:
    • TYPE_INT_HEX

      public static final int TYPE_INT_HEX
      The data field holds a number that was originally specified in hexadecimal (0xn).
      See Also:
    • TYPE_INT_BOOLEAN

      public static final int TYPE_INT_BOOLEAN
      The data field holds 0 or 1 that was originally specified as "false" or "true".
      See Also:
    • TYPE_FIRST_COLOR_INT

      public static final int TYPE_FIRST_COLOR_INT
      Identifies the start of integer values that were specified as color constants (starting with '#').
      See Also:
    • TYPE_INT_COLOR_ARGB8

      public static final int TYPE_INT_COLOR_ARGB8
      The data field holds a color that was originally specified as #aarrggbb.
      See Also:
    • TYPE_INT_COLOR_RGB8

      public static final int TYPE_INT_COLOR_RGB8
      The data field holds a color that was originally specified as #rrggbb.
      See Also:
    • TYPE_INT_COLOR_ARGB4

      public static final int TYPE_INT_COLOR_ARGB4
      The data field holds a color that was originally specified as #argb.
      See Also:
    • TYPE_INT_COLOR_RGB4

      public static final int TYPE_INT_COLOR_RGB4
      The data field holds a color that was originally specified as #rgb.
      See Also:
    • TYPE_LAST_COLOR_INT

      public static final int TYPE_LAST_COLOR_INT
      Identifies the end of integer values that were specified as color constants.
      See Also:
    • TYPE_LAST_INT

      public static final int TYPE_LAST_INT
      Identifies the end of plain integer values.
      See Also:
    • COMPLEX_UNIT_SHIFT

      public static final int COMPLEX_UNIT_SHIFT
      Complex data: bit location of unit information.
      See Also:
    • COMPLEX_UNIT_MASK

      public static final int COMPLEX_UNIT_MASK
      Complex data: mask to extract unit information (after shifting by COMPLEX_UNIT_SHIFT). This gives us 16 possible types, as defined below.
      See Also:
    • COMPLEX_UNIT_PX

      public static final int COMPLEX_UNIT_PX
      TYPE_DIMENSION complex unit: Value is raw pixels.
      See Also:
    • COMPLEX_UNIT_DIP

      public static final int COMPLEX_UNIT_DIP
      TYPE_DIMENSION complex unit: Value is Device Independent Pixels.
      See Also:
    • COMPLEX_UNIT_SP

      public static final int COMPLEX_UNIT_SP
      TYPE_DIMENSION complex unit: Value is a scaled pixel.
      See Also:
    • COMPLEX_UNIT_PT

      public static final int COMPLEX_UNIT_PT
      TYPE_DIMENSION complex unit: Value is in points.
      See Also:
    • COMPLEX_UNIT_IN

      public static final int COMPLEX_UNIT_IN
      TYPE_DIMENSION complex unit: Value is in inches.
      See Also:
    • COMPLEX_UNIT_MM

      public static final int COMPLEX_UNIT_MM
      TYPE_DIMENSION complex unit: Value is in millimeters.
      See Also:
    • COMPLEX_UNIT_FRACTION

      public static final int COMPLEX_UNIT_FRACTION
      TYPE_FRACTION complex unit: A basic fraction of the overall size.
      See Also:
    • COMPLEX_UNIT_FRACTION_PARENT

      public static final int COMPLEX_UNIT_FRACTION_PARENT
      TYPE_FRACTION complex unit: A fraction of the parent size.
      See Also:
    • COMPLEX_RADIX_SHIFT

      public static final int COMPLEX_RADIX_SHIFT
      Complex data: where the radix information is, telling where the decimal place appears in the mantissa.
      See Also:
    • COMPLEX_RADIX_MASK

      public static final int COMPLEX_RADIX_MASK
      Complex data: mask to extract radix information (after shifting by COMPLEX_RADIX_SHIFT). This give us 4 possible fixed point representations as defined below.
      See Also:
    • COMPLEX_RADIX_23p0

      public static final int COMPLEX_RADIX_23p0
      Complex data: the mantissa is an integral number -- i.e., 0xnnnnnn.0
      See Also:
    • COMPLEX_RADIX_16p7

      public static final int COMPLEX_RADIX_16p7
      Complex data: the mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn
      See Also:
    • COMPLEX_RADIX_8p15

      public static final int COMPLEX_RADIX_8p15
      Complex data: the mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn
      See Also:
    • COMPLEX_RADIX_0p23

      public static final int COMPLEX_RADIX_0p23
      Complex data: the mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn
      See Also:
    • COMPLEX_MANTISSA_SHIFT

      public static final int COMPLEX_MANTISSA_SHIFT
      Complex data: bit location of mantissa information.
      See Also:
    • COMPLEX_MANTISSA_MASK

      public static final int COMPLEX_MANTISSA_MASK
      Complex data: mask to extract mantissa information (after shifting by COMPLEX_MANTISSA_SHIFT). This gives us 23 bits of precision; the top bit is the sign.
      See Also:
    • DATA_NULL_UNDEFINED

      public static final int DATA_NULL_UNDEFINED
      TYPE_NULL data indicating the value was not specified.
      See Also:
    • DATA_NULL_EMPTY

      public static final int DATA_NULL_EMPTY
      TYPE_NULL data indicating the value was explicitly set to null.
      See Also:
    • DENSITY_DEFAULT

      public static final int DENSITY_DEFAULT
      If density is equal to this value, then the density should be treated as the system's default density value:
      See Also:
    • DENSITY_NONE

      public static final int DENSITY_NONE
      If density is equal to this value, then there is no density associated with the resource and it should not be scaled.
      See Also:
    • type

      public int type
      The type held by this value, as defined by the constants here. This tells you how to interpret the other fields in the object.
  • Constructor Details

    • TypedValue

      public TypedValue()
  • Method Details

    • complexToFloat

      public static float complexToFloat(int complex)
      Retrieve the base value from a complex data integer. This uses the COMPLEX_MANTISSA_MASK and COMPLEX_RADIX_MASK fields of the data to compute a floating point representation of the number they describe. The units are ignored.
      Parameters:
      complex - A complex data value.
      Returns:
      A floating point value corresponding to the complex data.
    • coerceToString

      public static String coerceToString(int type, int data)
      Perform type conversion as per coerceToString on an explicitly supplied type and data.
      Parameters:
      type - The data type identifier.
      data - The data value.
      Returns:
      String The coerced string value. If the value is null or the type is not known, null is returned.