ElevationOverlayProvider

public class ElevationOverlayProvider


Utility for calculating elevation overlay alpha values and colors.

Summary

Public constructors

ElevationOverlayProvider(Context context)
ElevationOverlayProvider(
    boolean elevationOverlayEnabled,
    int elevationOverlayColor,
    int elevationOverlayAccentColor,
    int colorSurface,
    float displayDensity
)

Public methods

int
calculateOverlayAlpha(float elevation)

Calculates the alpha value, between 0 and 255, that should be used with the elevation overlay color, based on the provided elevation value.

float

Calculates the alpha fraction, between 0 and 1, that should be used with the elevation overlay color, based on the provided elevation value.

int
compositeOverlay(int backgroundColor, float elevation)

Blends the calculated elevation overlay color with the provided backgroundColor.

int
compositeOverlay(int backgroundColor, float elevation, View overlayView)

See compositeOverlay.

int
compositeOverlayIfNeeded(int backgroundColor, float elevation)

Blends the calculated elevation overlay color (@see #compositeOverlay(int, float)) with the backgroundColor, only if the current theme's R.attr.elevationOverlayEnabled is true and the backgroundColor matches the theme's surface color ( R.attr.colorSurface); otherwise returns the backgroundColor.

int
compositeOverlayIfNeeded(
    int backgroundColor,
    float elevation,
    View overlayView
)

See compositeOverlayIfNeeded.

int

Blends the calculated elevation overlay color (@see #compositeOverlayIfNeeded(int, float)) with the current theme's color int value for R.attr.colorSurface if needed.

int
compositeOverlayWithThemeSurfaceColorIfNeeded(
    float elevation,
    View overlayView
)

See compositeOverlayWithThemeSurfaceColorIfNeeded.

float
getParentAbsoluteElevation(View overlayView)

Returns the absolute elevation of the parent of the provided overlayView, or in other words, the sum of the elevations of all ancestors of the overlayView.

int

Returns the current theme's color int value for R.attr.elevationOverlayColor.

int

Returns the current theme's color int value for R.attr.colorSurface.

boolean

Returns the current theme's boolean value for R.attr.elevationOverlayEnabled.

Public constructors

ElevationOverlayProvider

public ElevationOverlayProvider(Context context)

ElevationOverlayProvider

public ElevationOverlayProvider(
    boolean elevationOverlayEnabled,
    int elevationOverlayColor,
    int elevationOverlayAccentColor,
    int colorSurface,
    float displayDensity
)

Public methods

calculateOverlayAlpha

public int calculateOverlayAlpha(float elevation)

Calculates the alpha value, between 0 and 255, that should be used with the elevation overlay color, based on the provided elevation value.

calculateOverlayAlphaFraction

public float calculateOverlayAlphaFraction(float elevation)

Calculates the alpha fraction, between 0 and 1, that should be used with the elevation overlay color, based on the provided elevation value.

compositeOverlay

public int compositeOverlay(int backgroundColor, float elevation)

Blends the calculated elevation overlay color with the provided backgroundColor.

An alpha level is applied to the theme's R.attr.elevationOverlayColor by using a formula that is based on the provided elevation value.

compositeOverlay

public int compositeOverlay(int backgroundColor, float elevation, View overlayView)

See compositeOverlay.

compositeOverlayIfNeeded

public int compositeOverlayIfNeeded(int backgroundColor, float elevation)

Blends the calculated elevation overlay color (@see #compositeOverlay(int, float)) with the backgroundColor, only if the current theme's R.attr.elevationOverlayEnabled is true and the backgroundColor matches the theme's surface color ( R.attr.colorSurface); otherwise returns the backgroundColor.

compositeOverlayIfNeeded

public int compositeOverlayIfNeeded(
    int backgroundColor,
    float elevation,
    View overlayView
)

See compositeOverlayIfNeeded.

The absolute elevation of the parent of the provided overlayView will also be factored in when determining the overlay color.

compositeOverlayWithThemeSurfaceColorIfNeeded

public int compositeOverlayWithThemeSurfaceColorIfNeeded(float elevation)

Blends the calculated elevation overlay color (@see #compositeOverlayIfNeeded(int, float)) with the current theme's color int value for R.attr.colorSurface if needed.

compositeOverlayWithThemeSurfaceColorIfNeeded

public int compositeOverlayWithThemeSurfaceColorIfNeeded(
    float elevation,
    View overlayView
)

See compositeOverlayWithThemeSurfaceColorIfNeeded.

The absolute elevation of the parent of the provided overlayView will also be factored in when determining the overlay color.

getParentAbsoluteElevation

public float getParentAbsoluteElevation(View overlayView)

Returns the absolute elevation of the parent of the provided overlayView, or in other words, the sum of the elevations of all ancestors of the overlayView.

getThemeElevationOverlayColor

public int getThemeElevationOverlayColor()

Returns the current theme's color int value for R.attr.elevationOverlayColor.

getThemeSurfaceColor

public int getThemeSurfaceColor()

Returns the current theme's color int value for R.attr.colorSurface.

isThemeElevationOverlayEnabled

public boolean isThemeElevationOverlayEnabled()

Returns the current theme's boolean value for R.attr.elevationOverlayEnabled.