public final class Icon extends Object implements Parcelable
Modifier and Type | Class and Description |
---|---|
static interface |
Icon.OnDrawableLoadedListener
Implement this interface to receive a callback when
loadDrawableAsync
is finished and your Drawable is ready. |
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<Icon> |
CREATOR |
static int |
MIN_ASHMEM_ICON_SIZE |
static int |
TYPE_BITMAP |
static int |
TYPE_DATA |
static int |
TYPE_RESOURCE |
static int |
TYPE_URI |
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Modifier and Type | Method and Description |
---|---|
void |
convertToAshmem()
Puts the memory used by this instance into Ashmem memory, if possible.
|
static Icon |
createFromStream(InputStream stream)
Create an Icon from the specified stream.
|
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(Context context,
int resId)
Create an Icon pointing to a drawable resource.
|
static Icon |
createWithResource(Resources res,
int resId)
Version of createWithResource that takes Resources.
|
static Icon |
createWithResource(String resPackage,
int resId)
Create an Icon pointing to a drawable resource.
|
int |
describeContents()
Parcelable interface
|
Bitmap |
getBitmap() |
byte[] |
getDataBytes() |
int |
getDataLength() |
int |
getDataOffset() |
int |
getResId() |
Resources |
getResources() |
String |
getResPackage() |
int |
getType() |
Uri |
getUri() |
String |
getUriString() |
boolean |
hasTint() |
Drawable |
loadDrawable(Context context)
Returns a Drawable that can be used to draw the image inside this Icon, constructing it
if necessary.
|
Drawable |
loadDrawableAsUser(Context context,
int userId)
Load the requested resources under the given userId, if the system allows it,
before actually loading the drawable.
|
void |
loadDrawableAsync(Context context,
Icon.OnDrawableLoadedListener listener,
Handler handler)
Invokes
loadDrawable(Context) on a background thread and notifies the
on the handler
when finished. |
void |
loadDrawableAsync(Context context,
Message andThen)
Invokes
loadDrawable(Context) on the given Handler
and then sends andThen to the same Handler when finished. |
boolean |
sameAs(Icon otherIcon)
Compares if this icon is constructed from the same resources as another icon.
|
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.
|
void |
writeToStream(OutputStream stream)
Writes a serialized version of an Icon to the specified stream.
|
public static final int TYPE_BITMAP
public static final int TYPE_RESOURCE
public static final int TYPE_DATA
public static final int TYPE_URI
public static final int MIN_ASHMEM_ICON_SIZE
public static final Parcelable.Creator<Icon> CREATOR
public int getType()
TYPE_BITMAP
,
TYPE_RESOURCE
,
TYPE_DATA
, or
TYPE_URI
.public Bitmap getBitmap()
Bitmap
held by this TYPE_BITMAP
Icon.public int getDataLength()
TYPE_DATA
Icon.public int getDataOffset()
TYPE_DATA
Icon at which
valid compressed bitmap data is found.public byte[] getDataBytes()
TYPE_DATA
Icon ctonaining compressed
bitmap data.public Resources getResources()
Resources
for this TYPE_RESOURCE
Icon.public String getResPackage()
TYPE_RESOURCE
Icon.public int getResId()
TYPE_RESOURCE
Icon.public void loadDrawableAsync(Context context, Message andThen)
loadDrawable(Context)
on the given Handler
and then sends andThen
to the same Handler when finished.context
- Context
in which to load the drawable; see
loadDrawable(Context)
andThen
- Message
to send to its target once the drawable
is available. The obj
property is populated with the Drawable.public void loadDrawableAsync(Context context, Icon.OnDrawableLoadedListener listener, Handler handler)
loadDrawable(Context)
on a background thread and notifies the
listener
on the handler
when finished.context
- Context
in which to load the drawable; see
loadDrawable(Context)
listener
- to be notified
when
loadDrawable(Context)
finishedhandler
- Handler
on which to notify the listener
public Drawable loadDrawable(Context context)
loadDrawableAsync
instead.public Drawable loadDrawableAsUser(Context context, int userId)
public void convertToAshmem()
public void writeToStream(OutputStream stream) throws IOException
stream
- The stream on which to serialize the Icon.IOException
public static Icon createFromStream(InputStream stream) throws IOException
stream
- The input stream from which to reconstruct the Icon.IOException
public boolean sameAs(Icon otherIcon)
otherIcon
- the other iconpublic static Icon createWithResource(Context context, @DrawableRes int resId)
context
- The context for the application whose resources should be used to resolve the
given resource ID.resId
- ID of the drawable resourcepublic static Icon createWithResource(Resources res, @DrawableRes int resId)
public static Icon createWithResource(String resPackage, @DrawableRes int resId)
resPackage
- Name of the package containing the resource in questionresId
- ID of the drawable resourcepublic static Icon createWithBitmap(Bitmap bits)
bits
- A valid Bitmap
objectpublic static Icon createWithData(byte[] data, int offset, int length)
data
- Byte array storing compressed bitmap data of a type that
BitmapFactory
can decode (see Bitmap.CompressFormat
).offset
- Offset into data
at which the bitmap data startslength
- Length of the bitmap datapublic static Icon createWithContentUri(String uri)
uri
- A uri referring to local content:// or file:// image data.public static Icon createWithContentUri(Uri uri)
uri
- A uri referring to local content:// or file:// image data.public Icon setTint(int tint)
tint
- a color, as in Drawable.setTint(int)
public Icon setTintList(ColorStateList tintList)
tintList
- as in Drawable.setTintList(ColorStateList)
, null to remove tintpublic Icon setTintMode(PorterDuff.Mode mode)
mode
- a blending mode, as in Drawable.setTintMode(PorterDuff.Mode)
, may be nullpublic boolean hasTint()
public static Icon createWithFilePath(String path)
path
- A path to a file that contains compressed bitmap data of
a type that BitmapFactory
can decode.public String toString()
Object
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())
public int describeContents()
describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel dest, int flags)
Parcelable
writeToParcel
in interface Parcelable
dest
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.