belongs to Maven artifact androidx.core:core:1.0.0-alpha1

IconCompat

public class IconCompat
extends Object

java.lang.Object
   ↳ androidx.core.graphics.drawable.IconCompat


Helper for accessing features in Icon.

Summary

Constants

int TYPE_UNKOWN

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

Public methods

static IconCompat createFromBundle(Bundle bundle)

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

static IconCompat createFromIcon(Icon icon)

Creates an IconCompat from an Icon.

static IconCompat createWithAdaptiveBitmap(Bitmap bits)

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

static IconCompat createWithBitmap(Bitmap bits)

Create an Icon pointing to a bitmap in memory.

static IconCompat createWithContentUri(String uri)

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

static IconCompat createWithContentUri(Uri uri)

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

static IconCompat createWithData(byte[] data, int offset, int length)

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

static IconCompat createWithResource(Context context, int resId)

Create an Icon pointing to a drawable resource.

int getResId()

Gets the resource id used to create this icon.

static int getResId(Icon icon)

Gets the resource used to create this icon.

String getResPackage()

Gets the package used to create this icon.

static String getResPackage(Icon icon)

Gets the package used to create this icon.

static int getType(Icon icon)

Gets the type of the icon provided.

int getType()

Gets the type of the icon provided.

Uri getUri(Icon icon)

Gets the uri used to create this icon.

Uri getUri()

Gets the uri used to create this icon.

Drawable loadDrawable(Context context)

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

IconCompat setTint(int tint)

Store a color to use whenever this Icon is drawn.

IconCompat setTintList(ColorStateList tintList)

Store a color to use whenever this Icon is drawn.

IconCompat setTintMode(PorterDuff.Mode mode)

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

Bundle toBundle()

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

Icon toIcon()

Convert this compat object to Icon object.

String toString()

Inherited methods

Constants

TYPE_UNKOWN

int TYPE_UNKOWN

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

See also:

Constant Value: -1 (0xffffffff)

Public methods

createFromBundle

IconCompat createFromBundle (Bundle bundle)

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

Parameters
bundle Bundle

Returns
IconCompat

createFromIcon

IconCompat createFromIcon (Icon icon)

Creates an IconCompat from an Icon.

Parameters
icon Icon

Returns
IconCompat

createWithAdaptiveBitmap

IconCompat createWithAdaptiveBitmap (Bitmap bits)

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

Parameters
bits Bitmap: A valid Bitmap object

Returns
IconCompat

createWithBitmap

IconCompat createWithBitmap (Bitmap bits)

Create an Icon pointing to a bitmap in memory.

Parameters
bits Bitmap: A valid Bitmap object

Returns
IconCompat

createWithContentUri

IconCompat createWithContentUri (String uri)

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

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

Returns
IconCompat

createWithContentUri

IconCompat createWithContentUri (Uri uri)

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

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

Returns
IconCompat

createWithData

IconCompat createWithData (byte[] data, 
                int offset, 
                int length)

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

Parameters
data byte: Byte array storing compressed bitmap data of a type that BitmapFactory can decode (see Bitmap.CompressFormat).

offset int: Offset into data at which the bitmap data starts

length int: Length of the bitmap data

Returns
IconCompat

createWithResource

IconCompat createWithResource (Context context, 
                int resId)

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 int: ID of the drawable resource

Returns
IconCompat

getResId

int getResId ()

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.

Returns
int

getResId

int getResId (Icon icon)

Gets the resource 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. Returns 0 if the id cannot be gotten.

Parameters
icon Icon

Returns
int

getResPackage

String getResPackage ()

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.

Returns
String

getResPackage

String getResPackage (Icon icon)

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. Returns null when the value cannot be gotten.

Parameters
icon Icon

Returns
String

getType

int getType (Icon icon)

Gets the type of the icon provided.

Note that new types may be added later, so callers should guard against other types being returned. Returns TYPE_UNKOWN when the type cannot be determined.

Parameters
icon Icon

Returns
int

getType

int getType ()

Gets the type of the icon provided.

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

Returns
int

getUri

Uri getUri (Icon icon)

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. Returns null if the uri cannot be gotten.

Parameters
icon Icon

Returns
Uri

getUri

Uri getUri ()

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.

Returns
Uri

loadDrawable

Drawable loadDrawable (Context context)

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.

setTint

IconCompat setTint (int tint)

Store a color to use whenever this Icon is drawn.

Parameters
tint int: a color, as in Drawable.setTint(int)

Returns
IconCompat this same object, for use in chained construction

setTintList

IconCompat setTintList (ColorStateList tintList)

Store a color to use whenever this Icon is drawn.

Parameters
tintList ColorStateList: as in Drawable.setTintList(ColorStateList), null to remove tint

Returns
IconCompat this same object, for use in chained construction

setTintMode

IconCompat setTintMode (PorterDuff.Mode mode)

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

Parameters
mode PorterDuff.Mode: a blending mode, as in Drawable.setTintMode(PorterDuff.Mode), may be null

Returns
IconCompat this same object, for use in chained construction

toBundle

Bundle toBundle ()

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

Returns
Bundle

toIcon

Icon toIcon ()

Convert this compat object to Icon object.

Returns
Icon Icon object

toString

String toString ()

Returns
String