Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.
added in version 1.0.0
belongs to Maven artifact androidx.leanback:leanback:1.0.0-rc01

ShadowOverlayContainer

public class ShadowOverlayContainer
extends FrameLayout

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ androidx.leanback.widget.ShadowOverlayContainer


Provides an SDK version-independent wrapper to support shadows, color overlays, and rounded corners. It's not always preferred to create a ShadowOverlayContainer, use ShadowOverlayHelper instead.

prepareParentForShadow(ViewGroup) must be called on parent of container before using shadow. Depending on sdk version, optical bounds might be applied to parent.

If shadows can appear outside the bounds of the parent view, setClipChildren(false) must be called on the grandparent view.

initialize(boolean, boolean, boolean) must be first called on the container. Then call wrap(View) to insert the wrapped view into the container.

Call setShadowFocusLevel(float) to control the strength of the shadow (focused shadows cast stronger shadows).

Call setOverlayColor(int) to control overlay color.

Summary

Constants

int SHADOW_DYNAMIC

Shadows depend on the size, shape, and position of the view.

int SHADOW_NONE

No shadow.

int SHADOW_STATIC

Shadows are fixed.

Inherited constants

Inherited fields

Public constructors

ShadowOverlayContainer(Context context)

Create ShadowOverlayContainer and auto select shadow type.

ShadowOverlayContainer(Context context, AttributeSet attrs)

Create ShadowOverlayContainer and auto select shadow type.

ShadowOverlayContainer(Context context, AttributeSet attrs, int defStyle)

Create ShadowOverlayContainer and auto select shadow type.

Public methods

void draw(Canvas canvas)
int getShadowType()

Returns the shadow type, one of SHADOW_NONE, SHADOW_STATIC, or SHADOW_DYNAMIC.

View getWrappedView()

Returns the wrapper view.

boolean hasOverlappingRendering()
void initialize(boolean hasShadow, boolean hasColorDimOverlay)

This method was deprecated in API level 1.0.0. use ShadowOverlayHelper.createShadowOverlayContainer(Context) instead.

void initialize(boolean hasShadow, boolean hasColorDimOverlay, boolean roundedCorners)

This method was deprecated in API level 1.0.0. use ShadowOverlayHelper.createShadowOverlayContainer(Context) instead.

static void prepareParentForShadow(ViewGroup parent)

prepareParentForShadow(ViewGroup) must be called on parent of container before using shadow.

void setOverlayColor(int overlayColor)

Set color (with alpha) of the overlay.

void setShadowFocusLevel(float level)

Set shadow focus level (0 to 1).

static boolean supportsDynamicShadow()

Returns true if the platform sdk supports dynamic shadows.

static boolean supportsShadow()

Return true if the platform sdk supports shadow.

void useDynamicShadow(float unfocusedZ, float focusedZ)

Sets the shadow type to SHADOW_DYNAMIC if supported and sets the elevation/Z values to the given parameters.

void useDynamicShadow()

Sets the shadow type to SHADOW_DYNAMIC if supported.

void useStaticShadow()

Sets the shadow type to SHADOW_STATIC if supported.

void wrap(View view)

Inserts view into the wrapper.

Protected methods

void onLayout(boolean changed, int l, int t, int r, int b)

Inherited methods

Constants

SHADOW_DYNAMIC

added in version 1.0.0
public static final int SHADOW_DYNAMIC

Shadows depend on the size, shape, and position of the view.

Constant Value: 3 (0x00000003)

SHADOW_NONE

added in version 1.0.0
public static final int SHADOW_NONE

No shadow.

Constant Value: 1 (0x00000001)

SHADOW_STATIC

added in version 1.0.0
public static final int SHADOW_STATIC

Shadows are fixed.

Constant Value: 2 (0x00000002)

Public constructors

ShadowOverlayContainer

added in version 1.0.0
public ShadowOverlayContainer (Context context)

Create ShadowOverlayContainer and auto select shadow type.

Parameters
context Context

ShadowOverlayContainer

added in version 1.0.0
public ShadowOverlayContainer (Context context, 
                AttributeSet attrs)

Create ShadowOverlayContainer and auto select shadow type.

Parameters
context Context

attrs AttributeSet

ShadowOverlayContainer

added in version 1.0.0
public ShadowOverlayContainer (Context context, 
                AttributeSet attrs, 
                int defStyle)

Create ShadowOverlayContainer and auto select shadow type.

Parameters
context Context

attrs AttributeSet

defStyle int

Public methods

draw

public void draw (Canvas canvas)

Parameters
canvas Canvas

getShadowType

added in version 1.0.0
public int getShadowType ()

Returns the shadow type, one of SHADOW_NONE, SHADOW_STATIC, or SHADOW_DYNAMIC.

Returns
int

getWrappedView

added in version 1.0.0
public View getWrappedView ()

Returns the wrapper view.

Returns
View

hasOverlappingRendering

public boolean hasOverlappingRendering ()

Returns
boolean

initialize

added in version 1.0.0
public void initialize (boolean hasShadow, 
                boolean hasColorDimOverlay)

This method was deprecated in API level 1.0.0.
use ShadowOverlayHelper.createShadowOverlayContainer(Context) instead.

Initialize shadows, color overlay.

Parameters
hasShadow boolean

hasColorDimOverlay boolean

initialize

added in version 1.0.0
public void initialize (boolean hasShadow, 
                boolean hasColorDimOverlay, 
                boolean roundedCorners)

This method was deprecated in API level 1.0.0.
use ShadowOverlayHelper.createShadowOverlayContainer(Context) instead.

Initialize shadows, color overlay, and rounded corners. All are optional. Shadow type are auto-selected based on useStaticShadow() and useDynamicShadow() call.

Parameters
hasShadow boolean

hasColorDimOverlay boolean

roundedCorners boolean

prepareParentForShadow

added in version 1.0.0
public static void prepareParentForShadow (ViewGroup parent)

prepareParentForShadow(ViewGroup) must be called on parent of container before using shadow. Depending on sdk version, optical bounds might be applied to parent.

Parameters
parent ViewGroup

setOverlayColor

added in version 1.0.0
public void setOverlayColor (int overlayColor)

Set color (with alpha) of the overlay.

Parameters
overlayColor int

setShadowFocusLevel

added in version 1.0.0
public void setShadowFocusLevel (float level)

Set shadow focus level (0 to 1). 0 for unfocused, 1f for fully focused.

Parameters
level float

supportsDynamicShadow

added in version 1.0.0
public static boolean supportsDynamicShadow ()

Returns true if the platform sdk supports dynamic shadows.

Returns
boolean

supportsShadow

added in version 1.0.0
public static boolean supportsShadow ()

Return true if the platform sdk supports shadow.

Returns
boolean

useDynamicShadow

added in version 1.0.0
public void useDynamicShadow (float unfocusedZ, 
                float focusedZ)

Sets the shadow type to SHADOW_DYNAMIC if supported and sets the elevation/Z values to the given parameters.

Parameters
unfocusedZ float

focusedZ float

useDynamicShadow

added in version 1.0.0
public void useDynamicShadow ()

Sets the shadow type to SHADOW_DYNAMIC if supported.

useStaticShadow

added in version 1.0.0
public void useStaticShadow ()

Sets the shadow type to SHADOW_STATIC if supported.

wrap

added in version 1.0.0
public void wrap (View view)

Inserts view into the wrapper.

Parameters
view View

Protected methods

onLayout

protected void onLayout (boolean changed, 
                int l, 
                int t, 
                int r, 
                int b)

Parameters
changed boolean

l int

t int

r int

b int