Formatter
class Formatter
kotlin.Any | |
↳ | android.text.format.Formatter |
Utility class to aid in formatting common values that are not covered by the java.util.Formatter
class in java.util
Summary
Public constructors | |
---|---|
Public methods | |
---|---|
static String! |
formatFileSize(context: Context?, sizeBytes: Long) Formats a content size to be in the form of bytes, kilobytes, megabytes, etc. |
static String! |
formatIpAddress(ipv4Address: Int) Returns a string in the canonical IPv4 format ###. |
static String! |
formatShortFileSize(context: Context?, sizeBytes: Long) Like |
Public constructors
Formatter
Formatter()
Public methods
formatFileSize
static fun formatFileSize(
context: Context?,
sizeBytes: Long
): String!
Formats a content size to be in the form of bytes, kilobytes, megabytes, etc.
As of O, the prefixes are used in their standard meanings in the SI system, so kB = 1000 bytes, MB = 1,000,000 bytes, etc.
In android.os.Build.VERSION_CODES#N
and earlier, powers of 1024 are used instead, with KB = 1024 bytes, MB = 1,048,576 bytes, etc.
If the context has a right-to-left locale, the returned string is wrapped in bidi formatting characters to make sure it's displayed correctly if inserted inside a right-to-left string. (This is useful in cases where the unit strings, like "MB", are left-to-right, but the locale is right-to-left.)
Parameters | |
---|---|
context |
Context?: Context to use to load the localized units This value may be null . |
sizeBytes |
Long: size value to be formatted, in bytes |
Return | |
---|---|
String! |
formatted string with the number |
formatIpAddress
static funformatIpAddress(ipv4Address: Int): String!
Deprecated: Use java.net.InetAddress#getHostAddress()
, which supports both IPv4 and IPv6 addresses. This method does not support IPv6 addresses.
Returns a string in the canonical IPv4 format ###.###.###.### from a packed integer containing the IP address. The IPv4 address is expected to be in little-endian format (LSB first). That is, 0x01020304 will return "4.3.2.1".
formatShortFileSize
static fun formatShortFileSize(
context: Context?,
sizeBytes: Long
): String!
Like formatFileSize
, but trying to generate shorter numbers (showing fewer digits of precision).
Parameters | |
---|---|
context |
Context?: This value may be null . |