Register now for Android Dev Summit 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

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

    static Int

    No shadow.

    static Int

    Shadows are fixed.

    Public methods

    ShadowOverlayContainer!

    Create ShadowOverlayContainer for this helper.

    Int

    Boolean

    Boolean

    Boolean

    Returns true if a "wrapper" ShadowOverlayContainer is needed.

    Unit

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

    Unit

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

    static Unit

    Set overlay color for view other than ShadowOverlayContainer.

    static Unit

    Set shadow focus level (0 to 1).

    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
    setShadowFocusLevel(view: View!, level: Float)

    Set shadow focus level (0 to 1).

    static Boolean

    Returns true if the platform sdk supports dynamic shadows.

    static Boolean

    Returns true if view.

    static Boolean

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

    static Boolean

    Return true if the platform sdk supports shadow.

    Constants

    SHADOW_DYNAMIC

    static val SHADOW_DYNAMIC: Int

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

    Value: 3

    SHADOW_NONE

    static val SHADOW_NONE: Int

    No shadow.

    Value: 1

    SHADOW_STATIC

    static val SHADOW_STATIC: Int

    Shadows are fixed.

    Value: 2

    Public methods

    createShadowOverlayContainer

    fun createShadowOverlayContainer(context: Context!): ShadowOverlayContainer!

    Create ShadowOverlayContainer for this helper.

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

    getShadowType

    fun getShadowType(): Int

    needsOverlay

    fun needsOverlay(): Boolean

    needsRoundedCorner

    fun needsRoundedCorner(): Boolean

    needsWrapper

    fun needsWrapper(): Boolean

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

    onViewCreated

    fun onViewCreated(view: View!): Unit

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

    Parameters
    view View!:

    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.

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

    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.

    setShadowFocusLevel

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

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

    supportsDynamicShadow

    static fun supportsDynamicShadow(): Boolean

    Returns true if the platform sdk supports dynamic shadows.

    supportsForeground

    static fun supportsForeground(): Boolean

    Returns true if view.setForeground() is supported.

    supportsRoundedCorner

    static fun supportsRoundedCorner(): Boolean

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

    supportsShadow

    static fun supportsShadow(): Boolean

    Return true if the platform sdk supports shadow.