Class RoundedImageDrawable
Image
object.- Since:
- 3.12
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class icyllis.modernui.graphics.drawable.Drawable
Drawable.Callback, Drawable.ConstantState
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionRoundedImageDrawable
(Resources res, Image image) Create drawable from an image, setting initial target density based on the display metrics of the resources.RoundedImageDrawable
(Resources res, InputStream stream) Create a drawable by decoding an image from the given input stream. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.float
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.void
getOutline
(Outline outline) Called to get the drawable to populate the Outline that defines its drawing area.final Paint
getPaint()
Returns the paint used to render this drawable.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.boolean
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.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
setCircular
(boolean circular) Sets the image shape to circular.void
setColorFilter
(ColorFilter colorFilter) Specify an optional color filter for the drawable.void
setCornerRadius
(float cornerRadius) Sets the corner radius to be applied when drawing the bitmap.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
(Rect subset) Specifies the subset of the image to draw.void
setTargetDensity
(int density) Set the density at which this drawable will be rendered.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, clearMutated, copyBounds, copyBounds, getBounds, getCallback, getChangingConfigurations, getConstantState, getCurrent, getDirtyBounds, getHotspotBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getPadding, getState, invalidateSelf, isAutoMirrored, isVisible, jumpToCurrentState, mutate, onLayoutDirectionChanged, onLevelChange, scaleFromDensity, scaleFromDensity, scheduleSelf, setAutoMirrored, setBounds, setBounds, setCallback, setChangingConfigurations, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setVisible, unscheduleSelf
-
Constructor Details
-
RoundedImageDrawable
Create drawable from an image, setting initial target density based on the display metrics of the resources. -
RoundedImageDrawable
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
- See Also:
-
setGravity
public void setGravity(int gravity) Set the gravity used to position/stretch the image within its bounds.- Parameters:
gravity
- the gravity- See Also:
-
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
-
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. -
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). -
getOutline
Description copied from class:Drawable
Called to get the drawable to populate the Outline that defines its drawing area.This method is called by the default
ViewOutlineProvider
to 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:
getOutline
in classDrawable
- See Also:
-
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
-
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.
-
setCircular
public void setCircular(boolean circular) Sets the image shape to circular.This overwrites any calls made to
setCornerRadius(float)
so far.If true, this overwrites any calls made to
setSrcRect(Rect)
so far. -
isCircular
public boolean isCircular()- Returns:
true
if the image is circular, elsefalse
.
-
setCornerRadius
public void setCornerRadius(float cornerRadius) Sets the corner radius to be applied when drawing the bitmap. -
getCornerRadius
public float getCornerRadius()- Returns:
- The corner radius applied when drawing the bitmap.
-
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
-