Class ImageDrawable
Image
object.-
Nested Class Summary
Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.Drawable
Drawable.Callback, Drawable.ConstantState
-
Field Summary
-
Constructor Summary
ConstructorDescriptionImageDrawable
(Image image) Deprecated.ImageDrawable
(Resources res, Image image) Create drawable from an image, setting initial target density based on the display metrics of the resources.ImageDrawable
(Resources res, InputStream stream) Create a drawable by decoding an image from the given input stream.ImageDrawable
(InputStream stream) Deprecated.useImageDrawable(Resources, InputStream)
insteadImageDrawable
(String namespace, String path) Create a drawable by opening a given file path and decoding the image. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the mutated state, allowing this drawable to be cached and mutated again.void
Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha).int
getAlpha()
Gets the current alpha value for the drawable.Returns the current color filter, ornull
if none set.final Drawable.ConstantState
Return aDrawable.ConstantState
instance that holds the shared state of this Drawable.int
Get the gravity used to position/stretch the image within its bounds.final Image
getImage()
Returns the image used by this drawable to render.int
Returns the drawable's intrinsic height.int
Returns the drawable's intrinsic width.final Paint
getPaint()
Returns the paint used to render this drawable.Indicates the repeat behavior of this drawable on the X axis.Indicates the repeat behavior of this drawable on the Y axis.boolean
Indicates whether this drawable has at least one state spec explicitly specifying state_focused.boolean
Indicates whether the mipmap hint is enabled on this drawable's image.boolean
Indicates whether antialiasing is enabled for this drawable.final boolean
Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left.boolean
isDither()
Returns true if color error may be distributed to smooth color transition.boolean
isFilter()
Returns the current filter.boolean
Indicates whether this drawable will change its appearance based on state.mutate()
A mutable ImageDrawable still shares its Image with any other Drawable that comes from the same resource.protected void
onBoundsChange
(Rect bounds) Override this in your subclass to change appearance if you vary based on the bounds.protected boolean
onStateChange
(int[] stateSet) Override this in your subclass to change appearance if you recognize the specified state.void
setAlpha
(int alpha) Specify an alpha value for the drawable.void
setAntiAlias
(boolean aa) Enables or disables antialiasing for this drawable.void
setAutoMirrored
(boolean mirrored) Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left).void
setColorFilter
(ColorFilter colorFilter) Specify an optional color filter for the drawable.void
setDither
(boolean dither) Sets a hint that indicates if color error may be distributed to smooth color transition.void
setFilter
(boolean filter) Set to true to have the drawable filter texture images with bilinear sampling when they are scaled or rotated.void
setGravity
(int gravity) Set the gravity used to position/stretch the image within its bounds.void
Switch to a new Image object.void
setMipmap
(boolean mipmap) Enables or disables the mipmap hint for this drawable's image.void
setSrcRect
(int left, int top, int right, int bottom) Specifies the subset of the image to draw.void
setSrcRect
(Rect srcRect) Specifies the subset of the image to draw.void
setTargetDensity
(int density) Set the density at which this drawable will be rendered.void
setTileModeX
(Shader.TileMode mode) Sets the repeat behavior of this drawable on the X axis.void
setTileModeXY
(Shader.TileMode tileModeX, Shader.TileMode tileModeY) Sets the repeat behavior of this drawable on both axis.final void
setTileModeY
(Shader.TileMode mode) Sets the repeat behavior of this drawable on the Y axis.void
setTintBlendMode
(BlendMode blendMode) Specifies a tint blending mode for this drawable.void
setTintList
(ColorStateList tint) Specifies tint color for this drawable as a color state list.Methods inherited from class icyllis.modernui.graphics.drawable.Drawable
applyTheme, canApplyTheme, copyBounds, copyBounds, getBounds, getCallback, getChangingConfigurations, getCurrent, getHotspotBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getPadding, getState, invalidateSelf, isVisible, jumpToCurrentState, onLayoutDirectionChanged, onLevelChange, scaleFromDensity, scaleFromDensity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setVisible, unscheduleSelf
-
Constructor Details
-
ImageDrawable
Deprecated.useImageDrawable(Resources, Image)
insteadCreate drawable from an image, setting target density toDisplayMetrics.DENSITY_DEFAULT
. -
ImageDrawable
Create drawable from an image, setting initial target density based on the display metrics of the resources. -
ImageDrawable
Create a drawable by opening a given file path and decoding the image.This method may only be called from UI thread.
-
ImageDrawable
Deprecated.useImageDrawable(Resources, InputStream)
insteadCreate a drawable by decoding an image from the given input stream. -
ImageDrawable
Create a drawable by decoding an image from the given input stream.This method silently ignores any IO exception. This method does not closed the given stream after read operation has completed. The stream will be at end if read operation succeeds.
This method may only be called from UI thread.
-
-
Method Details
-
getPaint
Returns the paint used to render this drawable. -
getImage
Returns the image used by this drawable to render. May be null. -
setImage
Switch to a new Image object. Calling this method will also reset the subset to the full image, seesetSrcRect(Rect)
. -
setTargetDensity
public void setTargetDensity(int density) Set the density at which this drawable will be rendered.- Parameters:
density
- The density scale for this drawable.- See Also:
-
getGravity
public int getGravity()Get the gravity used to position/stretch the image within its bounds.- Returns:
- the gravity applied to the image
-
setGravity
public void setGravity(int gravity) Set the gravity used to position/stretch the image within its bounds.- Parameters:
gravity
- the gravity
-
setSrcRect
public void setSrcRect(int left, int top, int right, int bottom) Specifies the subset of the image to draw. To draw the full image, callsetSrcRect(Rect)
with null.Calling this method when there's no image has no effect. Next call to
setImage(Image)
will reset the subset to the full image. -
setSrcRect
Specifies the subset of the image to draw. Null for the full image.Calling this method when there's no image has no effect. Next call to
setImage(Image)
will reset the subset to the full image.- Parameters:
srcRect
- the subset of the image
-
setMipmap
@Experimental public void setMipmap(boolean mipmap) Enables or disables the mipmap hint for this drawable's image.If the image is null calling this method has no effect.
- Parameters:
mipmap
- True if the image should use mipmaps, false otherwise.- See Also:
-
hasMipmap
@Experimental public boolean hasMipmap()Indicates whether the mipmap hint is enabled on this drawable's image.- Returns:
- True if the mipmap hint is set, false otherwise. If the image is null, this method always returns false.
- See Also:
-
setAntiAlias
public void setAntiAlias(boolean aa) Enables or disables antialiasing for this drawable. Antialiasing affects the edges of the image only so it applies only when the drawable is rotated. The default is true.- Parameters:
aa
- True if the image should be anti-aliased, false otherwise.- See Also:
-
isAntiAlias
public boolean isAntiAlias()Indicates whether antialiasing is enabled for this drawable. The default is true.- Returns:
- True if antialiasing is enabled, false otherwise.
- See Also:
-
setDither
public void setDither(boolean dither) Sets a hint that indicates if color error may be distributed to smooth color transition. For example, drawing 16-bit per channel image onto an 8-bit per channel device. The default value is false. -
isDither
public boolean isDither()Returns true if color error may be distributed to smooth color transition. The default value is false. -
setFilter
public void setFilter(boolean filter) Set to true to have the drawable filter texture images with bilinear sampling when they are scaled or rotated. The default is true.- Parameters:
filter
- true to use bilinear sampling, false to use nearest neighbor sampling
-
isFilter
public boolean isFilter()Returns the current filter. The default is true. -
getTileModeX
Indicates the repeat behavior of this drawable on the X axis.- Returns:
Shader.TileMode.CLAMP
if the image does not repeat,Shader.TileMode.REPEAT
orShader.TileMode.MIRROR
otherwise.
-
getTileModeY
Indicates the repeat behavior of this drawable on the Y axis.- Returns:
Shader.TileMode.CLAMP
if the image does not repeat,Shader.TileMode.REPEAT
orShader.TileMode.MIRROR
otherwise.
-
setTileModeX
Sets the repeat behavior of this drawable on the X axis. By default, the drawable does not repeat its image. UsingShader.TileMode.REPEAT
orShader.TileMode.MIRROR
the image can be repeated (or tiled) if the image is smaller than this drawable.- Parameters:
mode
- The repeat mode for this drawable.- See Also:
-
setTileModeY
Sets the repeat behavior of this drawable on the Y axis. By default, the drawable does not repeat its image. UsingShader.TileMode.REPEAT
orShader.TileMode.MIRROR
the image can be repeated (or tiled) if the image is smaller than this drawable.- Parameters:
mode
- The repeat mode for this drawable.- See Also:
-
setTileModeXY
Sets the repeat behavior of this drawable on both axis. By default, the drawable does not repeat its image. UsingShader.TileMode.REPEAT
orShader.TileMode.MIRROR
the image can be repeated (or tiled) if the image is smaller than this drawable.- Parameters:
tileModeX
- The X tile mode for this drawable.tileModeY
- The Y tile mode for this drawable.- See Also:
-
setAutoMirrored
public void setAutoMirrored(boolean mirrored) Description copied from class:Drawable
Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left). SeeLayoutDirection
.- Overrides:
setAutoMirrored
in classDrawable
- Parameters:
mirrored
- Set to true if the Drawable should be mirrored, false if not.
-
isAutoMirrored
public final boolean isAutoMirrored()Description copied from class:Drawable
Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. SeeLayoutDirection
.- Overrides:
isAutoMirrored
in classDrawable
- Returns:
- boolean Returns true if this Drawable will be automatically mirrored.
-
onBoundsChange
Description copied from class:Drawable
Override this in your subclass to change appearance if you vary based on the bounds.- Overrides:
onBoundsChange
in classDrawable
-
draw
Description copied from class:Drawable
Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha). -
setAlpha
public void setAlpha(int alpha) Description copied from class:Drawable
Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque. -
getAlpha
public int getAlpha()Description copied from class:Drawable
Gets the current alpha value for the drawable. 0 means fully transparent, 255 means fully opaque. This method is implemented by Drawable subclasses and the value returned is specific to how that class treats alpha. The default return value is 255 if the class does not override this method to return a value specific to its use of alpha. -
setTintList
Description copied from class:Drawable
Specifies tint color for this drawable as a color state list.A Drawable's drawing content will be blended together with its tint before it is drawn to the screen.
Note: Setting a color filter via
Drawable.setColorFilter(ColorFilter)
overrides tint.- Overrides:
setTintList
in classDrawable
- Parameters:
tint
- Color state list to use for tinting this drawable, ornull
to clear the tint- See Also:
-
setTintBlendMode
Description copied from class:Drawable
Specifies a tint blending mode for this drawable.Defines how this drawable's tint color should be blended into the drawable before it is drawn to screen. Default tint mode is
BlendMode.SRC_IN
.Note: Setting a color filter via
Drawable.setColorFilter(ColorFilter)
- Overrides:
setTintBlendMode
in classDrawable
- Parameters:
blendMode
- BlendMode to apply to the drawable, a value of null sets the default blend mode value ofBlendMode.SRC_IN
- See Also:
-
setColorFilter
Description copied from class:Drawable
Specify an optional color filter for the drawable.If a Drawable has a ColorFilter, each output pixel of the Drawable's drawing contents will be modified by the color filter before it is blended onto the render target of a Canvas.
Pass
null
to remove any existing color filter.Note: Setting a non-
null
color filter disablestint
.- Overrides:
setColorFilter
in classDrawable
- Parameters:
colorFilter
- The color filter to apply, ornull
to remove the existing color filter
-
getColorFilter
Description copied from class:Drawable
Returns the current color filter, ornull
if none set.- Overrides:
getColorFilter
in classDrawable
- Returns:
- the current color filter, or
null
if none set
-
mutate
A mutable ImageDrawable still shares its Image with any other Drawable that comes from the same resource. -
clearMutated
public void clearMutated()Description copied from class:Drawable
Clears the mutated state, allowing this drawable to be cached and mutated again.- Overrides:
clearMutated
in classDrawable
-
onStateChange
Description copied from class:Drawable
Override this in your subclass to change appearance if you recognize the specified state.- Overrides:
onStateChange
in classDrawable
- Returns:
- Returns true if the state change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last state.
-
isStateful
public boolean isStateful()Description copied from class:Drawable
Indicates whether this drawable will change its appearance based on state. Clients can use this to determine whether it is necessary to calculate their state and call setState.- Overrides:
isStateful
in classDrawable
- Returns:
- True if this drawable changes its appearance based on state, false otherwise.
- See Also:
-
hasFocusStateSpecified
public boolean hasFocusStateSpecified()Description copied from class:Drawable
Indicates whether this drawable has at least one state spec explicitly specifying state_focused.Note: A View uses a
Drawable
instance as its background and it changes its appearance based on a state. On keyboard devices, it should specify its state_focused to make sure the user knows which view is holding the focus.- Overrides:
hasFocusStateSpecified
in classDrawable
- Returns:
true
if state_focused is specified for this drawable.
-
getIntrinsicWidth
public int getIntrinsicWidth()Description copied from class:Drawable
Returns the drawable's intrinsic width.Intrinsic width is the width at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic width, such as a solid color, this method returns -1.
- Overrides:
getIntrinsicWidth
in classDrawable
- Returns:
- the intrinsic width, or -1 if no intrinsic width
-
getIntrinsicHeight
public int getIntrinsicHeight()Description copied from class:Drawable
Returns the drawable's intrinsic height.Intrinsic height is the height at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic height, such as a solid color, this method returns -1.
- Overrides:
getIntrinsicHeight
in classDrawable
- Returns:
- the intrinsic height, or -1 if no intrinsic height
-
getConstantState
Description copied from class:Drawable
Return aDrawable.ConstantState
instance that holds the shared state of this Drawable.- Overrides:
getConstantState
in classDrawable
- Returns:
- The ConstantState associated to that Drawable.
- See Also:
-
ImageDrawable(Resources, Image)
instead