Most visited

Recently visited

Added in API level 23

Icon

public final class Icon
extends Object implements Parcelable

java.lang.Object
   ↳ android.graphics.drawable.Icon


An umbrella container for several serializable graphics representations, including Bitmaps, compressed bitmap images (e.g. JPG or PNG), and drawable resources (including vectors). Much ink has been spilled on the best way to load images, and many clients may have different needs when it comes to threading and fetching. This class is therefore focused on encapsulation rather than behavior.

Summary

Nested classes

interface Icon.OnDrawableLoadedListener

Implement this interface to receive a callback when loadDrawableAsync is finished and your Drawable is ready. 

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<Icon> CREATOR

Public methods

static Icon createWithBitmap(Bitmap bits)

Create an Icon pointing to a bitmap in memory.

static Icon createWithContentUri(String uri)

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

static Icon createWithContentUri(Uri uri)

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

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

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

static Icon createWithFilePath(String path)

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

static Icon createWithResource(String resPackage, int resId)

Create an Icon pointing to a drawable resource.

static Icon createWithResource(Context context, int resId)

Create an Icon pointing to a drawable resource.

int describeContents()

Parcelable interface

Drawable loadDrawable(Context context)

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

void loadDrawableAsync(Context context, Message andThen)

Invokes loadDrawable(Context) on the given Handler and then sends andThen to the same Handler when finished.

void loadDrawableAsync(Context context, Icon.OnDrawableLoadedListener listener, Handler handler)

Invokes loadDrawable(Context) on a background thread and notifies the listener on the handler when finished.

Icon setTint(int tint)

Store a color to use whenever this Icon is drawn.

Icon setTintList(ColorStateList tintList)

Store a color to use whenever this Icon is drawn.

Icon setTintMode(PorterDuff.Mode mode)

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

String toString()

Returns a string representation of the object.

void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

Fields

CREATOR

Added in API level 23
Creator<Icon> CREATOR

Public methods

createWithBitmap

Added in API level 23
Icon createWithBitmap (Bitmap bits)

Create an Icon pointing to a bitmap in memory.

Parameters
bits Bitmap: A valid Bitmap object
Returns
Icon

createWithContentUri

Added in API level 23
Icon 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
Icon

createWithContentUri

Added in API level 23
Icon 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
Icon

createWithData

Added in API level 23
Icon 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
Icon

createWithFilePath

Added in API level 23
Icon createWithFilePath (String path)

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

Parameters
path String: A path to a file that contains compressed bitmap data of a type that BitmapFactory can decode.
Returns
Icon

createWithResource

Added in API level 23
Icon createWithResource (String resPackage, 
                int resId)

Create an Icon pointing to a drawable resource.

Parameters
resPackage String: Name of the package containing the resource in question
resId int: ID of the drawable resource
Returns
Icon

createWithResource

Added in API level 23
Icon 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
Icon

describeContents

Added in API level 23
int describeContents ()

Parcelable interface

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

loadDrawable

Added in API level 23
Drawable loadDrawable (Context context)

Returns a Drawable that can be used to draw the image inside this Icon, constructing it if necessary. Depending on the type of image, this may not be something you want to do on the UI thread, so consider using loadDrawableAsync instead.

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.

loadDrawableAsync

Added in API level 23
void loadDrawableAsync (Context context, 
                Message andThen)

Invokes loadDrawable(Context) on the given Handler and then sends andThen to the same Handler when finished.

Parameters
context Context: Context in which to load the drawable; see loadDrawable(Context)
andThen Message: Message to send to its target once the drawable is available. The obj property is populated with the Drawable.

loadDrawableAsync

Added in API level 23
void loadDrawableAsync (Context context, 
                Icon.OnDrawableLoadedListener listener, 
                Handler handler)

Invokes loadDrawable(Context) on a background thread and notifies the listener on the handler when finished.

Parameters
context Context: Context in which to load the drawable; see loadDrawable(Context)
listener Icon.OnDrawableLoadedListener: to be notified when loadDrawable(Context) finished
handler Handler: Handler on which to notify the listener

setTint

Added in API level 23
Icon setTint (int tint)

Store a color to use whenever this Icon is drawn.

Parameters
tint int: a color, as in setTint(int)
Returns
Icon this same object, for use in chained construction

setTintList

Added in API level 23
Icon setTintList (ColorStateList tintList)

Store a color to use whenever this Icon is drawn.

Parameters
tintList ColorStateList: as in setTintList(ColorStateList), null to remove tint
Returns
Icon this same object, for use in chained construction

setTintMode

Added in API level 23
Icon setTintMode (PorterDuff.Mode mode)

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

Parameters
mode PorterDuff.Mode: a blending mode, as in setTintMode(PorterDuff.Mode), may be null
Returns
Icon this same object, for use in chained construction

toString

Added in API level 23
String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
String a string representation of the object.

writeToParcel

Added in API level 23
void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Parameters
dest Parcel: The Parcel in which the object should be written.
flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.

Hooray!