IconCompat

Added in 1.1.0

class IconCompat : VersionedParcelable


Helper for accessing features in android.graphics.drawable.Icon.

Summary

Constants

const Int

An icon that was created using createWithAdaptiveBitmap.

const Int

An icon that was created using createWithBitmap.

const Int

An icon that was created using createWithData.

const Int

An icon that was created using createWithResource.

const Int

Value returned when the type of an Icon cannot be determined.

const Int

An icon that was created using createWithContentUri.

const Int

An icon that was created using createWithAdaptiveBitmapContentUri.

Public functions

java-static IconCompat?

Extracts an icon from a bundle that was added using toBundle.

java-static IconCompat?
@RequiresApi(value = 23)
createFromIcon(context: Context, icon: Icon)

Creates an IconCompat from an Icon.

java-static IconCompat

Create an Icon pointing to a bitmap in memory that follows the icon design guideline defined by android.graphics.drawable.AdaptiveIconDrawable.

java-static IconCompat

Create an Icon pointing to an image file specified by URI.

java-static IconCompat

Create an Icon pointing to an image file specified by URI.

java-static IconCompat

Create an Icon pointing to a bitmap in memory.

java-static IconCompat

Create an Icon pointing to an image file specified by URI.

java-static IconCompat

Create an Icon pointing to an image file specified by URI.

java-static IconCompat
createWithData(data: ByteArray, offset: Int, length: Int)

Create an Icon pointing to a compressed bitmap stored in a byte array.

java-static IconCompat

Create an Icon pointing to a drawable resource.

@DrawableRes Int

Gets the drawable resource id used to create this icon.

String

Gets the package used to create this icon.

Int

Gets the type of the icon provided.

Uri

Gets the uri used to create this icon.

Drawable?

Returns a Drawable that can be used to draw the image inside this Icon, constructing it if necessary.

Unit

Called immediately after this object has been deserialized, can be used to handle any custom fields that cannot be easily annotated.

Unit

Called immediately before this object is going to be serialized, can be used to handle any custom fields that cannot be easily annotated.

IconCompat

Store a color to use whenever this Icon is drawn.

IconCompat

Store a color to use whenever this Icon is drawn.

IconCompat

Store a blending mode to use whenever this Icon is drawn.

Bundle

Adds this Icon to a Bundle that can be read back with the same parameters to createFromBundle.

Icon
@RequiresApi(value = 23)
toIcon()

This function is deprecated.

Use toIcon to generate the Icon object.

Icon
@RequiresApi(value = 23)
toIcon(context: Context?)

Convert this compat object to Icon object.

String

Constants

TYPE_ADAPTIVE_BITMAP

Added in 1.3.0
const val TYPE_ADAPTIVE_BITMAP = 5: Int

An icon that was created using createWithAdaptiveBitmap.

TYPE_BITMAP

Added in 1.3.0
const val TYPE_BITMAP = 1: Int

An icon that was created using createWithBitmap.

TYPE_DATA

Added in 1.3.0
const val TYPE_DATA = 3: Int

An icon that was created using createWithData.

TYPE_RESOURCE

Added in 1.3.0
const val TYPE_RESOURCE = 2: Int

An icon that was created using createWithResource.

TYPE_UNKNOWN

Added in 1.1.0
const val TYPE_UNKNOWN = -1: Int

Value returned when the type of an Icon cannot be determined.

TYPE_URI

Added in 1.3.0
const val TYPE_URI = 4: Int

An icon that was created using createWithContentUri.

TYPE_URI_ADAPTIVE_BITMAP

Added in 1.3.0
const val TYPE_URI_ADAPTIVE_BITMAP = 6: Int

An icon that was created using createWithAdaptiveBitmapContentUri.

Public functions

createFromBundle

Added in 1.1.0
java-static fun createFromBundle(bundle: Bundle): IconCompat?

Extracts an icon from a bundle that was added using toBundle.

createFromIcon

Added in 1.1.0
@RequiresApi(value = 23)
java-static fun createFromIcon(context: Context, icon: Icon): IconCompat?

Creates an IconCompat from an Icon.

createWithAdaptiveBitmap

Added in 1.1.0
java-static fun createWithAdaptiveBitmap(bits: Bitmap): IconCompat

Create an Icon pointing to a bitmap in memory that follows the icon design guideline defined by android.graphics.drawable.AdaptiveIconDrawable.

Parameters
bits: Bitmap

A valid android.graphics.Bitmap object

createWithAdaptiveBitmapContentUri

Added in 1.3.0
java-static fun createWithAdaptiveBitmapContentUri(uri: String): IconCompat

Create an Icon pointing to an image file specified by URI. Image file should follow the icon design guideline defined by AdaptiveIconDrawable.

Parameters
uri: String

A uri referring to local content:// or file:// image data.

createWithAdaptiveBitmapContentUri

Added in 1.3.0
java-static fun createWithAdaptiveBitmapContentUri(uri: Uri): IconCompat

Create an Icon pointing to an image file specified by URI. Image file should follow the icon design guideline defined by AdaptiveIconDrawable.

Parameters
uri: Uri

A uri referring to local content:// or file:// image data.

createWithBitmap

Added in 1.1.0
java-static fun createWithBitmap(bits: Bitmap): IconCompat

Create an Icon pointing to a bitmap in memory.

Parameters
bits: Bitmap

A valid android.graphics.Bitmap object

See also
createWithBitmap

createWithContentUri

Added in 1.1.0
java-static fun createWithContentUri(uri: String): IconCompat

Create an Icon pointing to an image file specified by URI.

Parameters
uri: String

A uri referring to local content:// or file:// image data.

createWithContentUri

Added in 1.1.0
java-static fun createWithContentUri(uri: Uri): IconCompat

Create an Icon pointing to an image file specified by URI.

Parameters
uri: Uri

A uri referring to local content:// or file:// image data.

createWithData

Added in 1.1.0
java-static fun createWithData(data: ByteArray, offset: Int, length: Int): IconCompat

Create an Icon pointing to a compressed bitmap stored in a byte array.

Parameters
data: ByteArray

Byte array storing compressed bitmap data of a type that android.graphics.BitmapFactory can decode (see android.graphics.Bitmap.CompressFormat).

offset: Int

Offset into data at which the bitmap data starts

length: Int

Length of the bitmap data

See also
createWithData

createWithResource

Added in 1.1.0
java-static fun createWithResource(context: Context, resId: @DrawableRes Int): IconCompat

Create an Icon pointing to a drawable resource.

Parameters
context: Context

The context for the application whose resources should be used to resolve the given resource ID.

resId: @DrawableRes Int

ID of the drawable resource

getResId

Added in 1.1.0
fun getResId(): @DrawableRes Int

Gets the drawable resource id used to create this icon.

Only valid for icons of type TYPE_RESOURCE. Note: This resource may not be available if the application changes at all, and it is up to the caller to ensure safety if this resource is re-used and/or persisted.

getResPackage

Added in 1.1.0
fun getResPackage(): String

Gets the package used to create this icon.

Only valid for icons of type TYPE_RESOURCE. Note: This package may not be available if referenced in the future, and it is up to the caller to ensure safety if this package is re-used and/or persisted.

getType

Added in 1.1.0
fun getType(): Int

Gets the type of the icon provided.

Note that new types may be added later, so callers should guard against other types being returned.

getUri

Added in 1.1.0
fun getUri(): Uri

Gets the uri used to create this icon.

Only valid for icons of type TYPE_URI. Note: This uri may not be available in the future, and it is up to the caller to ensure safety if this uri is re-used and/or persisted.

loadDrawable

Added in 1.1.0
fun loadDrawable(context: Context): Drawable?

Returns a Drawable that can be used to draw the image inside this Icon, constructing it if necessary.

Parameters
context: Context

Context in which to load the drawable; used to access Resources, for example.

Returns
Drawable?

A fresh instance of a drawable for this image, yours to keep.

onPostParceling

Added in 1.6.0
fun onPostParceling(): Unit

Called immediately after this object has been deserialized, can be used to handle any custom fields that cannot be easily annotated.

onPreParceling

Added in 1.6.0
fun onPreParceling(isStream: Boolean): Unit

Called immediately before this object is going to be serialized, can be used to handle any custom fields that cannot be easily annotated.

setTint

Added in 1.1.0
fun setTint(tint: @ColorInt Int): IconCompat

Store a color to use whenever this Icon is drawn.

Parameters
tint: @ColorInt Int

a color, as in setTint

Returns
IconCompat

this same object, for use in chained construction

setTintList

Added in 1.1.0
fun setTintList(tintList: ColorStateList?): IconCompat

Store a color to use whenever this Icon is drawn.

Parameters
tintList: ColorStateList?

as in setTintList, null to remove tint

Returns
IconCompat

this same object, for use in chained construction

setTintMode

Added in 1.1.0
fun setTintMode(mode: PorterDuff.Mode?): IconCompat

Store a blending mode to use whenever this Icon is drawn.

Parameters
mode: PorterDuff.Mode?

a blending mode, as in setTintMode, may be null

Returns
IconCompat

this same object, for use in chained construction

toBundle

Added in 1.1.0
fun toBundle(): Bundle

Adds this Icon to a Bundle that can be read back with the same parameters to createFromBundle.

toIcon

Added in 1.1.0
Deprecated in 1.3.0
@RequiresApi(value = 23)
fun toIcon(): Icon

toIcon

Added in 1.3.0
@RequiresApi(value = 23)
fun toIcon(context: Context?): Icon

Convert this compat object to Icon object.

Returns
Icon

Icon object

toString

fun toString(): String