Package icyllis.modernui.util

# Class TypedValue

java.lang.Object
icyllis.modernui.util.TypedValue

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

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static @interface`
  `TypedValue.ComplexDimensionUnit`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `COMPLEX_MANTISSA_MASK`
  Complex data: mask to extract mantissa information (after shifting by `COMPLEX_MANTISSA_SHIFT`).
  `static final int`
  `COMPLEX_MANTISSA_SHIFT`
  Complex data: bit shift of mantissa information.
  `static final int`
  `COMPLEX_RADIX_0p23`
  Complex data: the mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn
  `static final int`
  `COMPLEX_RADIX_16p7`
  Complex data: the mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn
  `static final int`
  `COMPLEX_RADIX_23p0`
  Complex data: the mantissa is an integral number -- i.e., 0xnnnnnn.0
  `static final int`
  `COMPLEX_RADIX_8p15`
  Complex data: the mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn
  `static final int`
  `COMPLEX_RADIX_MASK`
  Complex data: mask to extract radix information (after shifting by `COMPLEX_RADIX_SHIFT`).
  `static final int`
  `COMPLEX_RADIX_SHIFT`
  Complex data: where the radix information is, telling where the decimal place appears in the mantissa.
  `static final int`
  `COMPLEX_UNIT_DP`
  `TYPE_DIMENSION` complex unit: Value is device-independent pixels.
  `static final int`
  `COMPLEX_UNIT_FRACTION`
  `TYPE_FRACTION` complex unit: A fraction of the view size.
  `static final int`
  `COMPLEX_UNIT_FRACTION_PARENT`
  `TYPE_FRACTION` complex unit: A fraction of the parent size.
  `static final int`
  `COMPLEX_UNIT_IN`
  `TYPE_DIMENSION` complex unit: Value is in inches.
  `static final int`
  `COMPLEX_UNIT_MASK`
  Complex data: mask to extract unit information (after shifting by `COMPLEX_UNIT_SHIFT`).
  `static final int`
  `COMPLEX_UNIT_MM`
  `TYPE_DIMENSION` complex unit: Value is in millimeters.
  `static final int`
  `COMPLEX_UNIT_PT`
  `TYPE_DIMENSION` complex unit: Value is in points.
  `static final int`
  `COMPLEX_UNIT_PX`
  `TYPE_DIMENSION` complex unit: Value is raw pixels.
  `static final int`
  `COMPLEX_UNIT_SHIFT`
  Complex data: bit shift of unit information.
  `static final int`
  `COMPLEX_UNIT_SP`
  `TYPE_DIMENSION` complex unit: Value is scale-independent pixels.
  `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).
  `static final int`
  `TYPE_DIMENSION`
  The data field holds a complex number encoding a dimension value.
  `static final int`
  `TYPE_FLOAT`
  The data field holds an IEEE 754 floating-point number.
  `static final int`
  `TYPE_FRACTION`
  The data field holds a complex number encoding a fraction of a container.
  `static final int`
  `TYPE_NULL`
  The value contains no data.
  `static final int`
  `TYPE_REFERENCE`
  The data field holds a resource identifier.
  `static final int`
  `TYPE_STRING`
  The string field holds string data.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TypedValue()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static float`
  `applyDimension(int unit, float value, DisplayMetrics metrics)`
  Converts an unpacked complex data value holding a dimension to its final floating-point value.
  `static float`
  `complexToDimension(int data, DisplayMetrics metrics)`
  Converts a complex data value holding a dimension to its final floating point value.
  `static int`
  `complexToDimensionPixelOffset(int data, DisplayMetrics metrics)`
  Converts a complex data value holding a dimension to its final value as an integer pixel offset.
  `static int`
  `complexToDimensionPixelSize(int data, DisplayMetrics metrics)`
  Converts a complex data value holding a dimension to its final value as an integer pixel size.
  `static float`
  `complexToFloat(int complex)`
  Retrieve the base value from a complex data integer.
  `static float`
  `complexToFraction(int data, float base, float pbase)`
  Converts a complex data value holding a fraction to its final floating point value.
  `static int`
  `createComplexDimension(float value, int units)`
  Creates a complex data integer that stores a dimension value and units.
  `static int`
  `createComplexDimension(int value, int units)`
  Creates a complex data integer that stores a dimension value and units.
  `static int`
  `floatToComplex(float value)`
  Convert a base value to a complex data integer.
  `static int`
  `intToComplex(int value)`
  Convert a base value to 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:
      - Constant Field Values

  - ### TYPE_REFERENCE

    public static final int TYPE_REFERENCE
    The data field holds a resource identifier.
    See Also:
      - Constant Field Values

  - ### 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:
      - Constant Field Values

  - ### 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:
      - Constant Field Values

  - ### TYPE_FLOAT

    public static final int TYPE_FLOAT
    The data field holds an IEEE 754 floating-point number.
    See Also:
      - Constant Field Values

  - ### TYPE_DIMENSION

    public static final int TYPE_DIMENSION
    The data field holds a complex number encoding a dimension value.
    See Also:
      - Constant Field Values

  - ### TYPE_FRACTION

    public static final int TYPE_FRACTION
    The data field holds a complex number encoding a fraction of a container.
    See Also:
      - Constant Field Values

  - ### COMPLEX_UNIT_SHIFT

    public static final int COMPLEX_UNIT_SHIFT
    Complex data: bit shift of unit information.
    See Also:
      - Constant Field Values

  - ### 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:
      - Constant Field Values

  - ### COMPLEX_UNIT_PX

    public static final int COMPLEX_UNIT_PX
    `TYPE_DIMENSION` complex unit: Value is raw pixels.
    See Also:
      - Constant Field Values

  - ### COMPLEX_UNIT_DP

    public static final int COMPLEX_UNIT_DP
    `TYPE_DIMENSION` complex unit: Value is device-independent pixels.
    See Also:
      - Constant Field Values

  - ### COMPLEX_UNIT_SP

    public static final int COMPLEX_UNIT_SP
    `TYPE_DIMENSION` complex unit: Value is scale-independent pixels.
    See Also:
      - Constant Field Values

  - ### COMPLEX_UNIT_PT

    public static final int COMPLEX_UNIT_PT
    `TYPE_DIMENSION` complex unit: Value is in points.
    See Also:
      - Constant Field Values

  - ### COMPLEX_UNIT_IN

    public static final int COMPLEX_UNIT_IN
    `TYPE_DIMENSION` complex unit: Value is in inches.
    See Also:
      - Constant Field Values

  - ### COMPLEX_UNIT_MM

    public static final int COMPLEX_UNIT_MM
    `TYPE_DIMENSION` complex unit: Value is in millimeters.
    See Also:
      - Constant Field Values

  - ### COMPLEX_UNIT_FRACTION

    public static final int COMPLEX_UNIT_FRACTION
    `TYPE_FRACTION` complex unit: A fraction of the view size.
    See Also:
      - Constant Field Values

  - ### COMPLEX_UNIT_FRACTION_PARENT

    public static final int COMPLEX_UNIT_FRACTION_PARENT
    `TYPE_FRACTION` complex unit: A fraction of the parent size.
    See Also:
      - Constant Field Values

  - ### 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:
      - Constant Field Values

  - ### 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:
      - Constant Field Values

  - ### COMPLEX_RADIX_23p0

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

  - ### COMPLEX_RADIX_16p7

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

  - ### COMPLEX_RADIX_8p15

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

  - ### COMPLEX_RADIX_0p23

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

  - ### COMPLEX_MANTISSA_SHIFT

    public static final int COMPLEX_MANTISSA_SHIFT
    Complex data: bit shift of mantissa information.
    See Also:
      - Constant Field Values

  - ### 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:
      - Constant Field Values

- ## 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.

  - ### complexToDimension

    public static float complexToDimension(int data, DisplayMetrics metrics)
    Converts a complex data value holding a dimension to its final floating point value. The given data must be structured as a `TYPE_DIMENSION`.
    Parameters:
      `data` - A complex data value holding a unit, magnitude, and mantissa.
      `metrics` - Current display metrics to use in the conversion -- supplies display density and scaling information.
    Returns:
      The complex floating point value multiplied by the appropriate metrics depending on its unit.

  - ### complexToDimensionPixelOffset

    public static int complexToDimensionPixelOffset(int data, DisplayMetrics metrics)
    Converts a complex data value holding a dimension to its final value as an integer pixel offset.
    This is the same as `complexToDimension(int, icyllis.modernui.util.DisplayMetrics)`, except the raw floating point value is truncated to an integer (pixel) value. The given data must be structured as a `TYPE_DIMENSION`.
    Parameters:
      `data` - A complex data value holding a unit, magnitude, and mantissa.
      `metrics` - Current display metrics to use in the conversion -- supplies display density and scaling information.
    Returns:
      The number of pixels specified by the data and its desired multiplier and units.

  - ### complexToDimensionPixelSize

    public static int complexToDimensionPixelSize(int data, DisplayMetrics metrics)
    Converts a complex data value holding a dimension to its final value as an integer pixel size.
    This is the same as `complexToDimension(int, icyllis.modernui.util.DisplayMetrics)`, except the raw floating point value is converted to an integer (pixel) value for use as a size.
    A size conversion involves rounding the base value, and ensuring that a non-zero base value is at least one pixel in size.

    The given data must be structured as a `TYPE_DIMENSION`.

    Parameters:
      `data` - A complex data value holding a unit, magnitude, and mantissa.
      `metrics` - Current display metrics to use in the conversion -- supplies display density and scaling information.
    Returns:
      The number of pixels specified by the data and its desired multiplier and units.

  - ### applyDimension

    public static float applyDimension(int unit, float value, DisplayMetrics metrics)
    Converts an unpacked complex data value holding a dimension to its final floating-point value. The two parameters unit and value are as in `TYPE_DIMENSION`.
    Parameters:
      `unit` - The unit to convert from.
      `value` - The value to apply the unit to.
      `metrics` - Current display metrics to use in the conversion -- supplies display density and scaling information.
    Returns:
      The complex floating point value multiplied by the appropriate metrics depending on its unit.

  - ### intToComplex

    @Internal public static int intToComplex(int value)
    Convert a base value to a complex data integer.
    This sets the `COMPLEX_MANTISSA_MASK` and `COMPLEX_RADIX_MASK` fields of the data to create a floating point representation of the given value. The units are not set.

    This is the inverse of `complexToFloat(int)`.

    Parameters:
      `value` - An integer value.
    Returns:
      A complex data integer representing the value.

  - ### floatToComplex

    @Internal public static int floatToComplex(float value)
    Convert a base value to a complex data integer.
    This sets the `COMPLEX_MANTISSA_MASK` and `COMPLEX_RADIX_MASK` fields of the data to create a floating point representation of the given value. The units are not set.

    This is the inverse of `complexToFloat(int)`.

    Parameters:
      `value` - A floating point value.
    Returns:
      A complex data integer representing the value.

  - ### createComplexDimension

    @Internal public static int createComplexDimension(int value, int units)

    Creates a complex data integer that stores a dimension value and units.

    The resulting value can be passed to e.g. `complexToDimensionPixelOffset(int, DisplayMetrics)` to calculate the pixel value for the dimension.

    Parameters:
      `value` - the value of the dimension
      `units` - the units of the dimension, e.g. `COMPLEX_UNIT_DP`
    Returns:
      A complex data integer representing the value and units of the dimension.

  - ### createComplexDimension

    @Internal public static int createComplexDimension(float value, int units)

    Creates a complex data integer that stores a dimension value and units.

    The resulting value can be passed to e.g. `complexToDimensionPixelOffset(int, DisplayMetrics)` to calculate the pixel value for the dimension.

    Parameters:
      `value` - the value of the dimension
      `units` - the units of the dimension, e.g. `COMPLEX_UNIT_DP`
    Returns:
      A complex data integer representing the value and units of the dimension.

  - ### complexToFraction

    public static float complexToFraction(int data, float base, float pbase)
    Converts a complex data value holding a fraction to its final floating point value. The given data must be structured as a `TYPE_FRACTION`.
    Parameters:
      `data` - A complex data value holding a unit, magnitude, and mantissa.
      `base` - The base value of this fraction. In other words, a standard fraction is multiplied by this value.
      `pbase` - The parent base value of this fraction. In other words, a parent fraction (nn%p) is multiplied by this value.
    Returns:
      The complex floating point value multiplied by the appropriate base value depending on its unit.