Package android.util
Class TypedValue
- java.lang.Object
-
- android.util.TypedValue
-
-
Field Summary
Fields Modifier and Type Field Description intassetCookieAdditional information about where the value came from; only set for strings.intchangingConfigurationsIf Value came from a resource, these are the configurations for which its contents can change.static intCOMPLEX_MANTISSA_MASKComplex data: mask to extract mantissa information (after shifting byCOMPLEX_MANTISSA_SHIFT).static intCOMPLEX_MANTISSA_SHIFTComplex data: bit location of mantissa information.static intCOMPLEX_RADIX_0p23Complex data: the mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnnstatic intCOMPLEX_RADIX_16p7Complex data: the mantissa magnitude is 16 bits -- i.e, 0xnnnn.nnstatic intCOMPLEX_RADIX_23p0Complex data: the mantissa is an integral number -- i.e., 0xnnnnnn.0static intCOMPLEX_RADIX_8p15Complex data: the mantissa magnitude is 8 bits -- i.e, 0xnn.nnnnstatic intCOMPLEX_RADIX_MASKComplex data: mask to extract radix information (after shifting byCOMPLEX_RADIX_SHIFT).static intCOMPLEX_RADIX_SHIFTComplex data: where the radix information is, telling where the decimal place appears in the mantissa.static intCOMPLEX_UNIT_DIPTYPE_DIMENSIONcomplex unit: Value is Device Independent Pixels.static intCOMPLEX_UNIT_FRACTIONTYPE_FRACTIONcomplex unit: A basic fraction of the overall size.static intCOMPLEX_UNIT_FRACTION_PARENTTYPE_FRACTIONcomplex unit: A fraction of the parent size.static intCOMPLEX_UNIT_INTYPE_DIMENSIONcomplex unit: Value is in inches.static intCOMPLEX_UNIT_MASKComplex data: mask to extract unit information (after shifting byCOMPLEX_UNIT_SHIFT).static intCOMPLEX_UNIT_MMTYPE_DIMENSIONcomplex unit: Value is in millimeters.static intCOMPLEX_UNIT_PTTYPE_DIMENSIONcomplex unit: Value is in points.static intCOMPLEX_UNIT_PXTYPE_DIMENSIONcomplex unit: Value is raw pixels.static intCOMPLEX_UNIT_SHIFTComplex data: bit location of unit information.static intCOMPLEX_UNIT_SPTYPE_DIMENSIONcomplex unit: Value is a scaled pixel.intdataBasic data in the value, interpreted according totypestatic intDATA_NULL_EMPTYTYPE_NULLdata indicating the value was explicitly set to null.static intDATA_NULL_UNDEFINEDTYPE_NULLdata indicating the value was not specified.intdensityIf the Value came from a resource, this holds the corresponding pixel density.static intDENSITY_DEFAULTIfdensityis equal to this value, then the density should be treated as the system's default density value:DisplayMetrics.DENSITY_DEFAULT.static intDENSITY_NONEIfdensityis equal to this value, then there is no density associated with the resource and it should not be scaled.intresourceIdIf Value came from a resource, this holds the corresponding resource id.CharSequencestringIf the value holds a string, this is it.inttypeThe type held by this value, as defined by the constants here.static intTYPE_ATTRIBUTEThe data field holds an attribute resource identifier (referencing an attribute in the current theme style, not a resource entry).static intTYPE_DIMENSIONThe data field holds a complex number encoding a dimension value.static intTYPE_FIRST_COLOR_INTIdentifies the start of integer values that were specified as color constants (starting with '#').static intTYPE_FIRST_INTIdentifies the start of plain integer values.static intTYPE_FLOATThe data field holds an IEEE 754 floating point number.static intTYPE_FRACTIONThe data field holds a complex number encoding a fraction of a container.static intTYPE_INT_BOOLEANThe data field holds 0 or 1 that was originally specified as "false" or "true".static intTYPE_INT_COLOR_ARGB4The data field holds a color that was originally specified as #argb.static intTYPE_INT_COLOR_ARGB8The data field holds a color that was originally specified as #aarrggbb.static intTYPE_INT_COLOR_RGB4The data field holds a color that was originally specified as #rgb.static intTYPE_INT_COLOR_RGB8The data field holds a color that was originally specified as #rrggbb.static intTYPE_INT_DECThe data field holds a number that was originally specified in decimal.static intTYPE_INT_HEXThe data field holds a number that was originally specified in hexadecimal (0xn).static intTYPE_LAST_COLOR_INTIdentifies the end of integer values that were specified as color constants.static intTYPE_LAST_INTIdentifies the end of plain integer values.static intTYPE_NULLThe value contains no data.static intTYPE_REFERENCEThe data field holds a resource identifier.static intTYPE_STRINGThe string field holds string data.
-
Constructor Summary
Constructors Constructor Description TypedValue()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static floatapplyDimension(int unit, float value, DisplayMetrics metrics)Converts an unpacked complex data value holding a dimension to its final floating point value.CharSequencecoerceToString()Regardless of the actual type of the value, try to convert it to a string value.static StringcoerceToString(int type, int data)Perform type conversion as percoerceToString()on an explicitly supplied type and data.static floatcomplexToDimension(int data, DisplayMetrics metrics)Converts a complex data value holding a dimension to its final floating point value.static floatcomplexToDimensionNoisy(int data, DisplayMetrics metrics)Deprecated.static intcomplexToDimensionPixelOffset(int data, DisplayMetrics metrics)Converts a complex data value holding a dimension to its final value as an integer pixel offset.static intcomplexToDimensionPixelSize(int data, DisplayMetrics metrics)Converts a complex data value holding a dimension to its final value as an integer pixel size.static floatcomplexToFloat(int complex)Retrieve the base value from a complex data integer.static floatcomplexToFraction(int data, float base, float pbase)Converts a complex data value holding a fraction to its final floating point value.intgetComplexUnit()Return the complex unit type for this value.floatgetDimension(DisplayMetrics metrics)Return the data for this value as a dimension.floatgetFloat()Return the data for this value as a float.floatgetFraction(float base, float pbase)Return the data for this value as a fraction.voidsetTo(TypedValue other)StringtoString()Returns a string containing a concise, human-readable description of this object.
-
-
-
Field Detail
-
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
-
TYPE_FIRST_INT
public static final int TYPE_FIRST_INT
Identifies the start of plain integer values. Any type value from this toTYPE_LAST_INTmeans the data field holds a generic integer value.- See Also:
- Constant Field Values
-
TYPE_INT_DEC
public static final int TYPE_INT_DEC
The data field holds a number that was originally specified in decimal.- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
TYPE_LAST_INT
public static final int TYPE_LAST_INT
Identifies the end of plain integer values.- See Also:
- Constant Field Values
-
COMPLEX_UNIT_SHIFT
public static final int COMPLEX_UNIT_SHIFT
Complex data: bit location 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 byCOMPLEX_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_DIMENSIONcomplex unit: Value is raw pixels.- See Also:
- Constant Field Values
-
COMPLEX_UNIT_DIP
public static final int COMPLEX_UNIT_DIP
TYPE_DIMENSIONcomplex unit: Value is Device Independent Pixels.- See Also:
- Constant Field Values
-
COMPLEX_UNIT_SP
public static final int COMPLEX_UNIT_SP
TYPE_DIMENSIONcomplex unit: Value is a scaled pixel.- See Also:
- Constant Field Values
-
COMPLEX_UNIT_PT
public static final int COMPLEX_UNIT_PT
TYPE_DIMENSIONcomplex unit: Value is in points.- See Also:
- Constant Field Values
-
COMPLEX_UNIT_IN
public static final int COMPLEX_UNIT_IN
TYPE_DIMENSIONcomplex unit: Value is in inches.- See Also:
- Constant Field Values
-
COMPLEX_UNIT_MM
public static final int COMPLEX_UNIT_MM
TYPE_DIMENSIONcomplex unit: Value is in millimeters.- See Also:
- Constant Field Values
-
COMPLEX_UNIT_FRACTION
public static final int COMPLEX_UNIT_FRACTION
TYPE_FRACTIONcomplex unit: A basic fraction of the overall size.- See Also:
- Constant Field Values
-
COMPLEX_UNIT_FRACTION_PARENT
public static final int COMPLEX_UNIT_FRACTION_PARENT
TYPE_FRACTIONcomplex 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 byCOMPLEX_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 location 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 byCOMPLEX_MANTISSA_SHIFT). This gives us 23 bits of precision; the top bit is the sign.- See Also:
- Constant Field Values
-
DATA_NULL_UNDEFINED
public static final int DATA_NULL_UNDEFINED
TYPE_NULLdata indicating the value was not specified.- See Also:
- Constant Field Values
-
DATA_NULL_EMPTY
public static final int DATA_NULL_EMPTY
TYPE_NULLdata indicating the value was explicitly set to null.- See Also:
- Constant Field Values
-
DENSITY_DEFAULT
public static final int DENSITY_DEFAULT
Ifdensityis equal to this value, then the density should be treated as the system's default density value:DisplayMetrics.DENSITY_DEFAULT.- See Also:
- Constant Field Values
-
DENSITY_NONE
public static final int DENSITY_NONE
Ifdensityis equal to this value, then there is no density associated with the resource and it should not be scaled.- See Also:
- Constant Field Values
-
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.
-
string
public CharSequence string
If the value holds a string, this is it.
-
data
public int data
Basic data in the value, interpreted according totype
-
assetCookie
public int assetCookie
Additional information about where the value came from; only set for strings.
-
resourceId
public int resourceId
If Value came from a resource, this holds the corresponding resource id.
-
changingConfigurations
public int changingConfigurations
If Value came from a resource, these are the configurations for which its contents can change.
-
density
public int density
If the Value came from a resource, this holds the corresponding pixel density.
-
-
Method Detail
-
getFloat
public final float getFloat()
Return the data for this value as a float. Only use for values whose type isTYPE_FLOAT.
-
complexToFloat
public static float complexToFloat(int complex)
Retrieve the base value from a complex data integer. This uses theCOMPLEX_MANTISSA_MASKandCOMPLEX_RADIX_MASKfields 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 aTYPE_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 ascomplexToDimension(int, android.util.DisplayMetrics), except the raw floating point value is truncated to an integer (pixel) value. The given data must be structured as aTYPE_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 ascomplexToDimension(int, android.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 aTYPE_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.
-
complexToDimensionNoisy
@Deprecated public static float complexToDimensionNoisy(int data, DisplayMetrics metrics)
Deprecated.
-
getComplexUnit
public int getComplexUnit()
Return the complex unit type for this value. For example, a dimen type with value 12sp will returnCOMPLEX_UNIT_SP. Only use for values whose type isTYPE_DIMENSION.- Returns:
- The complex unit type.
-
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 inTYPE_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.
-
getDimension
public float getDimension(DisplayMetrics metrics)
Return the data for this value as a dimension. Only use for values whose type isTYPE_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.
-
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 aTYPE_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.
-
getFraction
public float getFraction(float base, float pbase)Return the data for this value as a fraction. Only use for values whose type isTYPE_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.
-
coerceToString
public final CharSequence coerceToString()
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.
-
coerceToString
public static final String coerceToString(int type, int data)
Perform type conversion as percoerceToString()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.
-
setTo
public void setTo(TypedValue other)
-
toString
public String toString()
Description copied from class:ObjectReturns 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
toStringmethod if you intend implementing your owntoStringmethod.
-
-