IconCompat

open class IconCompat : CustomVersionedParcelable
androidx.core.graphics.drawable.IconCompat

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

Summary

Constants

static Int

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

Public methods

open static IconCompat?
createFromBundle(@NonNull bundle: Bundle)

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

open static IconCompat?
createFromIcon(@NonNull context: Context, @NonNull icon: Icon)

Creates an IconCompat from an Icon.

open static IconCompat!

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

open static IconCompat!

Create an Icon pointing to a bitmap in memory.

open static IconCompat!

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

open static IconCompat!

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

open static IconCompat!
createWithData(data: ByteArray!, offset: Int, length: Int)

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

open static IconCompat!
createWithResource(context: Context!, @DrawableRes resId: Int)

Create an Icon pointing to a drawable resource.

open Int

Gets the resource id used to create this icon.

open String

Gets the package used to create this icon.

open Int

Gets the type of the icon provided.

open Uri

Gets the uri used to create this icon.

open Drawable!
loadDrawable(context: Context!)

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

open Unit

open Unit

open IconCompat!
setTint(tint: Int)

Store a color to use whenever this Icon is drawn.

open IconCompat!

Store a color to use whenever this Icon is drawn.

open IconCompat!
setTintMode(mode: Mode!)

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

open Bundle!

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

open Icon!

Convert this compat object to Icon object.

open String

Constants

TYPE_UNKNOWN

static val TYPE_UNKNOWN: Int

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

Value: -1

Public methods

createFromBundle

@Nullable open static fun createFromBundle(@NonNull bundle: Bundle): IconCompat?

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

createFromIcon

@Nullable open static fun createFromIcon(@NonNull context: Context, @NonNull icon: Icon): IconCompat?

Creates an IconCompat from an Icon.

createWithAdaptiveBitmap

open 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

createWithBitmap

open static fun createWithBitmap(bits: Bitmap!): IconCompat!

Create an Icon pointing to a bitmap in memory.

Parameters
bits Bitmap!: A valid android.graphics.Bitmap object

createWithContentUri

open 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

open 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

open 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 ByteArray!: Offset into data at which the bitmap data starts
length ByteArray!: Length of the bitmap data

createWithResource

open static fun createWithResource(context: Context!, @DrawableRes resId: 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 Context!: ID of the drawable resource

getResId

@IdRes open fun getResId(): Int

Gets the 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

@NonNull open 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

open 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

@NonNull open 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

open 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.
Return
Drawable!: A fresh instance of a drawable for this image, yours to keep.

onPostParceling

open fun onPostParceling(): Unit

onPreParceling

open fun onPreParceling(isStream: Boolean): Unit

setTint

open fun setTint(tint: Int): IconCompat!

Store a color to use whenever this Icon is drawn.

Parameters
tint Int: a color, as in Drawable#setTint(int)
Return
IconCompat!: this same object, for use in chained construction

setTintList

open fun setTintList(tintList: ColorStateList!): IconCompat!

Store a color to use whenever this Icon is drawn.

Parameters
tintList ColorStateList!: as in Drawable#setTintList(ColorStateList), null to remove tint
Return
IconCompat!: this same object, for use in chained construction

setTintMode

open fun setTintMode(mode: Mode!): IconCompat!

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

Parameters
mode Mode!: a blending mode, as in Drawable#setTintMode(PorterDuff.Mode), may be null
Return
IconCompat!: this same object, for use in chained construction

toBundle

open fun toBundle(): Bundle!

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

toIcon

open fun toIcon(): Icon!

Convert this compat object to Icon object.

Return
Icon!: Icon object

toString

@NonNull open fun toString(): String