Register now for Android Dev Summit 2019!

ShapeAppearanceModel

public class ShapeAppearanceModel
extends Object

java.lang.Object
   ↳ com.google.android.material.shape.ShapeAppearanceModel
Known Direct Subclasses


This class models the edges and corners of a shape, which are used by MaterialShapeDrawable to generate and render the shape for a view's background.

Summary

Nested classes

interface ShapeAppearanceModel.OnChangedListener

Listener called every time a ShapeAppearanceModel corner or edge is modified and notifies the MaterialShapeDrawable that the shape has changed so that it can invalidate itself. 

Constants

int PILL

Public constructors

ShapeAppearanceModel()

Constructs a default path generator with default edge and corner treatments.

ShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel)
ShapeAppearanceModel(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
ShapeAppearanceModel(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int defaultCornerSize)

Public methods

EdgeTreatment getBottomEdge()

Gets the edge treatment for the bottom edge.

CornerTreatment getBottomLeftCorner()

Gets the corner treatment for the bottom left corner.

CornerTreatment getBottomRightCorner()

Gets the corner treatment for the bottom right corner.

EdgeTreatment getLeftEdge()

Gets the edge treatment for the left edge.

EdgeTreatment getRightEdge()

Gets the edge treatment for the right edge.

EdgeTreatment getTopEdge()

Gets the edge treatment for the top edge.

CornerTreatment getTopLeftCorner()

Gets the corner treatment for the top left corner.

CornerTreatment getTopRightCorner()

Gets the corner treatment for the top right corner.

boolean isUsingPillCorner()

Checks if all four corners of this ShapeAppearanceModel are of size PILL.

void setAllCorners(CornerTreatment cornerTreatment)

Sets all corner treatments.

void setAllCorners(int cornerFamily, int cornerSize)

Sets all corner treatments to CornerTreatments generated from a cornerFamily and cornerSize.

void setAllEdges(EdgeTreatment edgeTreatment)

Sets all edge treatments.

void setBottomEdge(EdgeTreatment bottomEdge)

Sets the edge treatment for the bottom edge.

void setBottomLeftCorner(CornerTreatment bottomLeftCorner)

Sets the corner treatment for the bottom left corner.

void setBottomLeftCorner(int cornerFamily, int cornerSize)

Sets the corner treatment for the bottom left corner.

void setBottomRightCorner(CornerTreatment bottomRightCorner)

Sets the corner treatment for the bottom right corner.

void setBottomRightCorner(int cornerFamily, int cornerSize)

Sets the corner treatment for the bottom right corner.

void setCornerRadii(float topLeftCornerRadius, float topRightCornerRadius, float bottomRightCornerRadius, float bottomLeftCornerRadius)

Sets the corner size of all four corner treatments using the topLeftCornerRadius, topRightCornerRadius, bottomRightCornerRadius, and bottomLeftCornerRadius.

void setCornerRadius(float cornerRadius)

Sets the corner size of all four corner treatments to cornerRadius.

void setCornerTreatments(CornerTreatment topLeftCorner, CornerTreatment topRightCorner, CornerTreatment bottomRightCorner, CornerTreatment bottomLeftCorner)

Sets corner treatments.

void setEdgeTreatments(EdgeTreatment leftEdge, EdgeTreatment topEdge, EdgeTreatment rightEdge, EdgeTreatment bottomEdge)

Sets edge treatments.

void setLeftEdge(EdgeTreatment leftEdge)

Sets the edge treatment for the left edge.

void setRightEdge(EdgeTreatment rightEdge)

Sets the edge treatment for the right edge.

void setTopEdge(EdgeTreatment topEdge)

Sets the edge treatment for the top edge.

void setTopLeftCorner(CornerTreatment topLeftCorner)

Sets the corner treatment for the top left corner.

void setTopLeftCorner(int cornerFamily, int cornerSize)

Sets the corner treatment for the top left corner.

void setTopRightCorner(CornerTreatment topRightCorner)

Sets the corner treatment for the top right corner.

void setTopRightCorner(int cornerFamily, int cornerSize)

Sets the corner treatment for the top right corner.

Inherited methods

From class java.lang.Object

Constants

PILL

int PILL

Constant Value: -1 (0xffffffff)

Public constructors

ShapeAppearanceModel

ShapeAppearanceModel ()

Constructs a default path generator with default edge and corner treatments.

ShapeAppearanceModel

ShapeAppearanceModel (ShapeAppearanceModel shapeAppearanceModel)

Parameters
shapeAppearanceModel ShapeAppearanceModel

ShapeAppearanceModel

ShapeAppearanceModel (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

ShapeAppearanceModel

ShapeAppearanceModel (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes, 
                int defaultCornerSize)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

defaultCornerSize int

Public methods

getBottomEdge

EdgeTreatment getBottomEdge ()

Gets the edge treatment for the bottom edge.

Returns
EdgeTreatment the edge treatment for the bottom edge.

getBottomLeftCorner

CornerTreatment getBottomLeftCorner ()

Gets the corner treatment for the bottom left corner.

Returns
CornerTreatment the corner treatment for the bottom left corner.

getBottomRightCorner

CornerTreatment getBottomRightCorner ()

Gets the corner treatment for the bottom right corner.

Returns
CornerTreatment the corner treatment for the bottom right corner.

getLeftEdge

EdgeTreatment getLeftEdge ()

Gets the edge treatment for the left edge.

Returns
EdgeTreatment the edge treatment for the left edge.

getRightEdge

EdgeTreatment getRightEdge ()

Gets the edge treatment for the right edge.

Returns
EdgeTreatment the edge treatment for the right edge.

getTopEdge

EdgeTreatment getTopEdge ()

Gets the edge treatment for the top edge.

Returns
EdgeTreatment the edge treatment for the top edge.

getTopLeftCorner

CornerTreatment getTopLeftCorner ()

Gets the corner treatment for the top left corner.

Returns
CornerTreatment the corner treatment for the top left corner.

getTopRightCorner

CornerTreatment getTopRightCorner ()

Gets the corner treatment for the top right corner.

Returns
CornerTreatment the corner treatment for the top right corner.

isUsingPillCorner

boolean isUsingPillCorner ()

Checks if all four corners of this ShapeAppearanceModel are of size PILL.

Returns
boolean

setAllCorners

void setAllCorners (CornerTreatment cornerTreatment)

Sets all corner treatments.

Parameters
cornerTreatment CornerTreatment: the corner treatment to use for all four corners.

setAllCorners

void setAllCorners (int cornerFamily, 
                int cornerSize)

Sets all corner treatments to CornerTreatments generated from a cornerFamily and cornerSize.

Parameters
cornerFamily int: The family to be used to create the CornerTreatments for all four corners. May be one of ROUNDED or CUT.

cornerSize int: The size to be used to create the CornerTreatments for all four corners.

setAllEdges

void setAllEdges (EdgeTreatment edgeTreatment)

Sets all edge treatments.

Parameters
edgeTreatment EdgeTreatment: the edge treatment to use for all four edges.

setBottomEdge

void setBottomEdge (EdgeTreatment bottomEdge)

Sets the edge treatment for the bottom edge.

Parameters
bottomEdge EdgeTreatment: the desired treatment.

setBottomLeftCorner

void setBottomLeftCorner (CornerTreatment bottomLeftCorner)

Sets the corner treatment for the bottom left corner.

Parameters
bottomLeftCorner CornerTreatment: the desired treatment.

setBottomLeftCorner

void setBottomLeftCorner (int cornerFamily, 
                int cornerSize)

Sets the corner treatment for the bottom left corner.

Parameters
cornerFamily int: the family to use to create the corner treatment

cornerSize int: the size to use to create the corner treatment

setBottomRightCorner

void setBottomRightCorner (CornerTreatment bottomRightCorner)

Sets the corner treatment for the bottom right corner.

Parameters
bottomRightCorner CornerTreatment: the desired treatment.

setBottomRightCorner

void setBottomRightCorner (int cornerFamily, 
                int cornerSize)

Sets the corner treatment for the bottom right corner.

Parameters
cornerFamily int: the family to use to create the corner treatment

cornerSize int: the size to use to create the corner treatment

setCornerRadii

void setCornerRadii (float topLeftCornerRadius, 
                float topRightCornerRadius, 
                float bottomRightCornerRadius, 
                float bottomLeftCornerRadius)

Sets the corner size of all four corner treatments using the topLeftCornerRadius, topRightCornerRadius, bottomRightCornerRadius, and bottomLeftCornerRadius.

Note: This method does not create new CornerTreatments for all four corners. Instead, it directly modifies the corner size of each existing corner treatment.

Parameters
topLeftCornerRadius float

topRightCornerRadius float

bottomRightCornerRadius float

bottomLeftCornerRadius float

setCornerRadius

void setCornerRadius (float cornerRadius)

Sets the corner size of all four corner treatments to cornerRadius. This is a convenience method for setCornerRadii(float, float, float, float))}.

Note: This method does not create new CornerTreatments for all four corners. Instead, it directly modifies the corner size of each existing corner treatment.

Parameters
cornerRadius float

setCornerTreatments

void setCornerTreatments (CornerTreatment topLeftCorner, 
                CornerTreatment topRightCorner, 
                CornerTreatment bottomRightCorner, 
                CornerTreatment bottomLeftCorner)

Sets corner treatments.

Parameters
topLeftCorner CornerTreatment: the corner treatment to use in the top left corner.

topRightCorner CornerTreatment: the corner treatment to use in the top right corner.

bottomRightCorner CornerTreatment: the corner treatment to use in the bottom right corner.

bottomLeftCorner CornerTreatment: the corner treatment to use in the bottom left corner.

setEdgeTreatments

void setEdgeTreatments (EdgeTreatment leftEdge, 
                EdgeTreatment topEdge, 
                EdgeTreatment rightEdge, 
                EdgeTreatment bottomEdge)

Sets edge treatments.

Parameters
leftEdge EdgeTreatment: the edge treatment to use on the left edge.

topEdge EdgeTreatment: the edge treatment to use on the top edge.

rightEdge EdgeTreatment: the edge treatment to use on the right edge.

bottomEdge EdgeTreatment: the edge treatment to use on the bottom edge.

setLeftEdge

void setLeftEdge (EdgeTreatment leftEdge)

Sets the edge treatment for the left edge.

Parameters
leftEdge EdgeTreatment: the desired treatment.

setRightEdge

void setRightEdge (EdgeTreatment rightEdge)

Sets the edge treatment for the right edge.

Parameters
rightEdge EdgeTreatment: the desired treatment.

setTopEdge

void setTopEdge (EdgeTreatment topEdge)

Sets the edge treatment for the top edge.

Parameters
topEdge EdgeTreatment: the desired treatment.

setTopLeftCorner

void setTopLeftCorner (CornerTreatment topLeftCorner)

Sets the corner treatment for the top left corner.

Parameters
topLeftCorner CornerTreatment: the desired treatment.

setTopLeftCorner

void setTopLeftCorner (int cornerFamily, 
                int cornerSize)

Sets the corner treatment for the top left corner.

Parameters
cornerFamily int: the family to use to create the corner treatment

cornerSize int: the size to use to create the corner treatment

setTopRightCorner

void setTopRightCorner (CornerTreatment topRightCorner)

Sets the corner treatment for the top right corner.

Parameters
topRightCorner CornerTreatment: the desired treatment.

setTopRightCorner

void setTopRightCorner (int cornerFamily, 
                int cornerSize)

Sets the corner treatment for the top right corner.

Parameters
cornerFamily int: the family to use to create the corner treatment

cornerSize int: the size to use to create the corner treatment