ShapeAppearanceModel


public class ShapeAppearanceModel

Known direct subclasses
ShapePathModel

This class is deprecated.

Use ShapeAppearanceModel instead.


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 types

public final class ShapeAppearanceModel.Builder

Builder to create instances of ShapeAppearanceModels.

Constants

static final int

Flag representing bottom left corner of the shape.

static final int

Flag representing bottom right corner of the shape.

static final int

Flag representing top left corner of the shape.

static final int

Flag representing top right corner of the shape.

static final int
static final CornerSize

Public constructors

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

Public methods

static ShapeAppearanceModel.Builder
static ShapeAppearanceModel.Builder
builder(Theme theme, int shapeAppearanceResId)

This builder only takes in a single shape appearance, no shape appearance overlay.

static ShapeAppearanceModel.Builder
builder(
    Context context,
    int shapeAppearanceResId,
    int shapeAppearanceOverlayResId
)
static ShapeAppearanceModel.Builder
builder(
    Context context,
    AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes
)
static ShapeAppearanceModel.Builder
builder(
    Context context,
    AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes,
    CornerSize defaultCornerSize
)
static ShapeAppearanceModel.Builder
builder(
    Context context,
    AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes,
    int defaultCornerSize
)
EdgeTreatment

Gets the edge treatment for the bottom edge.

CornerTreatment

Gets the corner treatment for the bottom left corner.

CornerSize

Gets the corner size for the bottom left corner.

CornerTreatment

Gets the corner treatment for the bottom right corner.

CornerSize

Gets the corner size for the bottom right corner.

static CornerSize
getCornerSize(TypedArray a, int index, CornerSize defaultValue)
ShapeAppearanceModel

Returns the shape as a ShapeAppearanceModel of the ShapeAppearance, or the default shape if there are multiple shapes for different states.

EdgeTreatment

Gets the edge treatment for the left edge.

EdgeTreatment

Gets the edge treatment for the right edge.

ShapeAppearanceModel[]

Returns a list of the ShapeAppearanceModel of all states.

ShapeAppearanceModel
getShapeForState(int[] stateSet)

Returns a ShapeAppearanceModel for the given state set.

EdgeTreatment

Gets the edge treatment for the top edge.

CornerTreatment

Gets the corner treatment for the top left corner.

CornerSize

Gets the corner size for the top left corner.

CornerTreatment

Gets the corner treatment for the top right corner.

CornerSize

Gets the corner size for the top right corner.

boolean

Whether or not the ShapeAppearance provides different shapes for states.

ShapeAppearanceModel.Builder

Returns a builder with the edges and corners from this ShapeAppearanceModel

String
ShapeAppearanceModel

Returns a new ShapeAppearanceModel with the same edges and corners as the default shape, but with the corner size for all corners updated.

ShapeAppearanceModel
withCornerSize(float cornerSize)

Returns a copy of this ShapeAppearanceModel with the same edges and corners, but with the corner size for all corners updated.

Constants

CORNER_BOTTOM_LEFT

public static final int CORNER_BOTTOM_LEFT = 4

Flag representing bottom left corner of the shape.

CORNER_BOTTOM_RIGHT

public static final int CORNER_BOTTOM_RIGHT = 8

Flag representing bottom right corner of the shape.

CORNER_TOP_LEFT

public static final int CORNER_TOP_LEFT = 1

Flag representing top left corner of the shape.

CORNER_TOP_RIGHT

public static final int CORNER_TOP_RIGHT = 2

Flag representing top right corner of the shape.

NUM_CORNERS

public static final int NUM_CORNERS = 4

PILL

public static final CornerSize PILL

Public fields

bottomEdge

public EdgeTreatment bottomEdge

bottomLeftCorner

public CornerTreatment bottomLeftCorner

bottomLeftCornerSize

public CornerSize bottomLeftCornerSize

bottomRightCorner

public CornerTreatment bottomRightCorner

bottomRightCornerSize

public CornerSize bottomRightCornerSize

leftEdge

public EdgeTreatment leftEdge

rightEdge

public EdgeTreatment rightEdge

topEdge

public EdgeTreatment topEdge

topLeftCorner

public CornerTreatment topLeftCorner

topLeftCornerSize

public CornerSize topLeftCornerSize

topRightCorner

public CornerTreatment topRightCorner

topRightCornerSize

public CornerSize topRightCornerSize

Public constructors

ShapeAppearanceModel

public ShapeAppearanceModel()

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

Public methods

builder

public static ShapeAppearanceModel.Builder builder()

builder

public static ShapeAppearanceModel.Builder builder(Theme theme, int shapeAppearanceResId)

This builder only takes in a single shape appearance, no shape appearance overlay. Additionally, it does not use ContextThemeWrapper like the other builders, meaning XML @macro usages in the shape appearance are not supported, due to b/230755281.

builder

public static ShapeAppearanceModel.Builder builder(
    Context context,
    int shapeAppearanceResId,
    int shapeAppearanceOverlayResId
)

builder

public static ShapeAppearanceModel.Builder builder(
    Context context,
    AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes
)

builder

public static ShapeAppearanceModel.Builder builder(
    Context context,
    AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes,
    CornerSize defaultCornerSize
)

builder

public static ShapeAppearanceModel.Builder builder(
    Context context,
    AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes,
    int defaultCornerSize
)

getBottomEdge

public EdgeTreatment getBottomEdge()

Gets the edge treatment for the bottom edge.

Returns
EdgeTreatment

the edge treatment for the bottom edge.

getBottomLeftCorner

public CornerTreatment getBottomLeftCorner()

Gets the corner treatment for the bottom left corner.

Returns
CornerTreatment

the corner treatment for the bottom left corner.

getBottomLeftCornerSize

public CornerSize getBottomLeftCornerSize()

Gets the corner size for the bottom left corner.

Returns
CornerSize

the corner size for the bottom left corner.

getBottomRightCorner

public CornerTreatment getBottomRightCorner()

Gets the corner treatment for the bottom right corner.

Returns
CornerTreatment

the corner treatment for the bottom right corner.

getBottomRightCornerSize

public CornerSize getBottomRightCornerSize()

Gets the corner size for the bottom right corner.

Returns
CornerSize

the corner size for the bottom right corner.

getCornerSize

public static CornerSize getCornerSize(TypedArray a, int index, CornerSize defaultValue)

getDefaultShape

public ShapeAppearanceModel getDefaultShape()

Returns the shape as a ShapeAppearanceModel of the ShapeAppearance, or the default shape if there are multiple shapes for different states.

getLeftEdge

public EdgeTreatment getLeftEdge()

Gets the edge treatment for the left edge.

Returns
EdgeTreatment

the edge treatment for the left edge.

getRightEdge

public EdgeTreatment getRightEdge()

Gets the edge treatment for the right edge.

Returns
EdgeTreatment

the edge treatment for the right edge.

getShapeAppearanceModels

public ShapeAppearanceModel[] getShapeAppearanceModels()

Returns a list of the ShapeAppearanceModel of all states. If this ShapeAppearance is stateless, this will be a list of just the default shape.

getShapeForState

public ShapeAppearanceModel getShapeForState(int[] stateSet)

Returns a ShapeAppearanceModel for the given state set.

getTopEdge

public EdgeTreatment getTopEdge()

Gets the edge treatment for the top edge.

Returns
EdgeTreatment

the edge treatment for the top edge.

getTopLeftCorner

public CornerTreatment getTopLeftCorner()

Gets the corner treatment for the top left corner.

Returns
CornerTreatment

the corner treatment for the top left corner.

getTopLeftCornerSize

public CornerSize getTopLeftCornerSize()

Gets the corner size for the top left corner.

Returns
CornerSize

the corner size for the top left corner.

getTopRightCorner

public CornerTreatment getTopRightCorner()

Gets the corner treatment for the top right corner.

Returns
CornerTreatment

the corner treatment for the top right corner.

getTopRightCornerSize

public CornerSize getTopRightCornerSize()

Gets the corner size for the top right corner.

Returns
CornerSize

the corner size for the top right corner.

isStateful

public boolean isStateful()

Whether or not the ShapeAppearance provides different shapes for states.

toBuilder

public ShapeAppearanceModel.Builder toBuilder()

Returns a builder with the edges and corners from this ShapeAppearanceModel

toString

public String toString()

withCornerSize

public ShapeAppearanceModel withCornerSize(CornerSize cornerSize)

Returns a new ShapeAppearanceModel with the same edges and corners as the default shape, but with the corner size for all corners updated.

withCornerSize

public ShapeAppearanceModel withCornerSize(float cornerSize)

Returns a copy of this ShapeAppearanceModel with the same edges and corners, but with the corner size for all corners updated.