Class ImageDrawable
Image object.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.Drawable
Drawable.Callback, Drawable.ConstantState -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionImageDrawable(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 TypeMethodDescriptionvoidClears the mutated state, allowing this drawable to be cached and mutated again.voidDraw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha).intgetAlpha()Gets the current alpha value for the drawable.Returns the current color filter, ornullif none set.final Drawable.ConstantStateReturn aDrawable.ConstantStateinstance that holds the shared state of this Drawable.intGet the gravity used to position/stretch the image within its bounds.final ImagegetImage()Returns the image used by this drawable to render.intReturns the drawable's intrinsic height.intReturns the drawable's intrinsic width.voidgetOutline(Outline outline) Called to get the drawable to populate the Outline that defines its drawing area.final PaintgetPaint()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.booleanIndicates whether this drawable has at least one state spec explicitly specifying state_focused.booleanIndicates whether antialiasing is enabled for this drawable.final booleanTells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left.booleanisDither()Returns true if color error may be distributed to smooth color transition.booleanisFilter()Returns the current filter.booleanisMipmap()Returns the current mipmap state.booleanIndicates 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 voidonBoundsChange(Rect bounds) Override this in your subclass to change appearance if you vary based on the bounds.protected booleanonStateChange(int[] stateSet) Override this in your subclass to change appearance if you recognize the specified state.voidsetAlpha(int alpha) Specify an alpha value for the drawable.voidsetAntiAlias(boolean aa) Enables or disables antialiasing for this drawable.voidsetAutoMirrored(boolean mirrored) Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left).voidsetColorFilter(ColorFilter colorFilter) Specify an optional color filter for the drawable.voidsetDither(boolean dither) Sets a hint that indicates if color error may be distributed to smooth color transition.voidsetFilter(boolean filter) Set to true to have the drawable filter texture images with bilinear sampling when they are scaled or rotated.voidsetGravity(int gravity) Set the gravity used to position/stretch the image within its bounds.voidSwitch to a new Image object.voidsetMipmap(boolean mipmap) Set to true to have the drawable filter texture images with their mipmap images when they are scaled down.voidsetSrcRect(int left, int top, int right, int bottom) Specifies the subset of the image to draw.voidsetSrcRect(Rect subset) Specifies the subset of the image to draw.voidsetTargetDensity(int density) Set the density at which this drawable will be rendered.voidsetTileModeX(Shader.TileMode mode) Sets the repeat behavior of this drawable on the X axis.voidsetTileModeXY(Shader.TileMode tileModeX, Shader.TileMode tileModeY) Sets the repeat behavior of this drawable on both axis.final voidsetTileModeY(Shader.TileMode mode) Sets the repeat behavior of this drawable on the Y axis.voidsetTintBlendMode(BlendMode blendMode) Specifies a tint blending mode for this drawable.voidsetTintList(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, getDirtyBounds, 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:
subset- the subset of the image, in pixels
-
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 false.- 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 false.- 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. -
setMipmap
@Experimental public void setMipmap(boolean mipmap) Set to true to have the drawable filter texture images with their mipmap images when they are scaled down. The actual mipmap state still depends on whether theImagehas mipmaps.- Parameters:
mipmap- true to sample image with mipmaps, false to ignore mipmaps- See Also:
-
isMipmap
@Experimental public boolean isMipmap()Returns the current mipmap state.- See Also:
-
getTileModeX
Indicates the repeat behavior of this drawable on the X axis.- Returns:
Shader.TileMode.CLAMPif the image does not repeat,Shader.TileMode.REPEATorShader.TileMode.MIRRORotherwise.
-
getTileModeY
Indicates the repeat behavior of this drawable on the Y axis.- Returns:
Shader.TileMode.CLAMPif the image does not repeat,Shader.TileMode.REPEATorShader.TileMode.MIRRORotherwise.
-
setTileModeX
Sets the repeat behavior of this drawable on the X axis. By default, the drawable does not repeat its image. UsingShader.TileMode.REPEATorShader.TileMode.MIRRORthe 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.REPEATorShader.TileMode.MIRRORthe 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.REPEATorShader.TileMode.MIRRORthe 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:DrawableSet whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left). SeeLayoutDirection.- Overrides:
setAutoMirroredin classDrawable- Parameters:
mirrored- Set to true if the Drawable should be mirrored, false if not.
-
isAutoMirrored
public final boolean isAutoMirrored()Description copied from class:DrawableTells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. SeeLayoutDirection.- Overrides:
isAutoMirroredin classDrawable- Returns:
- boolean Returns true if this Drawable will be automatically mirrored.
-
onBoundsChange
Description copied from class:DrawableOverride this in your subclass to change appearance if you vary based on the bounds.- Overrides:
onBoundsChangein classDrawable
-
draw
Description copied from class:DrawableDraw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha). -
getOutline
Description copied from class:DrawableCalled to get the drawable to populate the Outline that defines its drawing area.This method is called by the default
ViewOutlineProviderto define the outline of the View.The default behavior defines the outline to be the bounding rectangle of 0 alpha. Subclasses that wish to convey a different shape or alpha value must override this method.
- Overrides:
getOutlinein classDrawable- See Also:
-
setAlpha
public void setAlpha(int alpha) Description copied from class:DrawableSpecify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque. -
getAlpha
public int getAlpha()Description copied from class:DrawableGets 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:DrawableSpecifies 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:
setTintListin classDrawable- Parameters:
tint- Color state list to use for tinting this drawable, ornullto clear the tint- See Also:
-
setTintBlendMode
Description copied from class:DrawableSpecifies 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:
setTintBlendModein 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:DrawableSpecify 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
nullto remove any existing color filter.Note: Setting a non-
nullcolor filter disablestint.- Overrides:
setColorFilterin classDrawable- Parameters:
colorFilter- The color filter to apply, ornullto remove the existing color filter
-
getColorFilter
Description copied from class:DrawableReturns the current color filter, ornullif none set.- Overrides:
getColorFilterin classDrawable- Returns:
- the current color filter, or
nullif 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:DrawableClears the mutated state, allowing this drawable to be cached and mutated again.- Overrides:
clearMutatedin classDrawable
-
onStateChange
Description copied from class:DrawableOverride this in your subclass to change appearance if you recognize the specified state.- Overrides:
onStateChangein 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:DrawableIndicates 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:
isStatefulin classDrawable- Returns:
- True if this drawable changes its appearance based on state, false otherwise.
- See Also:
-
hasFocusStateSpecified
public boolean hasFocusStateSpecified()Description copied from class:DrawableIndicates whether this drawable has at least one state spec explicitly specifying state_focused.Note: A View uses a
Drawableinstance 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:
hasFocusStateSpecifiedin classDrawable- Returns:
trueif state_focused is specified for this drawable.
-
getIntrinsicWidth
public int getIntrinsicWidth()Description copied from class:DrawableReturns 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:
getIntrinsicWidthin classDrawable- Returns:
- the intrinsic width, or -1 if no intrinsic width
-
getIntrinsicHeight
public int getIntrinsicHeight()Description copied from class:DrawableReturns 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:
getIntrinsicHeightin classDrawable- Returns:
- the intrinsic height, or -1 if no intrinsic height
-
getConstantState
Description copied from class:DrawableReturn aDrawable.ConstantStateinstance that holds the shared state of this Drawable.- Overrides:
getConstantStatein classDrawable- Returns:
- The ConstantState associated to that Drawable.
- See Also:
-
ImageDrawable(Resources, Image)instead