Package icyllis.modernui.resources
Class TypedValue
java.lang.Object
icyllis.modernui.resources.TypedValue
Container for a dynamically typed data value.
Primarily used with
Primarily used with
Resources
for holding resource values.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Complex data: mask to extract mantissa information (after shifting byCOMPLEX_MANTISSA_SHIFT
).static final int
Complex data: bit shift of mantissa information.static final int
Complex data: the mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnnstatic final int
Complex data: the mantissa magnitude is 16 bits -- i.e, 0xnnnn.nnstatic final int
Complex data: the mantissa is an integral number -- i.e., 0xnnnnnn.0static final int
Complex data: the mantissa magnitude is 8 bits -- i.e, 0xnn.nnnnstatic final int
Complex data: mask to extract radix information (after shifting byCOMPLEX_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 fraction of the view 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 byCOMPLEX_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 shift of unit information.static final int
TYPE_DIMENSION
complex unit: Value is scale-independent pixels.int
The cookie representing thePackAssets
in which the value resides.int
Basic data in the value, interpreted according totype
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.int
The type held by this value, as defined by the constants here.static final int
The object 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
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 object field holds a resource identifier.static final int
The object field holds string data. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
Regardless of the actual type of the value, try to convert it to a string value.static String
coerceToString
(int type, int data) Perform type conversion as percoerceToString()
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 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.final int
If the value came from a resource, these are the configurations for which its contents can change.int
Return the complex unit type for this value.final float
getFloat()
Return the data for this value as a float.final ResourceId
Return the data for this value as a resource id.static int
getUnitFromComplexDimension
(int complexDimension) Return the complex unit type for the given complex dimension.static int
intToComplex
(int value) Convert a base value to a complex data integer.boolean
Determine if a value is a color.toString()
-
Field Details
-
TYPE_NULL
public static final int TYPE_NULLThe value contains no data.- See Also:
-
TYPE_REFERENCE
public static final int TYPE_REFERENCEThe object field holds a resource identifier.- See Also:
-
TYPE_ATTRIBUTE
public static final int TYPE_ATTRIBUTEThe object 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_STRINGThe object field holds string data. In addition, if data is non-zero then it is the string block index of the string and cookie is the set of assets the string came from.- See Also:
-
TYPE_FLOAT
public static final int TYPE_FLOATThe data field holds an IEEE 754 floating-point number.- See Also:
-
TYPE_DIMENSION
public static final int TYPE_DIMENSIONThe data field holds a complex number encoding a dimension value.- See Also:
-
TYPE_FRACTION
public static final int TYPE_FRACTIONThe data field holds a complex number encoding a fraction of a container.- See Also:
-
TYPE_FIRST_INT
public static final int TYPE_FIRST_INTIdentifies the start of plain integer values. Any type value from this toTYPE_LAST_INT
means the data field holds a generic integer value.- See Also:
-
TYPE_INT_DEC
public static final int TYPE_INT_DECThe data field holds a number that was originally specified in decimal.- See Also:
-
TYPE_INT_HEX
public static final int TYPE_INT_HEXThe data field holds a number that was originally specified in hexadecimal (0xn).- See Also:
-
TYPE_INT_BOOLEAN
public static final int TYPE_INT_BOOLEANThe 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_INTIdentifies 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_ARGB8The data field holds a color that was originally specified as #aarrggbb.- See Also:
-
TYPE_INT_COLOR_RGB8
public static final int TYPE_INT_COLOR_RGB8The data field holds a color that was originally specified as #rrggbb.- See Also:
-
TYPE_INT_COLOR_ARGB4
public static final int TYPE_INT_COLOR_ARGB4The data field holds a color that was originally specified as #argb.- See Also:
-
TYPE_INT_COLOR_RGB4
public static final int TYPE_INT_COLOR_RGB4The data field holds a color that was originally specified as #rgb.- See Also:
-
TYPE_LAST_COLOR_INT
public static final int TYPE_LAST_COLOR_INTIdentifies the end of integer values that were specified as color constants.- See Also:
-
TYPE_LAST_INT
public static final int TYPE_LAST_INTIdentifies the end of plain integer values.- See Also:
-
COMPLEX_UNIT_SHIFT
public static final int COMPLEX_UNIT_SHIFTComplex data: bit shift of unit information.- See Also:
-
COMPLEX_UNIT_MASK
public static final int COMPLEX_UNIT_MASKComplex data: mask to extract unit information (after shifting byCOMPLEX_UNIT_SHIFT
). This gives us 16 possible types, as defined below.- See Also:
-
COMPLEX_UNIT_PX
public static final int COMPLEX_UNIT_PXTYPE_DIMENSION
complex unit: Value is raw pixels.- See Also:
-
COMPLEX_UNIT_DP
public static final int COMPLEX_UNIT_DPTYPE_DIMENSION
complex unit: Value is device-independent pixels.- See Also:
-
COMPLEX_UNIT_SP
public static final int COMPLEX_UNIT_SPTYPE_DIMENSION
complex unit: Value is scale-independent pixels.- See Also:
-
COMPLEX_UNIT_PT
public static final int COMPLEX_UNIT_PTTYPE_DIMENSION
complex unit: Value is in points.- See Also:
-
COMPLEX_UNIT_IN
public static final int COMPLEX_UNIT_INTYPE_DIMENSION
complex unit: Value is in inches.- See Also:
-
COMPLEX_UNIT_MM
public static final int COMPLEX_UNIT_MMTYPE_DIMENSION
complex unit: Value is in millimeters.- See Also:
-
COMPLEX_UNIT_FRACTION
public static final int COMPLEX_UNIT_FRACTIONTYPE_FRACTION
complex unit: A fraction of the view size.- See Also:
-
COMPLEX_UNIT_FRACTION_PARENT
public static final int COMPLEX_UNIT_FRACTION_PARENTTYPE_FRACTION
complex unit: A fraction of the parent size.- See Also:
-
COMPLEX_RADIX_SHIFT
public static final int COMPLEX_RADIX_SHIFTComplex 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_MASKComplex data: mask to extract radix information (after shifting byCOMPLEX_RADIX_SHIFT
). This give us 4 possible fixed point representations as defined below.- See Also:
-
COMPLEX_RADIX_23p0
public static final int COMPLEX_RADIX_23p0Complex data: the mantissa is an integral number -- i.e., 0xnnnnnn.0- See Also:
-
COMPLEX_RADIX_16p7
public static final int COMPLEX_RADIX_16p7Complex data: the mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn- See Also:
-
COMPLEX_RADIX_8p15
public static final int COMPLEX_RADIX_8p15Complex data: the mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn- See Also:
-
COMPLEX_RADIX_0p23
public static final int COMPLEX_RADIX_0p23Complex data: the mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn- See Also:
-
COMPLEX_MANTISSA_SHIFT
public static final int COMPLEX_MANTISSA_SHIFTComplex data: bit shift of mantissa information.- See Also:
-
COMPLEX_MANTISSA_MASK
public static final int COMPLEX_MANTISSA_MASKComplex 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:
-
DATA_NULL_UNDEFINED
public static final int DATA_NULL_UNDEFINEDTYPE_NULL
data indicating the value was not specified.- See Also:
-
DATA_NULL_EMPTY
public static final int DATA_NULL_EMPTYTYPE_NULL
data indicating the value was explicitly set to null.- See Also:
-
type
public int typeThe type held by this value, as defined by the constants here. This tells you how to interpret the other fields in the object. -
data
public int dataBasic data in the value, interpreted according totype
-
cookie
public int cookieThe cookie representing thePackAssets
in which the value resides.
-
-
Constructor Details
-
TypedValue
public TypedValue()
-
-
Method Details
-
getFloat
public final float getFloat()Return the data for this value as a float. Only use for values whose type isTYPE_FLOAT
. -
isColorType
public boolean isColorType()Determine if a value is a color.This works by comparing
type
toTYPE_FIRST_COLOR_INT
andTYPE_LAST_COLOR_INT
.- Returns:
- true if this value is a color
-
complexToFloat
public static float complexToFloat(int complex) Retrieve the base value from a complex data integer.
This uses theCOMPLEX_MANTISSA_MASK
andCOMPLEX_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
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
Converts a complex data value holding a dimension to its final value as an integer pixel offset.
This is the same ascomplexToDimension(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 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
Converts a complex data value holding a dimension to its final value as an integer pixel size.
This is the same ascomplexToDimension(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.
-
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.
-
getUnitFromComplexDimension
public static int getUnitFromComplexDimension(int complexDimension) Return the complex unit type for the given complex dimension. For example, a dimen type with value 12sp will returnCOMPLEX_UNIT_SP
. Use with values created withcreateComplexDimension(int, int)
etc.- Returns:
- The complex unit type.
-
applyDimension
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.
-
intToComplex
@Internal public static int intToComplex(int value) Convert a base value to a complex data integer.
This sets theCOMPLEX_MANTISSA_MASK
andCOMPLEX_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 theCOMPLEX_MANTISSA_MASK
andCOMPLEX_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 dimensionunits
- 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 dimensionunits
- 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 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.
-
getResourceId
Return the data for this value as a resource id. Only use for values whose type isTYPE_ATTRIBUTE
orTYPE_REFERENCE
, to obtain unresolved references or attributes. In addition, for complex resources (such as styles), this represents the resource itself. If the reference is invalid or null, null is returned. -
getChangingConfigurations
@Experimental public final int getChangingConfigurations()If the value came from a resource, these are the configurations for which its contents can change. -
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
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.
-
toString
-