public class

TypedValue

extends Object
java.lang.Object
   ↳android.util.TypedValue

Class Overview

Container for a dynamically typed data value. Primarily used with Resources for holding resource values.

Summary

Constants
intCOMPLEX_MANTISSA_MASKComplex data: mask to extract mantissa information (after shifting by COMPLEX_MANTISSA_SHIFT).
intCOMPLEX_MANTISSA_SHIFTComplex data: bit location of mantissa information.
intCOMPLEX_RADIX_0p23Complex data: the mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn
intCOMPLEX_RADIX_16p7Complex data: the mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn
intCOMPLEX_RADIX_23p0Complex data: the mantissa is an integral number -- i.e., 0xnnnnnn.0
intCOMPLEX_RADIX_8p15Complex data: the mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn
intCOMPLEX_RADIX_MASKComplex data: mask to extract radix information (after shifting by COMPLEX_RADIX_SHIFT).
intCOMPLEX_RADIX_SHIFTComplex data: where the radix information is, telling where the decimal place appears in the mantissa.
intCOMPLEX_UNIT_DIPTYPE_DIMENSION complex unit: Value is Device Independent Pixels.
intCOMPLEX_UNIT_FRACTIONTYPE_FRACTION complex unit: A basic fraction of the overall size.
intCOMPLEX_UNIT_FRACTION_PARENTTYPE_FRACTION complex unit: A fraction of the parent size.
intCOMPLEX_UNIT_INTYPE_DIMENSION complex unit: Value is in inches.
intCOMPLEX_UNIT_MASKComplex data: mask to extract unit information (after shifting by COMPLEX_UNIT_SHIFT).
intCOMPLEX_UNIT_MMTYPE_DIMENSION complex unit: Value is in millimeters.
intCOMPLEX_UNIT_PTTYPE_DIMENSION complex unit: Value is in points.
intCOMPLEX_UNIT_PXTYPE_DIMENSION complex unit: Value is raw pixels.
intCOMPLEX_UNIT_SHIFTComplex data: bit location of unit information.
intCOMPLEX_UNIT_SPTYPE_DIMENSION complex unit: Value is a scaled pixel.
intDENSITY_DEFAULTIf density is equal to this value, then the density should be treated as the system's default density value: DENSITY_DEFAULT.
intDENSITY_NONEIf density is equal to this value, then there is no density associated with the resource and it should not be scaled.
intTYPE_ATTRIBUTEThe data field holds an attribute resource identifier (referencing an attribute in the current theme style, not a resource entry).
intTYPE_DIMENSIONThe data field holds a complex number encoding a dimension value.
intTYPE_FIRST_COLOR_INTIdentifies the start of integer values that were specified as color constants (starting with '#').
intTYPE_FIRST_INTIdentifies the start of plain integer values.
intTYPE_FLOATThe data field holds an IEEE 754 floating point number.
intTYPE_FRACTIONThe data field holds a complex number encoding a fraction of a container.
intTYPE_INT_BOOLEANThe data field holds 0 or 1 that was originally specified as "false" or "true".
intTYPE_INT_COLOR_ARGB4The data field holds a color that was originally specified as #argb.
intTYPE_INT_COLOR_ARGB8The data field holds a color that was originally specified as #aarrggbb.
intTYPE_INT_COLOR_RGB4The data field holds a color that was originally specified as #rgb.
intTYPE_INT_COLOR_RGB8The data field holds a color that was originally specified as #rrggbb.
intTYPE_INT_DECThe data field holds a number that was originally specified in decimal.
intTYPE_INT_HEXThe data field holds a number that was originally specified in hexadecimal (0xn).
intTYPE_LAST_COLOR_INTIdentifies the end of integer values that were specified as color constants.
intTYPE_LAST_INTIdentifies the end of plain integer values.
intTYPE_NULLThe value contains no data.
intTYPE_REFERENCEThe data field holds a resource identifier.
intTYPE_STRINGThe string field holds string data.
Fields
public intassetCookieAdditional information about where the value came from; only set for strings.
public intchangingConfigurationsIf Value came from a resource, these are the configurations for which its contents can change.
public intdataBasic data in the value, interpreted according to type
public intdensityIf the Value came from a resource, this holds the corresponding pixel density.
public intresourceIdIf Value came from a resource, this holds the corresponding resource id.
public CharSequencestringIf the value holds a string, this is it.
public inttypeThe type held by this value, as defined by the constants here.
Public Constructors
TypedValue()
Public Methods
static float applyDimension(int unit, float value, DisplayMetrics metrics)
Converts an unpacked complex data value holding a dimension to its final floating point value.
final CharSequence coerceToString()
Regardless of the actual type of the value, try to convert it to a string value.
final static String coerceToString(int type, int data)
Perform type conversion as per coerceToString() on an explicitly supplied type and data.
static float complexToDimension(int data, DisplayMetrics metrics)
Converts a complex data value holding a dimension to its final floating point value.
static float complexToDimensionNoisy(int data, DisplayMetrics metrics)
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.
float getDimension(DisplayMetrics metrics)
Return the data for this value as a dimension.
final float getFloat()
Return the data for this value as a float.
float getFraction(float base, float pbase)
Return the data for this value as a fraction.
void setTo(TypedValue other)
String toString()
Returns a string containing a concise, human-readable description of this object.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int COMPLEX_MANTISSA_MASK

Since: API Level 1

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.

Constant Value: 16777215 (0x00ffffff)

public static final int COMPLEX_MANTISSA_SHIFT

Since: API Level 1

Complex data: bit location of mantissa information.

Constant Value: 8 (0x00000008)

public static final int COMPLEX_RADIX_0p23

Since: API Level 1

Complex data: the mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn

Constant Value: 3 (0x00000003)

public static final int COMPLEX_RADIX_16p7

Since: API Level 1

Complex data: the mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn

Constant Value: 1 (0x00000001)

public static final int COMPLEX_RADIX_23p0

Since: API Level 1

Complex data: the mantissa is an integral number -- i.e., 0xnnnnnn.0

Constant Value: 0 (0x00000000)

public static final int COMPLEX_RADIX_8p15

Since: API Level 1

Complex data: the mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn

Constant Value: 2 (0x00000002)

public static final int COMPLEX_RADIX_MASK

Since: API Level 1

Complex data: mask to extract radix information (after shifting by COMPLEX_RADIX_SHIFT). This give us 4 possible fixed point representations as defined below.

Constant Value: 3 (0x00000003)

public static final int COMPLEX_RADIX_SHIFT

Since: API Level 1

Complex data: where the radix information is, telling where the decimal place appears in the mantissa.

Constant Value: 4 (0x00000004)

public static final int COMPLEX_UNIT_DIP

Since: API Level 1

TYPE_DIMENSION complex unit: Value is Device Independent Pixels.

Constant Value: 1 (0x00000001)

public static final int COMPLEX_UNIT_FRACTION

Since: API Level 1

TYPE_FRACTION complex unit: A basic fraction of the overall size.

Constant Value: 0 (0x00000000)

public static final int COMPLEX_UNIT_FRACTION_PARENT

Since: API Level 1

TYPE_FRACTION complex unit: A fraction of the parent size.

Constant Value: 1 (0x00000001)

public static final int COMPLEX_UNIT_IN

Since: API Level 1

TYPE_DIMENSION complex unit: Value is in inches.

Constant Value: 4 (0x00000004)

public static final int COMPLEX_UNIT_MASK

Since: API Level 1

Complex data: mask to extract unit information (after shifting by COMPLEX_UNIT_SHIFT). This gives us 16 possible types, as defined below.

Constant Value: 15 (0x0000000f)

public static final int COMPLEX_UNIT_MM

Since: API Level 1

TYPE_DIMENSION complex unit: Value is in millimeters.

Constant Value: 5 (0x00000005)

public static final int COMPLEX_UNIT_PT

Since: API Level 1

TYPE_DIMENSION complex unit: Value is in points.

Constant Value: 3 (0x00000003)

public static final int COMPLEX_UNIT_PX

Since: API Level 1

TYPE_DIMENSION complex unit: Value is raw pixels.

Constant Value: 0 (0x00000000)

public static final int COMPLEX_UNIT_SHIFT

Since: API Level 1

Complex data: bit location of unit information.

Constant Value: 0 (0x00000000)

public static final int COMPLEX_UNIT_SP

Since: API Level 1

TYPE_DIMENSION complex unit: Value is a scaled pixel.

Constant Value: 2 (0x00000002)

public static final int DENSITY_DEFAULT

Since: API Level 4

If density is equal to this value, then the density should be treated as the system's default density value: DENSITY_DEFAULT.

Constant Value: 0 (0x00000000)

public static final int DENSITY_NONE

Since: API Level 4

If density is equal to this value, then there is no density associated with the resource and it should not be scaled.

Constant Value: 65535 (0x0000ffff)

public static final int TYPE_ATTRIBUTE

Since: API Level 1

The data field holds an attribute resource identifier (referencing an attribute in the current theme style, not a resource entry).

Constant Value: 2 (0x00000002)

public static final int TYPE_DIMENSION

Since: API Level 1

The data field holds a complex number encoding a dimension value.

Constant Value: 5 (0x00000005)

public static final int TYPE_FIRST_COLOR_INT

Since: API Level 1

Identifies the start of integer values that were specified as color constants (starting with '#').

Constant Value: 28 (0x0000001c)

public static final int TYPE_FIRST_INT

Since: API Level 1

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.

Constant Value: 16 (0x00000010)

public static final int TYPE_FLOAT

Since: API Level 1

The data field holds an IEEE 754 floating point number.

Constant Value: 4 (0x00000004)

public static final int TYPE_FRACTION

Since: API Level 1

The data field holds a complex number encoding a fraction of a container.

Constant Value: 6 (0x00000006)

public static final int TYPE_INT_BOOLEAN

Since: API Level 1

The data field holds 0 or 1 that was originally specified as "false" or "true".

Constant Value: 18 (0x00000012)

public static final int TYPE_INT_COLOR_ARGB4

Since: API Level 1

The data field holds a color that was originally specified as #argb.

Constant Value: 30 (0x0000001e)

public static final int TYPE_INT_COLOR_ARGB8

Since: API Level 1

The data field holds a color that was originally specified as #aarrggbb.

Constant Value: 28 (0x0000001c)

public static final int TYPE_INT_COLOR_RGB4

Since: API Level 1

The data field holds a color that was originally specified as #rgb.

Constant Value: 31 (0x0000001f)

public static final int TYPE_INT_COLOR_RGB8

Since: API Level 1

The data field holds a color that was originally specified as #rrggbb.

Constant Value: 29 (0x0000001d)

public static final int TYPE_INT_DEC

Since: API Level 1

The data field holds a number that was originally specified in decimal.

Constant Value: 16 (0x00000010)

public static final int TYPE_INT_HEX

Since: API Level 1

The data field holds a number that was originally specified in hexadecimal (0xn).

Constant Value: 17 (0x00000011)

public static final int TYPE_LAST_COLOR_INT

Since: API Level 1

Identifies the end of integer values that were specified as color constants.

Constant Value: 31 (0x0000001f)

public static final int TYPE_LAST_INT

Since: API Level 1

Identifies the end of plain integer values.

Constant Value: 31 (0x0000001f)

public static final int TYPE_NULL

Since: API Level 1

The value contains no data.

Constant Value: 0 (0x00000000)

public static final int TYPE_REFERENCE

Since: API Level 1

The data field holds a resource identifier.

Constant Value: 1 (0x00000001)

public static final int TYPE_STRING

Since: API Level 1

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.

Constant Value: 3 (0x00000003)

Fields

public int assetCookie

Since: API Level 1

Additional information about where the value came from; only set for strings.

public int changingConfigurations

Since: API Level 1

If Value came from a resource, these are the configurations for which its contents can change.

public int data

Since: API Level 1

Basic data in the value, interpreted according to type

public int density

Since: API Level 4

If the Value came from a resource, this holds the corresponding pixel density.

public int resourceId

Since: API Level 1

If Value came from a resource, this holds the corresponding resource id.

public CharSequence string

Since: API Level 1

If the value holds a string, this is it.

public int type

Since: API Level 1

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

Public Constructors

public TypedValue ()

Since: API Level 1

Public Methods

public static float applyDimension (int unit, float value, DisplayMetrics metrics)

Since: API Level 1

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.

public final CharSequence coerceToString ()

Since: API Level 1

Regardless of the actual type of the value, try to convert it to a string value. For example, a color type will be converted to a string of the form #aarrggbb.

Returns
  • CharSequence The coerced string value. If the value is null or the type is not known, null is returned.

public static final String coerceToString (int type, int data)

Since: API Level 1

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.

public static float complexToDimension (int data, DisplayMetrics metrics)

Since: API Level 1

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.

public static float complexToDimensionNoisy (int data, DisplayMetrics metrics)

Since: API Level 1

public static int complexToDimensionPixelOffset (int data, DisplayMetrics metrics)

Since: API Level 1

Converts a complex data value holding a dimension to its final value as an integer pixel offset. This is the same as complexToDimension(int, 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.

public static int complexToDimensionPixelSize (int data, DisplayMetrics metrics)

Since: API Level 1

Converts a complex data value holding a dimension to its final value as an integer pixel size. This is the same as complexToDimension(int, 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.

public static float complexToFloat (int complex)

Since: API Level 1

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.

public static float complexToFraction (int data, float base, float pbase)

Since: API Level 1

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.

public float getDimension (DisplayMetrics metrics)

Since: API Level 1

Return the data for this value as a dimension. Only use for values whose type is TYPE_DIMENSION.

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

public final float getFloat ()

Since: API Level 1

Return the data for this value as a float. Only use for values whose type is TYPE_FLOAT.

public float getFraction (float base, float pbase)

Since: API Level 1

Return the data for this value as a fraction. Only use for values whose type is TYPE_FRACTION.

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

public void setTo (TypedValue other)

Since: API Level 1

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.