added in version 1.0.0
belongs to Maven artifact androidx.core:core:1.0.0-beta01

IconCompat

public class IconCompat
extends CustomVersionedParcelable

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


Helper for accessing features in Icon.

Summary

Constants

int TYPE_UNKNOWN

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(Context context, 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.

String getResPackage()

Gets the package used to create this icon.

int getType()

Gets the type of the icon provided.

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.

void onPostParceling()
void onPreParceling(boolean isStream)
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_UNKNOWN

added in version 1.0.0
public static final int TYPE_UNKNOWN

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

Constant Value: -1 (0xffffffff)

Public methods

createFromBundle

added in version 1.0.0
public static IconCompat createFromBundle (Bundle bundle)

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

Parameters
bundle Bundle

Returns
IconCompat

createFromIcon

added in version 1.0.0
public static IconCompat createFromIcon (Context context, 
                Icon icon)

Creates an IconCompat from an Icon.

Parameters
context Context

icon Icon

Returns
IconCompat

createWithAdaptiveBitmap

added in version 1.0.0
public static 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

added in version 1.0.0
public static IconCompat createWithBitmap (Bitmap bits)

Create an Icon pointing to a bitmap in memory.

Parameters
bits Bitmap: A valid Bitmap object

Returns
IconCompat

createWithContentUri

added in version 1.0.0
public static 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

added in version 1.0.0
public static 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

added in version 1.0.0
public static 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

added in version 1.0.0
public static 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

added in version 1.0.0
public 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

getResPackage

added in version 1.0.0
public 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

getType

added in version 1.0.0
public 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

added in version 1.0.0
public 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

added in version 1.0.0
public 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.

onPostParceling

public void onPostParceling ()

onPreParceling

public void onPreParceling (boolean isStream)

Parameters
isStream boolean

setTint

added in version 1.0.0
public 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

added in version 1.0.0
public 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

added in version 1.0.0
public 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

added in version 1.0.0
public Bundle toBundle ()

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

Returns
Bundle

toIcon

added in version 1.0.0
public Icon toIcon ()

Convert this compat object to Icon object.

Returns
Icon Icon object

toString

public String toString ()

Returns
String