Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

ShadowOverlayHelper

class ShadowOverlayHelper
kotlin.Any
   ↳ androidx.leanback.widget.ShadowOverlayHelper

ShadowOverlayHelper is a helper class for shadow, overlay color and rounded corner. There are many choices to implement Shadow, overlay color. Initialize it with ShadowOverlayHelper.Builder and it decides the best strategy based on options user choose and current platform version.

  • For shadow: it may use 9-patch with opticalBounds or Z-value based shadow for API >= 21. When 9-patch is used, it requires a ShadowOverlayContainer to include 9-patch views.
  • For overlay: it may use ShadowOverlayContainer which overrides draw() or it may use setForeground(new ColorDrawable()) for API>=23. The foreground support might be disabled if rounded corner is applied due to performance reason.
  • For rounded-corner: it uses a ViewOutlineProvider for API>=21. There are two different strategies: use Wrapper with a ShadowOverlayContainer; or apply rounded corner, overlay and rounded-corner to the view itself. Below is an example of how helper is used. ShadowOverlayHelper mHelper = new ShadowOverlayHelper.Builder(). .needsOverlay(true).needsRoundedCorner(true).needsShadow(true) .build(); mHelper.prepareParentForShadow(parentView); // apply optical-bounds for 9-patch shadow. mHelper.setOverlayColor(view, Color.argb(0x80, 0x80, 0x80, 0x80)); mHelper.setShadowFocusLevel(view, 1.0f); ... View initializeView(View view) { if (mHelper.needsWrapper()) { ShadowOverlayContainer wrapper = mHelper.createShadowOverlayContainer(context); wrapper.wrap(view); return wrapper; } else { mHelper.onViewCreated(view); return view; } } ...
  • Summary

    Nested classes

    Builder for creating ShadowOverlayHelper.

    Option values for ShadowOverlayContainer.

    Constants
    static Int

    No shadow.

    static Int

    Shadows are fixed.

    static Int

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

    Public methods
    ShadowOverlayContainer!

    Create ShadowOverlayContainer for this helper.

    Unit

    Must be called when view is created for cases needsWrapper() is false.

    Boolean

    Unit
    setOverlayColor(view: View!, color: Int)

    Set overlay color for view, it can be a ShadowOverlayContainer if needsWrapper() is true, or other view type.

    Unit

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

    Boolean

    Boolean

    Returns true if a "wrapper" ShadowOverlayContainer is needed.

    Int

    Unit
    setShadowFocusLevel(view: View!, level: Float)

    Set shadow focus level (0 to 1).

    static Boolean

    Return true if the platform sdk supports shadow.

    static Boolean

    Returns true if the platform sdk supports dynamic shadows.

    static Boolean

    Returns true if the platform sdk supports rounded corner through outline.

    static Boolean

    Returns true if view.

    static Unit

    Set overlay color for view other than ShadowOverlayContainer.

    static Unit

    Set shadow focus level (0 to 1).

    Constants

    SHADOW_NONE

    static val SHADOW_NONE: Int

    No shadow.

    Value: 1

    SHADOW_STATIC

    static val SHADOW_STATIC: Int

    Shadows are fixed.

    Value: 2

    SHADOW_DYNAMIC

    static val SHADOW_DYNAMIC: Int

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

    Value: 3

    Public methods

    createShadowOverlayContainer

    fun createShadowOverlayContainer(context: Context!): ShadowOverlayContainer!

    Create ShadowOverlayContainer for this helper.

    Parameters
    context Context!: Context to create view.
    Return
    ShadowOverlayContainer!: ShadowOverlayContainer.

    onViewCreated

    fun onViewCreated(view: View!): Unit

    Must be called when view is created for cases needsWrapper() is false.

    Parameters
    view View!:

    needsRoundedCorner

    fun needsRoundedCorner(): Boolean

    setOverlayColor

    fun setOverlayColor(view: View!, color: Int): Unit

    Set overlay color for view, it can be a ShadowOverlayContainer if needsWrapper() is true, or other view type.

    prepareParentForShadow

    fun prepareParentForShadow(parent: ViewGroup!): Unit

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

    needsOverlay

    fun needsOverlay(): Boolean

    needsWrapper

    fun needsWrapper(): Boolean

    Returns true if a "wrapper" ShadowOverlayContainer is needed. When needsWrapper() is true, call createShadowOverlayContainer(Context) to create the wrapper.

    getShadowType

    fun getShadowType(): Int

    setShadowFocusLevel

    fun setShadowFocusLevel(view: View!, level: Float): Unit

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

    supportsShadow

    static fun supportsShadow(): Boolean

    Return true if the platform sdk supports shadow.

    supportsDynamicShadow

    static fun supportsDynamicShadow(): Boolean

    Returns true if the platform sdk supports dynamic shadows.

    supportsRoundedCorner

    static fun supportsRoundedCorner(): Boolean

    Returns true if the platform sdk supports rounded corner through outline.

    supportsForeground

    static fun supportsForeground(): Boolean

    Returns true if view.setForeground() is supported.

    setNoneWrapperOverlayColor

    static fun setNoneWrapperOverlayColor(view: View!, color: Int): Unit

    Set overlay color for view other than ShadowOverlayContainer. See also ShadowOverlayContainer#setOverlayColor(int).

    setNoneWrapperShadowFocusLevel

    static fun setNoneWrapperShadowFocusLevel(view: View!, level: Float): Unit

    Set shadow focus level (0 to 1). 0 for unfocused, 1 for fully focused. This is for view other than ShadowOverlayContainer. See also ShadowOverlayContainer#setShadowFocusLevel(float).