ContrastProtection


public abstract class ContrastProtection

Known direct subclasses
ColorProtection

A type of protection which draws the plain color.

GradientProtection

A type of protection which draws the gradient color.


An abstract class which describes a layer to be placed on the content of a window and underneath the system bar (which has a transparent background) to ensure the readability of the foreground elements (e.g., text, icons, ..., etc) of the system bar.

Concrete derived classes would describe how the protection should be drawn by supplying the Drawable.

The object of this class is stateful, and can only be used by one ProtectionView at a time.

Summary

Public constructors

Creates an instance associated with a WindowInsetsCompat.Side.

Public methods

void
animateAlpha(float toAlpha)

Animates the alpha from the current value to the specified one.

void
animateInsetsAmount(float toInsetsAmount)

Animates the insets amount from the current value to the specified one.

@FloatRange(from = 0.0, to = 1.0) float

Gets the opacity of the protection.

float

Gets the depth of the protection.

int

Gets the side of this protection.

void
setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha)

Sets the opacity of the protection to a value from 0 to 1, where 0 means the protection is completely transparent and 1 means the protection is completely opaque.

void
setInsetAmount(@FloatRange(from = 0.0, to = 1.0) float insetAmount)

Sets the depth of the protection to a value from 0 to 1, where 0 means the protection is completely outside the window and 1 means the protection is completely inside the window.

Public constructors

ContrastProtection

public ContrastProtection(int side)

Creates an instance associated with a WindowInsetsCompat.Side.

Parameters
int side

the given WindowInsetsCompat.Side.

Throws
java.lang.IllegalArgumentException

if the given side is not one of the four sides.

Public methods

animateAlpha

public void animateAlpha(float toAlpha)

Animates the alpha from the current value to the specified one.

Calling setAlpha during the animation will cancel the existing alpha animation.

Parameters
float toAlpha

The alpha that will be animated to. The range is [0, 1].

animateInsetsAmount

public void animateInsetsAmount(float toInsetsAmount)

Animates the insets amount from the current value to the specified one.

Calling setInsetAmount during the animation will cancel the existing animation of insets amount.

Parameters
float toInsetsAmount

The insets amount that will be animated to. The range is [0, 1].

getAlpha

public @FloatRange(from = 0.0, to = 1.0) float getAlpha()

Gets the opacity of the protection. This is a value from 0 to 1, where 0 means the protection is completely transparent and 1 means the protection is completely opaque.

Returns
@FloatRange(from = 0.0, to = 1.0) float

The opacity of the protection.

getInsetAmount

public float getInsetAmount()

Gets the depth of the protection. This is a value from 0 to 1, where 0 means the protection completely inside the window and 1 means the protection is completely outside the window.

Returns
float

The depth of the protection.

getSide

public int getSide()

Gets the side of this protection.

Returns
int

the side this protection is associated with.

setAlpha

public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha)

Sets the opacity of the protection to a value from 0 to 1, where 0 means the protection is completely transparent and 1 means the protection is completely opaque.

Parameters
@FloatRange(from = 0.0, to = 1.0) float alpha

The opacity of the protection.

Throws
java.lang.IllegalArgumentException

if the given alpha is not in a range of [0, 1].

setInsetAmount

public void setInsetAmount(@FloatRange(from = 0.0, to = 1.0) float insetAmount)

Sets the depth of the protection to a value from 0 to 1, where 0 means the protection is completely outside the window and 1 means the protection is completely inside the window.

Parameters
@FloatRange(from = 0.0, to = 1.0) float insetAmount

The depth of the protection.

Throws
java.lang.IllegalArgumentException

if the given inset amount is not in a range of [0, 1].