IconCompat
public class IconCompat implements VersionedParcelable
Helper for accessing features in android.graphics.drawable.Icon
.
Summary
Constants |
|
---|---|
static final int |
An icon that was created using |
static final int |
TYPE_BITMAP = 1 An icon that was created using |
static final int |
TYPE_DATA = 3 An icon that was created using |
static final int |
TYPE_RESOURCE = 2 An icon that was created using createWithResource. |
static final int |
TYPE_UNKNOWN = -1 Value returned when the type of an |
static final int |
TYPE_URI = 4 An icon that was created using createWithContentUri. |
static final int |
An icon that was created using createWithAdaptiveBitmapContentUri. |
Public methods |
|
---|---|
static @Nullable IconCompat |
createFromBundle(@NonNull Bundle bundle) Extracts an icon from a bundle that was added using |
static @NonNull IconCompat |
@RequiresApi(value = 23) Creates an IconCompat from an Icon. |
static @NonNull IconCompat |
Create an Icon pointing to a bitmap in memory that follows the icon design guideline defined by |
static @NonNull IconCompat |
Create an Icon pointing to an image file specified by URI. |
static @NonNull IconCompat |
Create an Icon pointing to an image file specified by URI. |
static @NonNull IconCompat |
createWithBitmap(@NonNull Bitmap bits) Create an Icon pointing to a bitmap in memory. |
static @NonNull IconCompat |
Create an Icon pointing to an image file specified by URI. |
static @NonNull IconCompat |
createWithContentUri(@NonNull Uri uri) Create an Icon pointing to an image file specified by URI. |
static @NonNull IconCompat |
createWithData(@NonNull byte[] data, int offset, int length) Create an Icon pointing to a compressed bitmap stored in a byte array. |
static @NonNull IconCompat |
createWithResource(@NonNull Context context, @DrawableRes int resId) Create an Icon pointing to a drawable resource. |
@DrawableRes int |
getResId() Gets the drawable resource id used to create this icon. |
@NonNull String |
Gets the package used to create this icon. |
int |
getType() Gets the type of the icon provided. |
@NonNull Uri |
getUri() Gets the uri used to create this icon. |
@Nullable Drawable |
loadDrawable(@NonNull Context context) Returns a Drawable that can be used to draw the image inside this Icon, constructing it if necessary. |
void |
Called immediately after this object has been deserialized, can be used to handle any custom fields that cannot be easily annotated. |
void |
onPreParceling(boolean isStream) Called immediately before this object is going to be serialized, can be used to handle any custom fields that cannot be easily annotated. |
@NonNull IconCompat |
Store a color to use whenever this Icon is drawn. |
@NonNull IconCompat |
setTintList(@Nullable ColorStateList tintList) Store a color to use whenever this Icon is drawn. |
@NonNull IconCompat |
setTintMode(@Nullable PorterDuff.Mode mode) Store a blending mode to use whenever this Icon is drawn. |
@NonNull Bundle |
toBundle() Adds this Icon to a Bundle that can be read back with the same parameters to |
@NonNull Icon |
@RequiresApi(value = 23) This method is deprecated. |
@NonNull Icon |
@RequiresApi(value = 23) Convert this compat object to |
@NonNull String |
toString() |
Constants
TYPE_ADAPTIVE_BITMAP
public static final int TYPE_ADAPTIVE_BITMAP = 5
An icon that was created using createWithAdaptiveBitmap
.
TYPE_BITMAP
public static final int TYPE_BITMAP = 1
An icon that was created using createWithBitmap
.
TYPE_DATA
public static final int TYPE_DATA = 3
An icon that was created using createWithData
.
TYPE_RESOURCE
public static final int TYPE_RESOURCE = 2
An icon that was created using createWithResource.
TYPE_UNKNOWN
public static final int TYPE_UNKNOWN = -1
Value returned when the type of an Icon
cannot be determined.
TYPE_URI
public static final int TYPE_URI = 4
An icon that was created using createWithContentUri.
TYPE_URI_ADAPTIVE_BITMAP
public static final int TYPE_URI_ADAPTIVE_BITMAP = 6
An icon that was created using createWithAdaptiveBitmapContentUri.
Public methods
createFromBundle
public static @Nullable IconCompat createFromBundle(@NonNull Bundle bundle)
Extracts an icon from a bundle that was added using toBundle
.
createFromIcon
@RequiresApi(value = 23)
public static @NonNull IconCompat createFromIcon(@NonNull Context context, @NonNull Icon icon)
Creates an IconCompat from an Icon.
createWithAdaptiveBitmap
public static @NonNull IconCompat createWithAdaptiveBitmap(@NonNull Bitmap bits)
Create an Icon pointing to a bitmap in memory that follows the icon design guideline defined by android.graphics.drawable.AdaptiveIconDrawable
.
Parameters | |
---|---|
@NonNull Bitmap bits |
A valid |
See also | |
---|---|
createWithAdaptiveBitmap |
createWithAdaptiveBitmapContentUri
public static @NonNull IconCompat createWithAdaptiveBitmapContentUri(@NonNull String uri)
Create an Icon pointing to an image file specified by URI. Image file should follow the icon design guideline defined by AdaptiveIconDrawable
.
See also | |
---|---|
createWithAdaptiveBitmapContentUri |
createWithAdaptiveBitmapContentUri
public static @NonNull IconCompat createWithAdaptiveBitmapContentUri(@NonNull Uri uri)
Create an Icon pointing to an image file specified by URI. Image file should follow the icon design guideline defined by AdaptiveIconDrawable
.
See also | |
---|---|
createWithAdaptiveBitmapContentUri |
createWithBitmap
public static @NonNull IconCompat createWithBitmap(@NonNull Bitmap bits)
Create an Icon pointing to a bitmap in memory.
Parameters | |
---|---|
@NonNull Bitmap bits |
A valid |
See also | |
---|---|
createWithBitmap |
createWithContentUri
public static @NonNull IconCompat createWithContentUri(@NonNull String uri)
Create an Icon pointing to an image file specified by URI.
See also | |
---|---|
createWithContentUri |
createWithContentUri
public static @NonNull IconCompat createWithContentUri(@NonNull Uri uri)
Create an Icon pointing to an image file specified by URI.
See also | |
---|---|
createWithContentUri |
createWithData
public static @NonNull IconCompat createWithData(@NonNull byte[] data, int offset, int length)
Create an Icon pointing to a compressed bitmap stored in a byte array.
Parameters | |
---|---|
@NonNull byte[] data |
Byte array storing compressed bitmap data of a type that |
int offset |
Offset into |
int length |
Length of the bitmap data |
See also | |
---|---|
createWithData |
createWithResource
public static @NonNull IconCompat createWithResource(@NonNull Context context, @DrawableRes int resId)
Create an Icon pointing to a drawable resource.
Parameters | |
---|---|
@NonNull Context context |
The context for the application whose resources should be used to resolve the given resource ID. |
@DrawableRes int resId |
ID of the drawable resource |
See also | |
---|---|
createWithResource |
getResId
public @DrawableRes int getResId()
Gets the drawable 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.
getResPackage
public @NonNull 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.
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.
getUri
public @NonNull 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.
loadDrawable
public @Nullable Drawable loadDrawable(@NonNull Context context)
Returns a Drawable that can be used to draw the image inside this Icon, constructing it if necessary.
onPostParceling
public void onPostParceling()
Called immediately after this object has been deserialized, can be used to handle any custom fields that cannot be easily annotated.
onPreParceling
public void onPreParceling(boolean isStream)
Called immediately before this object is going to be serialized, can be used to handle any custom fields that cannot be easily annotated.
setTint
public @NonNull IconCompat setTint(@ColorInt int tint)
Store a color to use whenever this Icon is drawn.
Returns | |
---|---|
@NonNull IconCompat |
this same object, for use in chained construction |
setTintList
public @NonNull IconCompat setTintList(@Nullable ColorStateList tintList)
Store a color to use whenever this Icon is drawn.
Parameters | |
---|---|
@Nullable ColorStateList tintList |
as in |
Returns | |
---|---|
@NonNull IconCompat |
this same object, for use in chained construction |
setTintMode
public @NonNull IconCompat setTintMode(@Nullable PorterDuff.Mode mode)
Store a blending mode to use whenever this Icon is drawn.
Parameters | |
---|---|
@Nullable PorterDuff.Mode mode |
a blending mode, as in |
Returns | |
---|---|
@NonNull IconCompat |
this same object, for use in chained construction |
toBundle
public @NonNull Bundle toBundle()
Adds this Icon to a Bundle that can be read back with the same parameters to createFromBundle
.