Android APIs
public class

ShadowOverlayContainer

extends ViewGroup
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.v17.leanback.widget.ShadowOverlayContainer

Class Overview

Provides an SDK version-independent wrapper to support shadows, color overlays, and rounded corners.

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

[Expand]
Inherited XML Attributes
From class android.view.ViewGroup
From class android.view.View
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.
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
ShadowOverlayContainer(Context context)
ShadowOverlayContainer(Context context, AttributeSet attrs)
ShadowOverlayContainer(Context context, AttributeSet attrs, int defStyle)
Public Methods
int getShadowType()
Returns the shadow type, one of SHADOW_NONE, SHADOW_STATIC, or SHADOW_DYNAMIC.
View getWrappedView()
Returns the wrapper view.
void initialize(boolean hasShadow, boolean hasColorDimOverlay)
This method is deprecated. use initialize(boolean, boolean, boolean) instead.
void initialize(boolean hasShadow, boolean hasColorDimOverlay, boolean roundedCorners)
Initialize shadows, color overlay, and rounded corners.
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()
Sets the shadow type to SHADOW_DYNAMIC if supported.
void useDynamicShadow(float unfocusedZ, float focusedZ)
Sets the shadow type to SHADOW_DYNAMIC if supported and sets the elevation/Z values to the given parameteres.
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)
Called from layout when this view should assign a size and position to each of its children.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

[Expand]
Inherited Methods
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Constants

public static final int SHADOW_DYNAMIC

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

Constant Value: 3 (0x00000003)

public static final int SHADOW_NONE

No shadow.

Constant Value: 1 (0x00000001)

public static final int SHADOW_STATIC

Shadows are fixed.

Constant Value: 2 (0x00000002)

Public Constructors

public ShadowOverlayContainer (Context context)

public ShadowOverlayContainer (Context context, AttributeSet attrs)

public ShadowOverlayContainer (Context context, AttributeSet attrs, int defStyle)

Public Methods

public int getShadowType ()

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

public View getWrappedView ()

Returns the wrapper view.

public void initialize (boolean hasShadow, boolean hasColorDimOverlay)

This method is deprecated.
use initialize(boolean, boolean, boolean) instead.

Initialize shadows, color overlay.

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

Initialize shadows, color overlay, and rounded corners. All are optional.

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.

public void setOverlayColor (int overlayColor)

Set color (with alpha) of the overlay.

public void setShadowFocusLevel (float level)

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

public static boolean supportsDynamicShadow ()

Returns true if the platform sdk supports dynamic shadows.

public static boolean supportsShadow ()

Return true if the platform sdk supports shadow.

public void useDynamicShadow ()

Sets the shadow type to SHADOW_DYNAMIC if supported.

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 parameteres.

public void useStaticShadow ()

Sets the shadow type to SHADOW_STATIC if supported.

public void wrap (View view)

Inserts view into the wrapper.

Protected Methods

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

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed This is a new size or position for this view
l Left position, relative to parent
t Top position, relative to parent
r Right position, relative to parent
b Bottom position, relative to parent

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.