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
|
Constants | |
---|---|
int |
TYPE_ADAPTIVE_BITMAP
An icon that was created using |
int |
TYPE_BITMAP
An icon that was created using |
int |
TYPE_DATA
An icon that was created using |
int |
TYPE_RESOURCE
An icon that was created using |
int |
TYPE_URI
An icon that was created using |
int |
TYPE_URI_ADAPTIVE_BITMAP
An icon that was created using |
Inherited constants |
---|
Fields | |
---|---|
public
static
final
Creator<Icon> |
CREATOR
|
Public methods | |
---|---|
static
Icon
|
createWithAdaptiveBitmap(Bitmap bits)
Create an Icon pointing to a bitmap in memory that follows the icon design guideline defined
by |
static
Icon
|
createWithAdaptiveBitmapContentUri(String uri)
Create an Icon pointing to an image file specified by URI. |
static
Icon
|
createWithAdaptiveBitmapContentUri(Uri uri)
Create an Icon pointing to an image file specified by URI. |
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 |
int
|
getResId()
Gets the resource 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
|
loadDrawableAsync(Context context, Message andThen)
Invokes |
void
|
loadDrawableAsync(Context context, Icon.OnDrawableLoadedListener listener, Handler handler)
Invokes |
Icon
|
setTint(int tint)
Store a color to use whenever this Icon is drawn. |
Icon
|
setTintBlendMode(BlendMode mode)
Store a blending mode 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 | |
---|---|
Constants
TYPE_ADAPTIVE_BITMAP
public static final int TYPE_ADAPTIVE_BITMAP
An icon that was created using Icon#createWithAdaptiveBitmap
.
See also:
Constant Value: 5 (0x00000005)
TYPE_BITMAP
public static final int TYPE_BITMAP
An icon that was created using Icon#createWithBitmap(Bitmap)
.
See also:
Constant Value: 1 (0x00000001)
TYPE_DATA
public static final int TYPE_DATA
An icon that was created using Icon#createWithData(byte[], int, int)
.
See also:
Constant Value: 3 (0x00000003)
TYPE_RESOURCE
public static final int TYPE_RESOURCE
An icon that was created using Icon#createWithResource
.
See also:
Constant Value: 2 (0x00000002)
TYPE_URI
public static final int TYPE_URI
An icon that was created using Icon#createWithContentUri
or Icon#createWithFilePath(String)
.
See also:
Constant Value: 4 (0x00000004)
TYPE_URI_ADAPTIVE_BITMAP
public static final int TYPE_URI_ADAPTIVE_BITMAP
An icon that was created using Icon#createWithAdaptiveBitmapContentUri
.
See also:
Constant Value: 6 (0x00000006)
Fields
Public methods
createWithAdaptiveBitmap
public static Icon 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 | |
---|---|
Icon |
This value cannot be null . |
createWithAdaptiveBitmapContentUri
public static Icon createWithAdaptiveBitmapContentUri (String uri)
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.
This value cannot be null . |
Returns | |
---|---|
Icon |
This value cannot be null . |
createWithAdaptiveBitmapContentUri
public static Icon createWithAdaptiveBitmapContentUri (Uri uri)
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.
This value cannot be null . |
Returns | |
---|---|
Icon |
This value cannot be null . |
createWithBitmap
public static Icon createWithBitmap (Bitmap bits)
Create an Icon pointing to a bitmap in memory.
Parameters | |
---|---|
bits |
Bitmap : A valid Bitmap object |
Returns | |
---|---|
Icon |
This value cannot be null . |
createWithContentUri
public static 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 |
This value cannot be null . |
createWithContentUri
public static 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 |
This value cannot be null . |
createWithData
public static 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 |
This value cannot be null . |
createWithFilePath
public static 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 |
This value cannot be null . |
createWithResource
public static 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 |
This value cannot be null . |
createWithResource
public static 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 |
This value cannot be null . |
describeContents
public int describeContents ()
Parcelable interface
Returns | |
---|---|
int |
a bitmask indicating the set of special object types marshaled
by this Parcelable object instance.
Value is either 0 or CONTENTS_FILE_DESCRIPTOR |
getResId
public int getResId ()
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 | |
---|---|
int |
getResPackage
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 |
This value cannot be null . |
getType
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 |
Value is TYPE_BITMAP , TYPE_RESOURCE , TYPE_DATA , TYPE_URI , TYPE_ADAPTIVE_BITMAP , or TYPE_URI_ADAPTIVE_BITMAP |
getUri
public Uri getUri ()
Gets the uri used to create this icon.
Only valid for icons of type TYPE_URI
and TYPE_URI_ADAPTIVE_BITMAP
.
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 |
This value cannot be null . |
loadDrawable
public 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.
This value may be null . |
loadDrawableAsync
public void loadDrawableAsync (Context context, Message andThen)
Invokes loadDrawable(android.content.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(android.content.Context)
This value cannot be null . |
andThen |
Message : Message to send to its target once the drawable
is available. The obj
property is populated with the Drawable.
This value cannot be null . |
loadDrawableAsync
public void loadDrawableAsync (Context context, Icon.OnDrawableLoadedListener listener, Handler handler)
Invokes loadDrawable(android.content.Context)
on a background thread and notifies the
on the listener
handler
when finished.
Parameters | |
---|---|
context |
Context : Context in which to load the drawable; see
loadDrawable(android.content.Context)
This value cannot be null . |
listener |
Icon.OnDrawableLoadedListener : to be notified when
loadDrawable(android.content.Context) finished |
handler |
Handler : Handler on which to notify the listener |
setTint
public Icon setTint (int tint)
Store a color to use whenever this Icon is drawn.
Parameters | |
---|---|
tint |
int : a color, as in Drawable#setTint(int) |
Returns | |
---|---|
Icon |
this same object, for use in chained construction
This value cannot be null . |
setTintBlendMode
public Icon setTintBlendMode (BlendMode mode)
Store a blending mode to use whenever this Icon is drawn.
Parameters | |
---|---|
mode |
BlendMode : a blending mode, as in Drawable#setTintMode(PorterDuff.Mode) , may be null |
Returns | |
---|---|
Icon |
this same object, for use in chained construction
This value cannot be null . |
setTintList
public Icon 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 | |
---|---|
Icon |
this same object, for use in chained construction
This value cannot be null . |
setTintMode
public 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 Drawable#setTintMode(PorterDuff.Mode) , may be null |
Returns | |
---|---|
Icon |
this same object, for use in chained construction
This value cannot be null . |
toString
public String toString ()
Returns a string representation of the object.
Returns | |
---|---|
String |
a string representation of the object. |
writeToParcel
public 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.
This value cannot be null . |
flags |
int : Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE .
Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE , and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.