TypedValue
open class TypedValue
kotlin.Any | |
↳ | android.util.TypedValue |
Container for a dynamically typed data value. Primarily used with android.content.res.Resources
for holding resource values.
Summary
Constants | |
---|---|
static Int |
Complex data: mask to extract mantissa information (after shifting by |
static Int |
Complex data: bit location of mantissa information. |
static Int |
Complex data: the mantissa magnitude is 0 bits -- i. |
static Int |
Complex data: the mantissa magnitude is 16 bits -- i. |
static Int |
Complex data: the mantissa is an integral number -- i. |
static Int |
Complex data: the mantissa magnitude is 8 bits -- i. |
static Int |
Complex data: mask to extract radix information (after shifting by |
static Int |
Complex data: where the radix information is, telling where the decimal place appears in the mantissa. |
static Int |
|
static Int |
|
static Int |
|
static Int |
|
static Int |
Complex data: mask to extract unit information (after shifting by |
static Int |
|
static Int |
|
static Int |
|
static Int |
Complex data: bit location of unit information. |
static Int |
|
static Int |
|
static Int |
|
static Int |
If |
static Int |
If |
static Int |
The data field holds an attribute resource identifier (referencing an attribute in the current theme style, not a resource entry). |
static Int |
The data field holds a complex number encoding a dimension value. |
static Int |
Identifies the start of integer values that were specified as color constants (starting with '#'). |
static Int |
Identifies the start of plain integer values. |
static Int |
The data field holds an IEEE 754 floating point number. |
static Int |
The data field holds a complex number encoding a fraction of a container. |
static Int |
The data field holds 0 or 1 that was originally specified as "false" or "true". |
static Int |
The data field holds a color that was originally specified as #argb. |
static Int |
The data field holds a color that was originally specified as #aarrggbb. |
static Int |
The data field holds a color that was originally specified as #rgb. |
static Int |
The data field holds a color that was originally specified as #rrggbb. |
static Int |
The data field holds a number that was originally specified in decimal. |
static Int |
The data field holds a number that was originally specified in hexadecimal (0xn). |
static Int |
Identifies the end of integer values that were specified as color constants. |
static Int |
Identifies the end of plain integer values. |
static Int |
The value contains no data. |
static Int |
The data field holds a resource identifier. |
static Int |
The string field holds string data. |
Public constructors | |
---|---|
Public methods | |
---|---|
open static Float |
applyDimension(unit: Int, value: Float, metrics: DisplayMetrics!) Converts an unpacked complex data value holding a dimension to its final floating point pixel value. |
CharSequence! |
Regardless of the actual type of the value, try to convert it to a string value. |
static String! |
coerceToString(type: Int, data: Int) Perform type conversion as per |
open static Float |
complexToDimension(data: Int, metrics: DisplayMetrics!) Converts a complex data value holding a dimension to its final floating point value. |
open static Int |
complexToDimensionPixelOffset(data: Int, metrics: DisplayMetrics!) Converts a complex data value holding a dimension to its final value as an integer pixel offset. |
open static Int |
complexToDimensionPixelSize(data: Int, metrics: DisplayMetrics!) Converts a complex data value holding a dimension to its final value as an integer pixel size. |
open static Float |
complexToFloat(complex: Int) Retrieve the base value from a complex data integer. |
open static Float |
complexToFraction(data: Int, base: Float, pbase: Float) Converts a complex data value holding a fraction to its final floating point value. |
open static Float |
convertDimensionToPixels(unitToConvertFrom: Int, value: Float, metrics: DisplayMetrics) Converts a dimension value to raw pixels, e. |
open static Float |
convertPixelsToDimension(unitToConvertTo: Int, pixelValue: Float, metrics: DisplayMetrics) Converts a pixel value to the given dimension, e. |
open static Float |
deriveDimension(unitToConvertTo: Int, pixelValue: Float, metrics: DisplayMetrics) Converts a pixel value to the given dimension, e. |
open Int |
Return the complex unit type for this value. |
open Float |
getDimension(metrics: DisplayMetrics!) Return the data for this value as a dimension. |
Float |
getFloat() Return the data for this value as a float. |
open Float |
getFraction(base: Float, pbase: Float) Return the data for this value as a fraction. |
open Boolean |
Determine if a value is a color. |
open Unit |
setTo(other: TypedValue!) |
open String |
toString() |
Properties | |
---|---|
Int |
Additional information about where the value came from; only set for strings. |
Int |
If the value came from a resource, these are the configurations for which its contents can change. |
Int |
Basic data in the value, interpreted according to |
Int |
If the Value came from a resource, this holds the corresponding pixel density. |
Int |
If Value came from a resource, this holds the corresponding resource id. |
Int |
If the Value came from a style resource or a layout resource (set in an XML layout), this holds the corresponding style or layout resource id against which the attribute was resolved. |
CharSequence! |
If the value holds a string, this is it. |
Int |
The type held by this value, as defined by the constants here. |
Constants
COMPLEX_MANTISSA_MASK
static val COMPLEX_MANTISSA_MASK: Int
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.
Value: 16777215
COMPLEX_MANTISSA_SHIFT
static val COMPLEX_MANTISSA_SHIFT: Int
Complex data: bit location of mantissa information.
Value: 8
COMPLEX_RADIX_0p23
static val COMPLEX_RADIX_0p23: Int
Complex data: the mantissa magnitude is 0 bits -- i.e, 0x0.nnnnnn
Value: 3
COMPLEX_RADIX_16p7
static val COMPLEX_RADIX_16p7: Int
Complex data: the mantissa magnitude is 16 bits -- i.e, 0xnnnn.nn
Value: 1
COMPLEX_RADIX_23p0
static val COMPLEX_RADIX_23p0: Int
Complex data: the mantissa is an integral number -- i.e., 0xnnnnnn.0
Value: 0
COMPLEX_RADIX_8p15
static val COMPLEX_RADIX_8p15: Int
Complex data: the mantissa magnitude is 8 bits -- i.e, 0xnn.nnnn
Value: 2
COMPLEX_RADIX_MASK
static val COMPLEX_RADIX_MASK: Int
Complex data: mask to extract radix information (after shifting by COMPLEX_RADIX_SHIFT
). This give us 4 possible fixed point representations as defined below.
Value: 3
COMPLEX_RADIX_SHIFT
static val COMPLEX_RADIX_SHIFT: Int
Complex data: where the radix information is, telling where the decimal place appears in the mantissa.
Value: 4
COMPLEX_UNIT_DIP
static val COMPLEX_UNIT_DIP: Int
TYPE_DIMENSION
complex unit: Value is Device Independent Pixels.
Value: 1
COMPLEX_UNIT_FRACTION
static val COMPLEX_UNIT_FRACTION: Int
TYPE_FRACTION
complex unit: A basic fraction of the overall size.
Value: 0
COMPLEX_UNIT_FRACTION_PARENT
static val COMPLEX_UNIT_FRACTION_PARENT: Int
TYPE_FRACTION
complex unit: A fraction of the parent size.
Value: 1
COMPLEX_UNIT_IN
static val COMPLEX_UNIT_IN: Int
TYPE_DIMENSION
complex unit: Value is in inches.
Value: 4
COMPLEX_UNIT_MASK
static val COMPLEX_UNIT_MASK: Int
Complex data: mask to extract unit information (after shifting by COMPLEX_UNIT_SHIFT
). This gives us 16 possible types, as defined below.
Value: 15
COMPLEX_UNIT_MM
static val COMPLEX_UNIT_MM: Int
TYPE_DIMENSION
complex unit: Value is in millimeters.
Value: 5
COMPLEX_UNIT_PT
static val COMPLEX_UNIT_PT: Int
TYPE_DIMENSION
complex unit: Value is in points.
Value: 3
COMPLEX_UNIT_PX
static val COMPLEX_UNIT_PX: Int
TYPE_DIMENSION
complex unit: Value is raw pixels.
Value: 0
COMPLEX_UNIT_SHIFT
static val COMPLEX_UNIT_SHIFT: Int
Complex data: bit location of unit information.
Value: 0
COMPLEX_UNIT_SP
static val COMPLEX_UNIT_SP: Int
TYPE_DIMENSION
complex unit: Value is a scaled pixel.
Value: 2
DATA_NULL_EMPTY
static val DATA_NULL_EMPTY: Int
TYPE_NULL
data indicating the value was explicitly set to null.
Value: 1
DATA_NULL_UNDEFINED
static val DATA_NULL_UNDEFINED: Int
TYPE_NULL
data indicating the value was not specified.
Value: 0
DENSITY_DEFAULT
static val DENSITY_DEFAULT: Int
If density
is equal to this value, then the density should be treated as the system's default density value: DisplayMetrics#DENSITY_DEFAULT
.
Value: 0
DENSITY_NONE
static val DENSITY_NONE: Int
If density
is equal to this value, then there is no density associated with the resource and it should not be scaled.
Value: 65535
TYPE_ATTRIBUTE
static val TYPE_ATTRIBUTE: Int
The data field holds an attribute resource identifier (referencing an attribute in the current theme style, not a resource entry).
Value: 2
TYPE_DIMENSION
static val TYPE_DIMENSION: Int
The data field holds a complex number encoding a dimension value.
Value: 5
TYPE_FIRST_COLOR_INT
static val TYPE_FIRST_COLOR_INT: Int
Identifies the start of integer values that were specified as color constants (starting with '#').
Value: 28
TYPE_FIRST_INT
static val TYPE_FIRST_INT: 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.
Value: 16
TYPE_FLOAT
static val TYPE_FLOAT: Int
The data field holds an IEEE 754 floating point number.
Value: 4
TYPE_FRACTION
static val TYPE_FRACTION: Int
The data field holds a complex number encoding a fraction of a container.
Value: 6
TYPE_INT_BOOLEAN
static val TYPE_INT_BOOLEAN: Int
The data field holds 0 or 1 that was originally specified as "false" or "true".
Value: 18
TYPE_INT_COLOR_ARGB4
static val TYPE_INT_COLOR_ARGB4: Int
The data field holds a color that was originally specified as #argb.
Value: 30
TYPE_INT_COLOR_ARGB8
static val TYPE_INT_COLOR_ARGB8: Int
The data field holds a color that was originally specified as #aarrggbb.
Value: 28
TYPE_INT_COLOR_RGB4
static val TYPE_INT_COLOR_RGB4: Int
The data field holds a color that was originally specified as #rgb.
Value: 31
TYPE_INT_COLOR_RGB8
static val TYPE_INT_COLOR_RGB8: Int
The data field holds a color that was originally specified as #rrggbb.
Value: 29
TYPE_INT_DEC
static val TYPE_INT_DEC: Int
The data field holds a number that was originally specified in decimal.
Value: 16
TYPE_INT_HEX
static val TYPE_INT_HEX: Int
The data field holds a number that was originally specified in hexadecimal (0xn).
Value: 17
TYPE_LAST_COLOR_INT
static val TYPE_LAST_COLOR_INT: Int
Identifies the end of integer values that were specified as color constants.
Value: 31
TYPE_LAST_INT
static val TYPE_LAST_INT: Int
Identifies the end of plain integer values.
Value: 31
TYPE_REFERENCE
static val TYPE_REFERENCE: Int
The data field holds a resource identifier.
Value: 1
TYPE_STRING
static val TYPE_STRING: Int
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.
Value: 3
Public constructors
TypedValue
TypedValue()
Public methods
applyDimension
open static fun applyDimension(
unit: Int,
value: Float,
metrics: DisplayMetrics!
): Float
Converts an unpacked complex data value holding a dimension to its final floating point pixel value. The two parameters unit and value are as in TYPE_DIMENSION
.
To convert the other way, e.g. from pixels to DP, use deriveDimension(int,float,android.util.DisplayMetrics)
.
Parameters | |
---|---|
unit |
Int: The unit to convert from. Value is android.util.TypedValue#COMPLEX_UNIT_PX , android.util.TypedValue#COMPLEX_UNIT_DIP , android.util.TypedValue#COMPLEX_UNIT_SP , android.util.TypedValue#COMPLEX_UNIT_PT , android.util.TypedValue#COMPLEX_UNIT_IN , or android.util.TypedValue#COMPLEX_UNIT_MM |
value |
Float: The value to apply the unit to. |
metrics |
DisplayMetrics!: Current display metrics to use in the conversion -- supplies display density and scaling information. |
Return | |
---|---|
Float |
The equivalent pixel value—i.e. the complex floating point value multiplied by the appropriate metrics depending on its unit—or zero if unit is not valid. |
coerceToString
fun coerceToString(): CharSequence!
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.
Return | |
---|---|
CharSequence! |
CharSequence The coerced string value. If the value is null or the type is not known, null is returned. |
coerceToString
static fun coerceToString(
type: Int,
data: Int
): String!
Perform type conversion as per coerceToString()
on an explicitly supplied type and data.
Parameters | |
---|---|
type |
Int: The data type identifier. |
data |
Int: The data value. |
Return | |
---|---|
String! |
String The coerced string value. If the value is null or the type is not known, null is returned. |
complexToDimension
open static fun complexToDimension(
data: Int,
metrics: DisplayMetrics!
): Float
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 |
Int: A complex data value holding a unit, magnitude, and mantissa. |
metrics |
DisplayMetrics!: Current display metrics to use in the conversion -- supplies display density and scaling information. |
Return | |
---|---|
Float |
The complex floating point value multiplied by the appropriate metrics depending on its unit. |
complexToDimensionPixelOffset
open static fun complexToDimensionPixelOffset(
data: Int,
metrics: DisplayMetrics!
): Int
Converts a complex data value holding a dimension to its final value as an integer pixel offset. This is the same as complexToDimension
, 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 |
Int: A complex data value holding a unit, magnitude, and mantissa. |
metrics |
DisplayMetrics!: Current display metrics to use in the conversion -- supplies display density and scaling information. |
Return | |
---|---|
Int |
The number of pixels specified by the data and its desired multiplier and units. |
complexToDimensionPixelSize
open static fun complexToDimensionPixelSize(
data: Int,
metrics: DisplayMetrics!
): Int
Converts a complex data value holding a dimension to its final value as an integer pixel size. This is the same as complexToDimension
, 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 |
Int: A complex data value holding a unit, magnitude, and mantissa. |
metrics |
DisplayMetrics!: Current display metrics to use in the conversion -- supplies display density and scaling information. |
Return | |
---|---|
Int |
The number of pixels specified by the data and its desired multiplier and units. |
complexToFloat
open static fun complexToFloat(complex: Int): Float
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 |
Int: A complex data value. |
Return | |
---|---|
Float |
A floating point value corresponding to the complex data. |
complexToFraction
open static fun complexToFraction(
data: Int,
base: Float,
pbase: Float
): Float
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 |
Int: A complex data value holding a unit, magnitude, and mantissa. |
base |
Float: The base value of this fraction. In other words, a standard fraction is multiplied by this value. |
pbase |
Float: The parent base value of this fraction. In other words, a parent fraction (nn%p) is multiplied by this value. |
Return | |
---|---|
Float |
The complex floating point value multiplied by the appropriate base value depending on its unit. |
convertDimensionToPixels
open static fun convertDimensionToPixels(
unitToConvertFrom: Int,
value: Float,
metrics: DisplayMetrics
): Float
Converts a dimension value to raw pixels, e.g. DP to PX.
This is just an alias of applyDimension(int,float,android.util.DisplayMetrics)
with an easier-to-find name.
Parameters | |
---|---|
unitToConvertFrom |
Int: The unit to convert from. Value is android.util.TypedValue#COMPLEX_UNIT_PX , android.util.TypedValue#COMPLEX_UNIT_DIP , android.util.TypedValue#COMPLEX_UNIT_SP , android.util.TypedValue#COMPLEX_UNIT_PT , android.util.TypedValue#COMPLEX_UNIT_IN , or android.util.TypedValue#COMPLEX_UNIT_MM |
value |
Float: The dimension value to apply the unit to. |
metrics |
DisplayMetrics: Current display metrics to use in the conversion -- supplies display density and scaling information. This value cannot be null . |
Return | |
---|---|
Float |
The equivalent pixel value—i.e. the complex floating point value multiplied by the appropriate metrics depending on its unit—or zero if unit is not valid. |
convertPixelsToDimension
open static fun convertPixelsToDimension(
unitToConvertTo: Int,
pixelValue: Float,
metrics: DisplayMetrics
): Float
Converts a pixel value to the given dimension, e.g. PX to DP.
This is just an alias of deriveDimension(int,float,android.util.DisplayMetrics)
with an easier-to-find name.
Parameters | |
---|---|
unitToConvertTo |
Int: The unit to convert to. Value is android.util.TypedValue#COMPLEX_UNIT_PX , android.util.TypedValue#COMPLEX_UNIT_DIP , android.util.TypedValue#COMPLEX_UNIT_SP , android.util.TypedValue#COMPLEX_UNIT_PT , android.util.TypedValue#COMPLEX_UNIT_IN , or android.util.TypedValue#COMPLEX_UNIT_MM |
pixelValue |
Float: The raw pixels value to convert from. |
metrics |
DisplayMetrics: Current display metrics to use in the conversion -- supplies display density and scaling information. This value cannot be null . |
Return | |
---|---|
Float |
A dimension value equivalent to the given number of pixels |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if unitToConvertTo is not valid. |
deriveDimension
open static fun deriveDimension(
unitToConvertTo: Int,
pixelValue: Float,
metrics: DisplayMetrics
): Float
Converts a pixel value to the given dimension, e.g. PX to DP.
This is the inverse of applyDimension(int,float,android.util.DisplayMetrics)
Parameters | |
---|---|
unitToConvertTo |
Int: The unit to convert to. Value is android.util.TypedValue#COMPLEX_UNIT_PX , android.util.TypedValue#COMPLEX_UNIT_DIP , android.util.TypedValue#COMPLEX_UNIT_SP , android.util.TypedValue#COMPLEX_UNIT_PT , android.util.TypedValue#COMPLEX_UNIT_IN , or android.util.TypedValue#COMPLEX_UNIT_MM |
pixelValue |
Float: The raw pixels value to convert from. |
metrics |
DisplayMetrics: Current display metrics to use in the conversion -- supplies display density and scaling information. This value cannot be null . |
Return | |
---|---|
Float |
A dimension value equivalent to the given number of pixels |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if unitToConvertTo is not valid. |
getComplexUnit
open fun getComplexUnit(): Int
Return the complex unit type for this value. For example, a dimen type with value 12sp will return COMPLEX_UNIT_SP
. Only use for values whose type is TYPE_DIMENSION
.
Return | |
---|---|
Int |
The complex unit type. |
getDimension
open fun getDimension(metrics: DisplayMetrics!): Float
Return the data for this value as a dimension. Only use for values whose type is TYPE_DIMENSION
.
Parameters | |
---|---|
metrics |
DisplayMetrics!: Current display metrics to use in the conversion -- supplies display density and scaling information. |
Return | |
---|---|
Float |
The complex floating point value multiplied by the appropriate metrics depending on its unit. |
getFloat
fun getFloat(): Float
Return the data for this value as a float. Only use for values whose type is TYPE_FLOAT
.
getFraction
open fun getFraction(
base: Float,
pbase: Float
): Float
Return the data for this value as a fraction. Only use for values whose type is TYPE_FRACTION
.
Parameters | |
---|---|
base |
Float: The base value of this fraction. In other words, a standard fraction is multiplied by this value. |
pbase |
Float: The parent base value of this fraction. In other words, a parent fraction (nn%p) is multiplied by this value. |
Return | |
---|---|
Float |
The complex floating point value multiplied by the appropriate base value depending on its unit. |
isColorType
open fun isColorType(): Boolean
Determine if a value is a color. This works by comparing type
to TYPE_FIRST_COLOR_INT
and TYPE_LAST_COLOR_INT
.
Return | |
---|---|
Boolean |
true if this value is a color |
toString
open fun toString(): String
Return | |
---|---|
String |
a string representation of the object. |
Properties
assetCookie
var assetCookie: Int
Additional information about where the value came from; only set for strings.
changingConfigurations
var changingConfigurations: Int
If the value came from a resource, these are the configurations for which its contents can change.
For example, if a resource has a value defined for the -land resource qualifier, this field will have the android.content.pm.ActivityInfo#CONFIG_ORIENTATION
bit set.
Value is either
0
or a combination of android.content.pm.ActivityInfo#CONFIG_MCC
, android.content.pm.ActivityInfo#CONFIG_MNC
, android.content.pm.ActivityInfo#CONFIG_LOCALE
, android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN
, android.content.pm.ActivityInfo#CONFIG_KEYBOARD
, android.content.pm.ActivityInfo#CONFIG_KEYBOARD_HIDDEN
, android.content.pm.ActivityInfo#CONFIG_NAVIGATION
, android.content.pm.ActivityInfo#CONFIG_ORIENTATION
, android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
, android.content.pm.ActivityInfo#CONFIG_UI_MODE
, android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE
, android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE
, android.content.pm.ActivityInfo#CONFIG_DENSITY
, android.content.pm.ActivityInfo#CONFIG_LAYOUT_DIRECTION
, android.content.pm.ActivityInfo#CONFIG_COLOR_MODE
, android.content.pm.ActivityInfo#CONFIG_FONT_SCALE
, and android.content.pm.ActivityInfo#CONFIG_GRAMMATICAL_GENDER
See Also
android.content.pm.ActivityInfo#CONFIG_MCC
android.content.pm.ActivityInfo#CONFIG_MNC
android.content.pm.ActivityInfo#CONFIG_LOCALE
android.content.pm.ActivityInfo#CONFIG_TOUCHSCREEN
android.content.pm.ActivityInfo#CONFIG_KEYBOARD
android.content.pm.ActivityInfo#CONFIG_KEYBOARD_HIDDEN
android.content.pm.ActivityInfo#CONFIG_NAVIGATION
android.content.pm.ActivityInfo#CONFIG_ORIENTATION
android.content.pm.ActivityInfo#CONFIG_SCREEN_LAYOUT
android.content.pm.ActivityInfo#CONFIG_UI_MODE
android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE
android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE
android.content.pm.ActivityInfo#CONFIG_DENSITY
android.content.pm.ActivityInfo#CONFIG_LAYOUT_DIRECTION
android.content.pm.ActivityInfo#CONFIG_COLOR_MODE
density
var density: Int
If the Value came from a resource, this holds the corresponding pixel density.
resourceId
var resourceId: Int
If Value came from a resource, this holds the corresponding resource id.
sourceResourceId
var sourceResourceId: Int
If the Value came from a style resource or a layout resource (set in an XML layout), this holds the corresponding style or layout resource id against which the attribute was resolved.
type
var type: Int
The type held by this value, as defined by the constants here. This tells you how to interpret the other fields in the object.