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 TypeMethodDescriptionvoidDraw 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.floatintGet 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.booleanIndicates whether this drawable has at least one state spec explicitly specifying state_focused.booleanIndicates whether the mipmap hint is enabled on this drawable's image.booleanIndicates whether antialiasing is enabled for this drawable.booleanbooleanisDither()Returns true if color error may be distributed to smooth color transition.booleanisFilter()Returns the current filter.booleanIndicates whether this drawable will change its appearance based on state.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.voidsetCircular(boolean circular) Sets the image shape to circular.voidsetColorFilter(ColorFilter colorFilter) Specify an optional color filter for the drawable.voidsetCornerRadius(float cornerRadius) Sets the corner radius to be applied when drawing the bitmap.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) Enables or disables the mipmap hint for this drawable's image.voidsetSrcRect(Rect subset) Specifies the subset of the image to draw.voidsetTargetDensity(int density) Set the density at which this drawable will be rendered.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, 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: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
-
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.
-
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:
trueif 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: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
-