FocusRingDrawable


public class FocusRingDrawable


Drawable wrapper that provides focus rings.

Summary

Public constructors

FocusRingDrawable(Context context, Drawable drawable)

Public methods

void
applyTheme(Theme theme)
boolean
void
draw(Canvas canvas)
static FocusRingDrawable
find(Drawable drawable)

Search for and return a FocusRingDrawable if it is either the provided drawable or one level deep in a DrawableWrapper or LayerDrawable.

static FocusRingDrawable
findAndMutate(Drawable drawable)

Search for, mutate, and return a FocusRingDrawable if it is either the provided drawable or one level deep in a DrawableWrapper or LayerDrawable.

ConstantState
Rect
float
int
float
float
MaterialShapeDrawable
int
float
float
ShapeAppearance
int[]
boolean
void
inflate(Resources res, XmlPullParser parser, AttributeSet attrs)
void
inflate(
    Resources res,
    XmlPullParser parser,
    AttributeSet attrs,
    Theme theme
)
boolean
boolean
boolean
void
static FocusRingDrawable
layer(Context context, LayerDrawable layerDrawable)

Add a FocusRingDrawable as a layer to the provided LayerDrawable if focus rings are enabled, otherwise do nothing and return null.

static FocusRingDrawable
layer(
    Context context,
    LayerDrawable layerDrawable,
    MaterialShapeDrawable materialShapeDrawable
)

Add a FocusRingDrawable as a layer to the provided LayerDrawable if focus rings are enabled, otherwise do nothing and return null.

Drawable
void
setFocusRingBounds(Rect bounds)
void
setFocusRingBounds(int left, int top, int right, int bottom)
void
setFocusRingEnabled(boolean enabled)
void
setFocusRingInnerInset(float innerInset)
void
setFocusRingInnerStrokeColor(int innerStrokeColor)
void
setFocusRingInnerStrokeWidth(float innerStrokeWidth)
void
setFocusRingInset(float inset)
void
void
setFocusRingOuterStrokeColor(int outerStrokeColor)
void
setFocusRingOuterStrokeWidth(float outerStrokeWidth)
void
setFocusRingRadius(float radius)
void
void
setFocusRingStateSet(int[] stateSet)
boolean
static Drawable
wrap(Context context, Drawable drawable)

Wrap the provided drawable with a FocusRingDrawable if focus rings are enabled, otherwise just return the provided drawable.

Protected methods

void
onBoundsChange(Rect bounds)
boolean
onStateChange(int[] stateSet)

Public constructors

FocusRingDrawable

public FocusRingDrawable()

FocusRingDrawable

public FocusRingDrawable(Context context, Drawable drawable)

Public methods

applyTheme

public void applyTheme(Theme theme)

canApplyTheme

public boolean canApplyTheme()

draw

public void draw(Canvas canvas)

find

public static FocusRingDrawable find(Drawable drawable)

Search for and return a FocusRingDrawable if it is either the provided drawable or one level deep in a DrawableWrapper or LayerDrawable.

This is useful for finding a FocusRingDrawable that has been set up with either wrap or layer, as well as the equivalent XML drawable configurations.

findAndMutate

public static FocusRingDrawable findAndMutate(Drawable drawable)

Search for, mutate, and return a FocusRingDrawable if it is either the provided drawable or one level deep in a DrawableWrapper or LayerDrawable.

If the FocusRingDrawable is a child of a DrawableWrapper or LayerDrawable, then the parent DrawableWrapper or LayerDrawable will be mutated instead of the FocusRingDrawable. This will in turn recreate and mutate the child FocusRingDrawable, which helps prevent issues related to constant state.

Also see find.

getConstantState

public ConstantState getConstantState()

getFocusRingBounds

public Rect getFocusRingBounds()

getFocusRingInnerInset

public float getFocusRingInnerInset()

getFocusRingInnerStrokeColor

public int getFocusRingInnerStrokeColor()

getFocusRingInnerStrokeWidth

public float getFocusRingInnerStrokeWidth()

getFocusRingInset

public float getFocusRingInset()

getFocusRingMaterialShapeDrawable

public MaterialShapeDrawable getFocusRingMaterialShapeDrawable()

getFocusRingOuterStrokeColor

public int getFocusRingOuterStrokeColor()

getFocusRingOuterStrokeWidth

public float getFocusRingOuterStrokeWidth()

getFocusRingRadius

public float getFocusRingRadius()

getFocusRingShapeAppearance

public ShapeAppearance getFocusRingShapeAppearance()

getFocusRingStateSet

public int[] getFocusRingStateSet()

hasFocusStateSpecified

public boolean hasFocusStateSpecified()

inflate

public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs)

inflate

public void inflate(
    Resources res,
    XmlPullParser parser,
    AttributeSet attrs,
    Theme theme
)

isFocusRingEnabled

public boolean isFocusRingEnabled()

isProjected

public boolean isProjected()

isStateful

public boolean isStateful()

jumpToCurrentState

public void jumpToCurrentState()

layer

public static FocusRingDrawable layer(Context context, LayerDrawable layerDrawable)

Add a FocusRingDrawable as a layer to the provided LayerDrawable if focus rings are enabled, otherwise do nothing and return null.

See layer.

layer

public static FocusRingDrawable layer(
    Context context,
    LayerDrawable layerDrawable,
    MaterialShapeDrawable materialShapeDrawable
)

Add a FocusRingDrawable as a layer to the provided LayerDrawable if focus rings are enabled, otherwise do nothing and return null.

This method of integrating focus rings should be preferred if the drawable is a bounded ripple drawable (has layers), because we can add the focus ring as a layer without affecting the ripple bounds. See wrap for an alternative method where the focus ring can wrap the provided drawable instead of being added as a layer.

The MaterialShapeDrawable will be used to draw the focus ring outline shape and bounds.

mutate

public Drawable mutate()

setFocusRingBounds

public void setFocusRingBounds(Rect bounds)

setFocusRingBounds

public void setFocusRingBounds(int left, int top, int right, int bottom)

setFocusRingEnabled

public void setFocusRingEnabled(boolean enabled)

setFocusRingInnerInset

public void setFocusRingInnerInset(float innerInset)

setFocusRingInnerStrokeColor

public void setFocusRingInnerStrokeColor(int innerStrokeColor)

setFocusRingInnerStrokeWidth

public void setFocusRingInnerStrokeWidth(float innerStrokeWidth)

setFocusRingInset

public void setFocusRingInset(float inset)

setFocusRingMaterialShapeDrawable

public void setFocusRingMaterialShapeDrawable(
    MaterialShapeDrawable materialShapeDrawable
)

setFocusRingOuterStrokeColor

public void setFocusRingOuterStrokeColor(int outerStrokeColor)

setFocusRingOuterStrokeWidth

public void setFocusRingOuterStrokeWidth(float outerStrokeWidth)

setFocusRingRadius

public void setFocusRingRadius(float radius)

setFocusRingShapeAppearance

public void setFocusRingShapeAppearance(ShapeAppearance shapeAppearance)

setFocusRingStateSet

public void setFocusRingStateSet(int[] stateSet)

updateFocusRingShapeAppearanceFromWrappedDrawable

public boolean updateFocusRingShapeAppearanceFromWrappedDrawable()

wrap

public static Drawable wrap(Context context, Drawable drawable)

Wrap the provided drawable with a FocusRingDrawable if focus rings are enabled, otherwise just return the provided drawable.

This method of integrating focus rings should be preferred if the drawable is an unbounded ripple drawable (has no layers), because wrapping the ripple will preserve the unbounded-ness. See layer for an alternative method where the focus ring can be added as a layer instead of wrapping.

Protected methods

onBoundsChange

protected void onBoundsChange(Rect bounds)

onStateChange

protected boolean onStateChange(int[] stateSet)